This tutorial shows you how to set up and run a Python script on a RevPi Connect to read input from a push button and control an LED.
Prerequisites #
Hardware #
✓ RevPi Connect 4
✓ RevPi DIO
✓ PiBridge plug connector (comes with the RevPi DIO)
✓ 24 V Power Supply
✓ 24 V LED
✓ Push-Button
✓ PC
Software #
✓ Modern web browser (e.g., Google Chrome or Mozilla Firefox).
Setting up the System #
For detailed instructions, refer to the Getting Started.
▷ Make sure your power supply is switched off.
▷ Connect the RevPi DIO to your base module using the PiBridge Adapter.
▷ Wire up your RevPi base module (e.g. RevPi Connect 5) and RevPi DIO to the power supply.
Make sure to also connect the Input and Output connections on top of the RevPi DIO.
▷ Connect your Push-Button to Input1 of the RevPi DIO and Ground of your 24 V power supply.
▷ Connect the LED to Output1 of the RevPi DIO and Ground of your 24 V power supply.
Powering Up the RevPi #
▷ Switch on the power supply.
▷ Ensure the RevPi is connected to your local network for accessibility.
You should be able to reach your RevPi via revpi[Serial].local
.
Serial is the middle number printed above the data matrix code on the front of your RevPi. Alternatively, you can enter the IP address of the RevPi in the web browser.

System Diagram #
Below is the diagram illustrating the connection setup. The button is connected to Input 1 (I_1) of the RevPi DIO, and the LED is connected to Output 1 (O_1). The button will be used to toggle the LED on or off.

Accessing the RevPi Interface #
▷ Open a web browser on a device connected to the same network.
▷ Access the RevPi system using its IP address.
Note
|
For network troubleshooting or determining the IP address of your RevPi, consult Getting Started. |
Step 1: Configuring the Hardware in PiCtory #
▷ Assign appropriate I/O names for easier reference, e.g., Output1_LED und Input1_button..
▷ Save the configuration and restart the driver to apply the changes.
Step 2: Installing and Starting RevPi Commander #
▷ Download the RevPi Commander software and install it on your PC.
Refer to the installation guide.
▷ Launch the software on your PC.
The interface will open as shown below:

Step 3: Connecting to RevPi Connect 4 #
Ensuring Network Connection #
▷ Verify your RevPi is connected to the same network as your PC.
Scanning for RevPi Devices #
RevPi Commander automatically scans for connected devices.
▷ To manually scan, go to File and select Search Revolution Pi.

Entering Login Credentials #
❯ A new window will open in which you must enter your login details.
▷ Enter your RevPi’s username and password in the prompt.
Confirming Connection #
❯ After successful login, the RevPi Commander interface will display the device status. If no control program is uploaded, the interface will show no program status:

Step 4: Uploading and Running a Control Program #
Opening the PLC Developer #
▷ In RevPi Commander, go to
to access the file manager.Selecting Control Program #
▷ In the file manager, navigate to the location of your control program.
▷ If not already done, create a dedicated folder for your control programs.

Uploading the Program #
▷ Choose your control program and select the right arrow icon to upload it to the RevPi.

Running the Program #
▷ Once the upload is complete, select Stop-Upload-Start to run the program.
▷ If there are no errors, the interface will display the following status:

Step 5: Using RevPi Commander Functions #
Configuring Hardware with PiCtory #
▷ In RevPi Commander, go to
to access PiCtory.Resetting Drivers #
▷ Use the Reset Drivers option to resolve potential driver issues.
Accessing Log Files #
▷ In RevPi Commander, go to
for operational logs and error troubleshooting.Modifying PLC Options #
▷ In RevPi Commander, go to
to do such a change like:-
Selecting the default start program.
-
Activating or deactivating the software watchdog.

PLC Programm #
▷ In RevPi Commander, go to
The following options are available:

Key Features #
-
Select Python PLC Start Program:
-
Choose the program to run on the RevPi.
-
Specify arguments for the program if needed.
-
Enable write permissions for the working directory.
-
Set a software watchdog (0 to disable).
-
-
Transfer PLC Program:
-
Select the upload format (e.g., ZIP Archive).
-
Include PiCtory configuration during the upload.
-
Optionally clear all existing files on the RevPi before uploading.
-
-
Available Actions:
-
Download: Retrieve the current PLC program from the RevPi.
-
Upload: Upload a new PLC program to the RevPi.
-
-
Manage Control Files:
-
PiCtory Configuration: Download or upload your hardware configuration.
-
Process Image: Download the current process image from piControl0 for verification or debugging purposes.
-
These settings help you define, upload, and manage the behavior of your PLC program on the RevPi system.
Step 6: Deploying a Python Script Using RevPiModIO #
Writing a Python Script #
Create a Python script (e.g., Revpi_.py
) using RevPiModIO with the following content:
import revpimodio2
import time
# Initialize the RevPiModIO object
rpi = revpimodio2.RevPiModIO(autorefresh=True)
while True:
# Read the value of Input1 (button)
button_state = rpi.io.I_1.value
# If the button is pressed (assuming value 1 means pressed)
if button_state == 1:
# Turn on the LED by setting Output1 to 1
rpi.io.O_1.value = 1
else:
# Turn off the LED by setting Output1 to 0
rpi.io.O_1.value = 0
# Print the button state and LED output value for verification
print(f"Button state: {button_state}, LED state: {rpi.io.O_1.value}")
# Wait for a short period before checking again
time.sleep(0.1)
Explanation:
Input1 (I_1) is used to read the state of the button.
When the button is pressed (assuming it sends 1 when pressed and 0 when released), it will toggle the LED on Output1 (O_1).
Output1 (O_1) is controlled based on the button state:
If the button is pressed (I_1.value == 1), the LED will be turned on (O_1.value = 1).
If the button is not pressed (I_1.value == 0), the LED will be turned off (O_1.value = 0)
Uploading the Script #
▷ In RevPi Commander, open PLC Developer as explained in Step 4.1.
▷ Upload the Python script as described in Step 4.3.
Executing the Script #
▷ After uploading, select Stop-Upload-Start to run the script on your RevPi.
Monitoring the PLC System #
-
On the RevPi Commander homepage, view the system overview, including connected modules.
-
Check input and output status.
-
Verify module functionality and troubleshoot if needed.
