Skip to main content

Python Tutorial

Introduction

Prerequisites

Hardware

  • RevPi Base Module
  • RevPi DIO Module
  • PiBrige connector (comes with the DIO module)
  • 24V Power Supply
  • A 24V LED
  • A Push-Button
  • A PC

Software

  • A modern web browser (e.g., Google Chrome or Mozilla Firefox).

System Setup

Follow these steps to configure your system. For detailed instructions, refer to the Getting Started guide.

▷ 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) and RevPi DIO to the power supply. Make sure to also connect the Input and Output connections on top of the DIO module.

▷ Connect your Push-Button to Input1 of the RevPi DIO module and Ground of your 24V power supply.

▷ Connect the LED to Output1 of the RevPi DIO and Ground of your 24V power supply.

  • Power 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 where Serial is the Middle Number printed above the Data Matrix Code on the Front of your RevPi.

    Serial Number

  • 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.

    System Diagram

  • Access 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 the Getting Started guide.

Step 1: Configure the Hardware in PiCtory

Start PiCtory.

Add the RevPi DIO module to your configuration.

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: Install and Start RevPi Commander

  1. Install RevPi Commander
    Download and install the software on your PC. Refer to the installation guide.

  2. Open RevPi Commander
    Launch the software on your PC. The interface will open as shown below:

    Start RevPi Commander

Step 3: Connect to RevPi Connect 4

Ensure Network Connection

  • Verify your RevPi is connected to the same network as your PC.

Scan for RevPi Devices

  • RevPi Commander automatically scans for connected devices. To manually scan:

▷ Go to File and click Search Revolution Pi.

Search RevPi

Select Your Device

▷ Choose your RevPi Connect 4 from the list of detected devices.

Select RevPi

Establish SSH Connection

▷ Click Connect to RevPi and select Connect via SSH (recommended).

Connect SSH

Enter 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.

Confirm 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:

    RevPi Status

Step 4: Upload and Run a Control Program

Open the PLC Developer

  • In RevPi Commander, go to PLC > PLC Developer to access the file manager.

Select Your 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.

    Open File Manager

Upload the Program

  • Choose your control program and click the right arrow icon to upload it to the RevPi.

    Upload Program

Run the Program

  • Once the upload is complete, click Stop-Upload-Start to run the program.

  • If there are no errors, the interface will display the following status:

    Program Running

Step 5: Use RevPi Commander Functions

Configure Hardware with PiCtory

  • In RevPi Commander, go to PLC > PiCtory Configuration to access PiCtory.

Reset Drivers

  • Use the Reset Drivers option to resolve potential driver issues.

Access Log Files

  • In RevPi Commander, go to PLC > PLC Log Files for operational logs and error troubleshooting.

Modify PLC Options

  • In RevPi Commander, go to PLC > PLC Options to do such a change like:

    • Selecting the default start program.
    • Activating or deactivating the software watchdog.

    PLC Options

PLC Programm

  • In RevPi Commander, go to PLC > PLC Programm to configure and manage your PLC program. The following options are available:

    PLC Programm

Key Features:

  1. 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).
  2. 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.
  3. 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: Deploy a Python Script Using RevPiModIO

Write a Python Script

Create a Python script (e.g., Revpi_.py) 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)

Upload the Script

  • In RevPi Commander, open PLC Developer as explained in Step 4.1.
  • Upload the Python script as described in Step 4.3.

Execute the Script

  • After uploading, click Stop-Upload-Start to run the script on your RevPi.

Monitor the PLC System

Overview

  • On the RevPi Commander homepage, view the system overview, including connected modules.

  • Check input and output status.

  • Verify module functionality and troubleshoot if needed.

    System Overview