Getting Started Raspberry Pi GPIO

The Open Automation Software platform has a built in communication driver for General Purpose Input / Output when deployed on a Raspberry Pi 4.  Tags can be defined to read or write to GPIO pins.

You can view the OAS GPIO Setup Video to familiarize yourself with the following steps to setup GPIO communications on your Raspberry Pi 4.

The following steps can be used to setup communications with the GPIO pins.

Step 1

Download and install OAS onto Raspberry Pi 4 device.  View the Raspberry Pi Installation guide for an easy to following video instructions or use the Linux Installation guide for step by step instructions to use the simple install script.

Step 2

Setup access to gpiomem for the user account the OASEngine is running under.  The default is oasuser.

This is achieved by adding a rules file to etc/udev/rules.d/.

Log in to the root account and change directory to etc/udev/rules.d/.

ssh ubuntu@<ip address of Raspberry Pi>
cd /etc/udev/rules.d/

Create a file oas-gpio.rules with an editor with the following contents, then save the file.

SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:oasuser /dev/gpiomem && chmod -R 660 /dev/gpiomem'"

To create and edit the file you can use nano.

sudo nano oas-gpio.rules

Reboot the system.

sudo reboot

Step 3

OASFrom a Windows system start Configure OAS application from the program group Open Automation Software.

Step 4

Select Configure-Tags.

Configure Tags

Enter the IP Address of the Raspberry Pi device and click Select.

Note: Optionally select the Live Data Cloud node if you are hosting data from the Raspberry Pi over the Internet with a standard Internet connection.

Step 5

Select ADD GROUP to add the group GPIO and click OK.  The group name can be anything you like, in this example it will be GPIO.

With the GPIO group selected click on ADD TAG to a tag with the name Pin 5.  The tag name can be anything you desire.  In this example we are assigning to GPIO Pin 5 so we will name it Pin 5.

Step 6

Change the Data Type of the tag to Boolean.

Change Data Source Tag property to GPIO.

Set the Pin Mode to one of the following.

Input: Read Only – Configures the GPIO pin in floating mode, with high impedance.
InputPullDown: Read Only – Configures the GPIO pin as high impedance with a pull-down resistor to ground.
InputPullUp: Read Only – Configures the GPIO pin as high impedance with a pull-up resistor to the voltage charge connection (VCC).
Output: Write Only – Configures the GPIO pin in strong drive mode, with low impedance.

Note: A pin cannot be set to both Input and Output.  Inputs are read only.  Outputs are write only.

When defining the pin as an input set the desired Polling Rate for the update speed.

Select Apply Changes to activate the pin communications.

Step 7

To define multiple tags use the CSV Export and CSV Import on the toolbar in the upper right together with Microsoft Excel.

Note: You can also programmatically define Tags and Drivers using the OPCSystems .NET component with the TagCSVImport and DriverInterfaceCSVImport methods or the REST API.

Step 8

Select the Save button on the toolbar at the top.

Save Button

Optionally create a directory on the Raspberry Pi and specify a file name to save to and select SAVE.

Step 9

Under Configure – Options set the Default Tag Configuration File so when the device restarts the tag file will automatically be loaded.