How to - part 3 - Communication Raspberry and AI sensors

Marek Bodorik

May 18 2020, 7 min read

Introduction

About this project

In this tutorial, I will demonstrate how to create a project with sensors which use the analog signals as an output on a Raspberry PI by using D2000 software. First, you need to download an image for Raspberry PI and install it according to this online manual and download the client for Windows. After a successful installation, we are ready to start.

Wiring

I prepared several sensors which will measure a different quantity. All of them have common characteristic. For this project I used these components:

1.      Raspberry Pi 3

2.      Rain sensor and comparator

3.      Soil moisture sensor

4.      Photoresistor

5.      Breadboard and jump wires

D2000

D2000 consists of several programs. Three programs are important for common users – GR.EXE, HI.EXE and CNF.EXE:

·         GR.EXE (GREDIT) is a graphic editor allowing to create schemes (called pictures) which display the logged technological process.

·         HI.EXE (Human Interface - user's console) provides communication of operator with D2000 system. This process displays created schemes which contain the technological data.

·         CNF.EXE (CNF) is a process intended to configure various non-graphical D2000 objects (e.g. I/O tags, historical values, evaluated tags, etc.). This process is used to create new objects, modify and delete existing ones. It is not necessary to open CNF.EXE separately because CNF is a part of GREDIT. You can find it in GREDIT toolbar menu as you can see in the Figure 1.

Figure 1: CNF button in GREDIT application

Picture

For this project, I decided to create a new picture based on a demo example and I will show you how to make it. First I opened GREDIT application and by clicking on the System button situated in the menu bar and then on New Picture, I created a new picture. I changed the name of the picture to S.measuringStation and then finished by clicking the Create button.

Figure 2: Creating a new picture

A newly created picture is empty. First, I chose a rectangle from toolbars on the left side and used it as a background. On the right side there is the palettes section of component where we can change colors, lines and other visual attributes.

The next step is to create an object which will show the actual values from sensors. First I used the text fields from toolbar menu on left side which will indicate a measurand name and unit of measurement. I displayed all values in percentage. On the right pane in the palettes section I changed text color and connected objects (I/O tags) to the text fields. In the text field I wrote down name, unit and {V} mask which will display a value from I/O tag.

New object

If you want to create a new object KOM.EXE must be running in the background. In Demo project KOM.EXE is launched automatically. KOM is the process of communication and processing of I/O tags that allows communication with the control systems via serial communication lines.

In GREDIT application there is a CNF button which opens CNF application where you can easily make the new object. First a small window will open where you have to change both the name of I/O tag and parent.

Figure 3: New object - window

After the name is chosen in the second window is needed to change a few parameters. As a Description you may use the name of I/O tag, value type must be Analog input. According to the documentation in the Address tab, you have to change the address tag to the AI, Number of pin. Information about pins you can find in the GPIO  protocol documentation.

In CNF you can see values from pin. I calibrated them in a very simple procedure. A photoresistor has small resistor in front. I used a led battery from a mobile phone and a minimum value what photoresistor showed was 0. When I switched off all lights and hid the photoresistor in my palm the maximum value was 520. If you want to show this value in percentage you need to convert it. Every object has a Conversion tab which you can find in the Edit objects window in CNF. The easiest way to convert this values is a Linear conversion in the form out = A*In + B. So I had a system of linear equations with two variables in the following form:

Figure 4: Conversion of values

From this linear system I got results A = -10/52 (-0.19) and B = 100. I inserted these two variables in the Conversion tab and now the values are in the percentage.

The calibration for the soil moisture sensor is a little bit complicated because you need soil. First, put the sensor to the dry soil and then pour water inside and look for the lowest value.

For the rain sensor, I used water spray and found the minimum value. When the rain sensor is dry, the value is bigger. But for the rain sensor, I made a local variable which indicates a sort of rain. From the toolbar, I chose Edit local variablebutton and created a local variable called _Title.

Figure 5: Local variable button
Figure 6: Created a local variable

When the local variable is created via a small button on the bottom then you have to change the category to the LOCAL and the value type to the TEXT. Then, in GREDIT next to the local variable button there is another button Edit picture script where I made a short script to the local variable.

The script runs only one after HI is open or schematic changed and saved. For this reason, I used the procedure. In D2000 there are various commands and ways how to create it but the procedure made in the script is the best way, I think.

Figure 7: Procedure made in the script

In the figure 7, you can see the short procedure for changing a text which will indicate the intensity of rain. In the first row there is only the name of procedure and the procedure head. Then there are several if-else for 4 types of rain.

If the value is in the range defined by if-else, the text is assigned to the local variable_Title. The values are not properly measured but for this tutorial they are sufficient. Then, in row 14 you can see the method ON CHANGE. Every time when the value on the Analog port 2 is changed, this procedure rainIndicator is called.

Figure 8: Connecting the local variable

After the script is done the last thing what to do is to create a new text field and connect the local variable. However, the local variables are not in the listed object but next to the entry field you can find the L button. When clicking it, the list of local variables will display. Choose your variable and connect it to the Text field. After this, every time when the value on the rain sensor is changed, the procedure is called and the text is changing according to the value.

After all these steps I opened the HI application. When it was running, I closed all open windows from the Demo project and opened my picture (this is possible by using CTRL + S shortcut or via menu Open -> Picture, then I selected my new picture S.measuredStation).

Figure 9: Opened picture

The next step was to have my picture opened automatically after login to HI application. I opened a CNF application, then I chose a User from the list of objects on the left side. Demo application uses the preconfigured SystemD2000 user; I changed the Composition to S.measuringStation.

Figure 10: Changing composition

The web interface is available at http: //<raspberry_ip_address>/myapp. In CNF application there must be checked if the processes for web interface are running. You can find it in the object type Process and the running process should be: SELF.SES, SELF.TCD, SELF.TTS and SELF.WSC. If the processes are not running, open the D2000 System Console and look for raspberry-pi (my app) in the left pane. Join the process and run the mentioned processes, name and password are standard (SystemD2000:SystemD2000). After I checked the processes I entered a standard username and password and clicked on the Login button. This way I can access the application without any additional software installed on my computer!

XML Import and Export

XML Import and Export can be started from CNF or GREDIT applications. XML Export is the means to export the object configuration in the form of an XML file. First go to System tab and open XML Export settings and check Recursive export with all referenced objects option. After this, choose All types from the listed objects and write down into Mask text field *name of picture*. Then choose your object and click XML Export from popup menu activated via right-click. XML file will be saved to your chosen folder.

All objects can be exported and if you want to import them on another computer or project you can download my S.LedExample and import it to your downloaded Demo project. Open XML Import via menu Object -> XML Import in CNF application. A dialog, displayed in Figure 11, will open. In the left pane find the folder where XML files are saved and import all XML objects.

Figure 11: XML import dialog box

Then open the HI application and open a picture by CTRL + O shortcut. Choose Picture from object types in the left pane and find S.measuringStation picture in the main pane.

Conclusion

That was my first experience with analog ports on raspberry PI and D2000. For the first time I tried to write the procedure in D2000 and after I found out the conversion, everything was good. This is the way how to make simple sensors with analog output except sensors where data format contains more data unit.

Subscription was successful

Thank you for submitting form.

Image Description

Your message was successfully sent.

Thank you for submitting the form.

Image Description

Your message was successfully sent.

Thank you for submitting the form.

Image Description