# Kunbus Revolution Pi RevPi Core 3 and DIO module

**URL:** <https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197>\
**Category:** balenaOS\
**Created:** [October 10, 2019, 9:35am UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197 "2019-10-10T09:35:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcomisso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mcomisso/32/2620_2.png) [@mcomisso](https://forums.balena.io/u/mcomisso)\
**Post date:** [October 10, 2019, 9:35am UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/1 "2019-10-10T09:35:19Z")

</div>

Hello,  
I’ve been able to install balenaOS on this device and run a simple service, but now I would like to interact with the IO module. Has someone ever been able to do something like that?

I’ve added the Kunbus repos and installed the pi\* stuff but I can’t get the module to work, neither access to Pictory.

Cheers,  
Matteo

---

<div class="post-metadata">

**Author:** ![samothx](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@samothx](https://forums.balena.io/u/samothx)\
**Post date:** [October 11, 2019, 8:14am UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/2 "2019-10-11T08:14:40Z")

</div>

Hi @mcomisso  
I will have to ask the team if we have any prior experience with the Kunbus Revolution Pi and its modular infrastructure.  
After taking a look at what the device does it seems that Pictory is a peace of software that needs to run on the device to set up the installed modules. On Balena this would have to be set up in a container. Next step would be to provide the required kernel\_modules / drivers for the attached hardware module.  
Altogether it sounds like it might be a challenging setup. I will come back to you when I have heard from the devices team.

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [October 11, 2019, 9:05am UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/4 "2019-10-11T09:05:24Z")

</div>

Hi. You can use the demo test example from here: [https://github.com/balena-io-playground/revpi-core3-test](https://github.com/balena-io-playground/revpi-core3-test)

You can follow these steps:

1. Download an OS image from dashboard and provision the board with it  
Clone the test application:  
git clone [https://github.com/resin-io-projects/revpi-core3-test](https://github.com/resin-io-projects/revpi-core3-test)

Before booting the board copy the config.rsc file from the cloned application in the resin-boot partition.

Push the application to your board:  
git remote add balena \<your\_app\_repo\>  
git push balena

1. Enter the application’s container and run:  
piControl/piTest/piTest -w O\_1,1

2. Enter the application’s container and run:  
piControl/piTest/piTest -w O\_1,0

And the expected results are these:

1. 

The board should appear as online in the dashboard and running the application

1. 

The pin O\_1 of the DIO module should have 24V.

1. 

The pin O\_1 of the DIO module should now have 0V.

---

<div class="post-metadata">

**Author:** ![mcomisso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mcomisso/32/2620_2.png) [@mcomisso](https://forums.balena.io/u/mcomisso)\
**Post date:** [October 11, 2019, 3:14pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/6 "2019-10-11T15:14:29Z")

</div>

Hi Florin,  
not sure to understand what you mean with this line:

> Before booting the board copy the config.rsc file from the cloned application in the resin-boot partition.

Right now this is my Dockerfile.template:

```
# base-image for node on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/#dockerfile-templates
# and about balena base images here: https://www.balena.io/docs/reference/base-images/base-images/
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:stretch-run

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.
# RUN install_packages git

RUN export DEBIAN_FRONTEND=noninteractive
RUN echo "deb http://packages.revolutionpi.de/ stretch main contrib" > /etc/apt/sources.list.d/revpi.list && echo "deb http://packages.revolutionpi.de/ updates/" >> /etc/apt/sources.list.d/revpi.list && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A217345D3B70E7CE && apt-get update

RUN install_packages python3
RUN install_packages systemd
RUN install_packages python3-revpimodio2 pitest revpi-firmware revpi-tools pictory

# Defines our working directory in container
WORKDIR /usr/src/app

COPY config.rsc /etc/revpi/config.rsc

# This will copy all files in our root to the working directory in the container
COPY . ./

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1

# server.js will run when container starts up on the device
CMD ["python3", "app.py"]

```

The config.rsc has been generated by me using Pictory on this device before flashing it with balenaOS.

Problem is that the DIO module appears not configured.

```
root@ab3ba30:/usr/src/app# piTest -d
Found 2 devices:

Address: 0 module type: 95 (0x5f) RevPi Core V1.2
Module is present
     input offset: 0 length: 6
    output offset: 6 length: 5

Address: 32 module type: 96 (0x60) RevPi DIO V1.4
Module is present, but NOT CONFIGURED!!!
     input offset: 11 length: 70
    output offset: 81 length: 18

```

Any help is appreciated.

Cheers,  
Matteo

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [October 11, 2019, 4:16pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/7 "2019-10-11T16:16:03Z")

</div>

Hi @mcomisso  
I think that Florin mean that after you provision the device with the OS image but before booting it, you should mount the resin-boot partition and manually add the config.rsc of the link repository there.

> <https://github.com/balena-io-playground/revpi-core3-test/blob/master/config.rsc>

---

<div class="post-metadata">

**Author:** ![mcomisso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mcomisso/32/2620_2.png) [@mcomisso](https://forums.balena.io/u/mcomisso)\
**Post date:** [October 31, 2019, 2:16pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/9 "2019-10-31T14:16:38Z")

</div>

Hi guys,  
I’ve managed to have it working.

So, if someone will ever need to do the same:

1. Flash your RevPi Core with the BalenaOS
2. Clone the test application: git clone [https://github.com/resin-io-projects/revpi-core3-test](https://github.com/resin-io-projects/revpi-core3-test)
3. Based on how you connect the DIO module, change the “position” to “32” (if the module is on the right of the RevPi Core) or “31” (if the module is on the left of the RevPi Core) inside the file config.rsc contained inside the test application
4. Connect the RevPi Core via USB, mount the resin-boot partition and copy the config.rsc file in it
5. Enjoy!

I’ve done some tests and it looks like the GUID, name, bmk and offset values inside the config.rsc file are not that useful: I’ve changed them to random values and I’m still able to read and write inputs and outputs.

Thanks a lot for the support!

Regards,  
Matteo

---

<div class="post-metadata">

**Author:** ![afitzek](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/afitzek/32/359_2.png) [@afitzek](https://forums.balena.io/u/afitzek)\
**Post date:** [October 31, 2019, 2:30pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/10 "2019-10-31T14:30:12Z")

</div>

Hi @mcomisso,

Great to hear that it works for you now and thank you very much for sharing your results here.

Regards,

---

<div class="post-metadata">

**Author:** ![mcomisso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mcomisso/32/2620_2.png) [@mcomisso](https://forums.balena.io/u/mcomisso)\
**Post date:** [November 13, 2019, 2:29pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/12 "2019-11-13T14:29:24Z")

</div>

Just to complete this thread: this is my final Dockerfile:

```
# Use the raspberrypi3 type, not the revpi-core-3
FROM balenalib/armv7hf-debian:jessie-run
LABEL io.balena.device-type="raspberrypi3"

ENV LANG C.UTF-8

# Add the RevolutionPi repository
RUN export DEBIAN_FRONTEND=noninteractive
RUN echo "deb http://packages.revolutionpi.de/ stretch main contrib" > /etc/apt/sources.list.d/revpi.list && echo "deb http://packages.revolutionpi.de/ updates/" >> /etc/apt/sources.list.d/revpi.list && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A217345D3B70E7CE && apt-get update

# Install build tools and remove layer cache afterwards
RUN apt-get -q update && apt-get install -yq --no-install-recommends \
	build-essential \
    python3 \
	git \
	systemd \
	python3-revpimodio2 \
	pitest \
	python3-pip \
	&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install paho-mqtt

# Defines our working directory in container
WORKDIR /usr/src/app

# Clone and compile Kunbus's piTest binary
RUN git clone https://github.com/RevolutionPi/piControl
RUN cd /usr/src/app/piControl/piTest && make

# This will copy all files in our root to the working directory in the container
# The same config.rsc file must be put both in the resin-boot partition and inside the container!
COPY config.rsc /etv/revpi/config.rsc
COPY . ./

#switch on systemd init system in container
ENV INITSYSTEM on

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1

CMD ["python3", "app.py"]

```

With this setup I’ve been able to run a really simple Python script that publish via MQTT the status of one input, like this one:

```
import revpimodio2
import paho.mqtt.client as mqttClient

def on_connect(client, userdata, flags, rc):
  if rc == 0:
    print("Connected to broker")
    global Connected
    Connected = True
  else:
    print("Connection failed")

Connected=False
broker_address="my-mqtt-broker"
port=1883

client = mqttClient.Client("RevolutionPi")

def EventFunction(ioname, iovalue):
    """Event function, which is executed when the value changes."""
    print("Input {} now has value {}".format(ioname, iovalue))
    client.on_connect = on_connect
    client.connect(broker_address, port=port)
    client.publish("topic",'{ "RevolutionPi": { "I_1": "' + str(iovalue) + '" } }')

# Instantiates RevPiModIO
rpi = revpimodio2.RevPiModIO(autorefresh=True, configrsc="config.rsc")

# Catch Strg+C signal and exit program clean
rpi.handlesignalend()

rpi.cycletime=500

# Register input events
rpi.io.I_1.reg_event(EventFunction)

# Start event processing (program will block here)
print("Start mainloop")
rpi.mainloop()

```

I hope this could be useful!

Regards,  
Matteo

---

<div class="post-metadata">

**Author:** ![savnik](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@savnik](https://forums.balena.io/u/savnik)\
**Post date:** [February 11, 2021, 7:51pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/14 "2021-02-11T19:51:45Z")

</div>

> [@mcomisso](#):
>
> `COPY config.rsc /etv/revpi/config.rsc`

Hi, I’am trying to reproduce this in my own setup.  
Is it a typo or intention in the path /etv/… ?

---

<div class="post-metadata">

**Author:** ![mithsG](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@mithsG](https://forums.balena.io/u/mithsG)\
**Post date:** [February 18, 2022, 4:54pm UTC](https://forums.balena.io/t/kunbus-revolution-pi-revpi-core-3-and-dio-module/36197/15 "2022-02-18T16:54:16Z")

</div>

HI foks,

I have setup of kunbus revolution pi Revpi core 3 and DIO module connected to sensor.  
The value of the sensor I am able to read on I\_14.  
I need to write bash script or python script to publish and subscribe to access the sensor data using MQTT.  
i am new to kunbus rev pi need guidance.  
your help is appreciated ASAP

Thanks in advance
