Objective: Set up and run a Python script on a RevPi to read input from a pushbutton 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).
1. 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 Input I_1 of the RevPi DIO and Ground of your 24 V power supply.
▷ Connect the LED to Output O_1 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 number>.local.
You can find the serial number on the front of the housing.
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 I_1 of the RevPi DIO, and the LED is connected to Output 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, see Getting Started. |
2. 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.
3. 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:
4. Connecting to RevPi Connect 4 #
▷ Verify your RevPi is connected to the same network as your PC.
RevPi Commander automatically scans for connected devices.
▷ Select … to scan manually.
▷ Select the RevPi Connect 4 from the list of detected devices.
Establishing SSH Connection
▷ Select .
❯ A new window opens.
▷ Enter your RevPi’s username and password in the prompt.
❯ After successful login, the RevPi Commander interface displays the device status.
If no control program is uploaded, the interface shows no program status:
5. Uploading and Running a Control Program #
▷ Select in the RevPi Commander to access the file manager.
▷ In the file manager, navigate to the location of your control program.
▷ If not already done, create a dedicated folder for your control programs.
▷ Select your control program and select > to upload it to the RevPi.
▷ Once the upload is complete, select Stop - Upload - Start to run the program.
❯ If there are no errors, the interface displays the following status:
6. Using RevPi Commander Functions #
Configuring Hardware with PiCtory
▷ Select to access Cockpit.
▷ Log in with user name pi and the password.
▷ Select .
❯ PiCtory opens.
See also: System Configuration with PiCtory
Resetting Drivers
▷ Select to resolve potential driver issues.
Accessing Log Files
▷ Select for operational logs and error troubleshooting.
Modifying PLC Options
▷ Select for:
-
Selecting the default start program.
-
Activating or deactivating the software watchdog.
PLC Programm
▷ Select to configure and manage the PLC program.
Key Features
-
Select Python PLC Start Program:
-
Select 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.
7. Deploying a Python Script Using RevPiModIO #
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)
-
Input I_1 is used to read the state of the button.
-
When the button is pressed (assuming it sends
1when pressed and0when released), it will toggle the LED on Output O_1. -
Output 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).
-
▷ Select .
▷ Upload the Python script.
▷ Select Stop - Upload - Start to run the script on the RevPi.
Monitoring the PLC System #
-
On the RevPi Commander homepage, view the system overview, including connected modules.
-
Check the input and output status.
-
Verify the module functionality and troubleshoot if needed.