Welcome to the Revolution Pi with Python

Program your Revolution Pi of Kunbus GmbH with Python!

Python module

This module provides you with various functions to access the hardware of the Revolution Pi with your Python program. It does not matter whether you come from the PLC sector and program cyclically or event-based as an application developer of e.g. Raspberry Pi.

PLC System for software, network and MQTT

With our RevPiPyPLC system you can make fast IO-Checks over the network, upload your control program, start it at system start and transfer all IO data via MQTT. Or simply write data from any Python system to the process image.

And there are no license fees!

Example for a flipflop with RevPiModIO


# -*- coding: utf-8 -*-
"""Flip Flop control cycle."""
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2021 Sven Sager"
__license__ = "GPLv3"

import revpimodio2

def main(ct: revpimodio2.Cycletools) -> None:
    """RevPiModIO will call this function every 50 milliseconds."""
    if ct.first:
        # This is True in first cycle only / on program start

        # Define all your variables inside the ct.var object
        ct.var.counter = 0

    # You can use sub routines to split the cycle into logical parts
    flip_flop(ct)  # Always pass the ct object

    # Show the health of your program, by flashing the green A1 led

    # You may want to use the watchdog, so toggle it!

    if ct.last:
        # This is True in last cycle only / program exit
        print("I_7 goes {0} times to True".format(ct.var.counter))

        # Set save IO states before exit

def flip_flop(ct: revpimodio2.Cycletools):
    This is the logic of a sub routine inside the cycle.

    If Input I_7 goes to true, it will invert the actual state
    of the Output O_1.
    if ct.changed(ct.io.I_7, edge=revpimodio2.RISING):
        # ct.changed compares the state of I_7 with the last cycle
        ct.var.counter += 1
        ct.io.O_1(not ct.io.O_1())

revpimodio2.run_plc(main, cycletime=50)  # 50ms is the default



# -*- coding: utf-8 -*-
"""Flip Flop control cycle."""
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2021 Sven Sager"
__license__ = "GPLv3"

import revpimodio2

# Define global variables
counter = 0

def evt_i_7(name, value) -> None:
    """Event function for input I_7 will invert state of O_1."""
    global counter
    counter += 0
    rpi.io.O_1(not rpi.io.O_1())

def toggle_led_wd(name, value) -> None:
    """By changing the LED, we will start the next timer event."""

    # Show the health of your program, by flashing the green A1 led
    rpi.core.a1green(not rpi.core.a1green())

    # You may want to use the watchdog, so toggle it!

def clean_up():
    """Will be called at the end of the program."""
    print("I_7 goes {0} times to True".format(counter))

    # Set save IO states before exit

# Create the RevPiModIO object
rpi = revpimodio2.RevPiModIO(autorefresh=True)

# This will catch exit signals and calls the clean_up function

# Register an event function to input I_7 for changing state to True
rpi.io.I_7.reg_event(evt_i_7, edge=revpimodio2.RISING)

# Register a timer event to change state of A1 LED every 500 ms
rpi.core.a1green.reg_timerevent(toggle_led_wd, 500, prefire=True)

More examples


Version 2.5.8

Important update Fixes errors when using shared_procimg when querying the output status, especially in .cycleloop(…). The status of set outputs was one cycle behind. So the values of the outputs in the next cycle were still at the old status. Offset check of the entire process image and omission of overlapping IOs. When using several …

Version 2.5.7

Important update Corrects errors in the length specifications of the memory areas from the process image if the piCtory configurations have gaps. This has been discovered so far with the “Modbus Master 150” module. The error means that the IOs of modules behind the incomplete module are not correctly synchronized. Flat: Switch button and relay …

Version 2.5.6

Important update! Fixes cycle problem with shared_procimg=True As soon as a new value was assigned to an output, RevPiModIO immediately wrote it into the process image. Outputs may only be written to the process image after the cycle function has been completely processed (when using .cycleloop) or after calling .writeprocimg. The error is not relevant …