Arduino PLC

What is it for?

The Arduino device probably needs no introduction. You can implement many interesting projects using this system. All you need to do is buy the right board, connect it to your computer using a USB cable and you can program it using free software by writing a program in C\C++. And that's the problem. Well, to program a simple system, you need a "powerful computer" and additional software. In most cases, our system performs a very simple task and sometimes we want to make minor changes to its operation. Isn't it possible to do it so that the programming is performed by Arduino itself? The presented solution is proof that it is possible. The presented system is nothing more than an expansion board connected to the popular Arduino. The module is equipped with an OLED display and a 5-button keyboard. It is worth paying attention to the simplicity of this solution, the use of popular components and its low cost.


How does it work?

The essence of this device is a program uploaded once to Arduino (the program, in source form, is placed on github ArduinoProgramowaneRecznie). This program deals with the keyboard, display and execution of instructions given by the user. Using the 5-button keyboard, we navigate through the menu displayed on the OLED display. By selecting the appropriate items in the menu, we are able to program or edit the list of instructions that our Arduino is to perform. These instructions are similar in structure to assembly language. Figure 1 shows the individual elements of the instructions. A line of code may contain only a command (a command without parameters).

Description of the construction

The element necessary for the proper functioning of the device is the aforementioned expansion module. For a better understanding of the construction and operation of the device, it is worth analyzing the schematic diagram shown in Figure 2. The system basically consists of two parts. The first is the OLED display module marked on the diagram as U2. Currently, there are many different cheap display modules on the market with support for the I2C bus. In this case, it is a 0.96’’ 128x64px OLED display module based on the SSD1306 controller. The second element of the module is a keyboard consisting of the PCF8574P system (8-bit digital input expander with support for I2C communication), buttons S1…S5 and resistors R1…R5. Additionally, the module has LED D1 connected to the digital output D13 via resistor R9. The keyboard and display are connected to a common I2C bus led out of the module via SCL and SDA outputs – marked on the Arduino board as A4, A5). The entire module is powered by Arduino. Inputs A0, A1, A2 of the U1 system are connected to GND to set the default I2C bus address of the PCF8574P system. Resistors R1, R2 perform the function of pulling the SDA and SCL lines to a high state.

Assembly and start-up

All the elements of the module should be connected according to the schematic diagram shown in Figure 2. Note: It is important to pay attention to the correct connection of the keyboard button signals. This ensures the correct functioning of the system. Otherwise, some buttons will not work or will work incorrectly. Figure 3 shows the arrangement of the buttons, their function and the appropriate input to the PCF8574P system.

Another thing to pay attention to is the pinout of the OLED module. It must be consistent with the photo no. below (the order of pins from the left looking from above: GND, VCC, SCL, SDA). There are modules on the market with a different order of pinouts.

After connecting the module to the Arduino board (in this case Arduino UNO), uploading the program to the microcontroller using the Arduino software and connecting the power supply, the OLED display should show the inscription "NO PROGRAM". After 3 seconds, the inscription disappears and the main menu appears with the options RUN, EDIT, PROGRAM, CLEAR. We move around the menu using the UP and DOWN buttons, and activate the selected option with the ENTER button (to go back a level, press the LEFT button). The diagram in Figure 4 shows a list of steps to be taken to create a simple program that blinks an LED on the Arduino board (output D13 – LED_BUILDIN) at a frequency of 1Hz when we press the DOWN button on the keyboard.

Each block in the drawing shows the view from the display at a given moment of editing. The text marked in black is the option selected with the UP/DOWN buttons. The arrows point to the next screen that appears after selecting the option by pressing the ENTER key (except for the described arrows in the first and last line). At the beginning (looking from the top) you can see how the previously mentioned message "No program" is displayed and after 3 seconds you are transferred to the main menu. We select EDIT and can add more lines of the program "[+]". We select the positions indicated in the drawing and confirm with the "ENTER" button. On the screens with the texts "Enter byte nr:", "Enter bit nr:" we edit the parameter values ​​by selecting the position of the given digit with the LEFT/RIGHT buttons, and then increasing or decreasing its value with the UP/DOWN buttons and confirm with the "ENTER" button. The return arrow in the drawing means that editing the new line is finished and returning to the listing of the entire program. At the bottom of the drawing on the left side you can see the entire listing of the program. Now, to run the created program, we exit the editing with the LEFT button and go to the main menu. We select "Run" and then "Save&Run". The program is saved to the non-volatile internal memory and its execution begins. The table below contains a description of the above program.



Final remarks

Arduino remembers the program after the power is turned off. When the power is applied, if the program is detected, it is automatically executed. To exit the "Running..." mode to the main menu, simultaneously press the LEFT and RIGHT buttons and hold for 3 seconds. In the "Running..." mode, the display turns off automatically after 30 seconds.




Brak komentarzy:

Prześlij komentarz