RemoteGPIO: Adding Relays and Digital Inputs

This solution is mainly targeting Cerbo GX users that wants to extend Digital Inputs and Relays on their system.
Please note that there is a conflict with Kwindrem’s RpiGpioSetup that is targeting Raspberry pi users, but we have some users that reports to have successful setup with rPI and RemoteGPIO.

In order to have a reliable direct attached interface to the relay, I selected a Modbus/RTU based relay from Dingtian that attaches on the USB port of the Cerbo GX.
There are many solutions for attaching relays via Ethernet, but I didn’t the relays to rely on an external Ethernet network switch. That said, the driver is now also supporting this Dingtian device via TCP/IP.

This Dingtian box provide 8x relays, that can be controlled with Modbus Serial, but also over IP and with various additional protocols: https://fr.aliexpress.com/item/4000999069820.html
They have variants of 4 or 8 relays.
A USB to RS 485 adapter will be required, and I strongly recommend to go with a RS485 to USB adapter based on FTDI chipset, in particular FT232R and follow the instructions on how to program it.

You can find an extensive questions and answers as well as all the required links (As a new user on the new Community page, I’m limited to 2x links and 5 pictures in this post…) on the previous Victron community thread dedicated to RemoteGPIO here: https://communityarchive.victronenergy.com/questions/245584/remotegpio-ex-venus-rgpio-now-available-with-setup.html

Below I’m trying to capture most of the relevant information.

RemoteGPIO (ex venus_rgpio) now released in v3.2.1

******* UPDATE Version 3.3.0 ****************

No more reboot required after configuration change, just ise restart RemoteGPIO services.

CPU resources optimisations: Overall cpu usage can be reduced by up to 75% depending on number of modules and options selected.

Several settings menu enhancements. Added option to enable/disable digital inputs per module. Added option to ‘Restart RemoteGPIO’ from the menu.

Thanks to Derrick (drtinaz)

******* UPDATE Version 3.2.2 ****************

Relays confirm to work with RaspBerry, but Digital Input won’t. It will require additional work for making Digital Inputs working with RaspBerry.

******* UPDATE Version 3.2.1 ****************

Removed option for 16x relay module. It will require different driver version

Added support for reading relays status and updating GUI. This option is set to default off in RemoteGPIO settings.

****** UPDATE Version 3.2 **********

Support for 2, 4, 8, and 16x relais modules.

Support up to 3x units.

Thanks to Derrick for adding the above

As we don’t have all the units here to test, thanks in advance to report here your experience with the 16x relai version.

****** UPDATE Version 3.0 ************

I am happy to announce here that version 3.0 is finally released with many changes.

Configuration is done from the Venus OS graphical interface, no more file editing is required.

The big change is how RemoteGPIO is integrated into Venus OS: it is now natively integrated at the D-Bus level, allowing the use of relays and GUI digital inputs straight from the GUI.

RemoteGPIO runs as a service in VenuOS without the need to run NodeRed with Venus OS Large. NodeRed is still supported for advanced integration.

I encourage you to upgrade to version 3.0.

capture-decran-2024-03-16-a-120338.pngcapture-decran-2024-03-16-a-120417.pngcapture-decran-2024-03-16-a-120426.pngcapture-decran-2024-03-16-a-120704.pngcapture-decran-2024-03-16-a-120753.png

As of today up to 18 additional relays and digital inputs are supported with two 8x relay Dingtian units. Both TCP and RS485 models are supported. I will add support for different Dingtian size models soon.

The latest GuiMods version must be installed. A big THANK YOU to Kevin Windrem for updating GuiMods and PackageManager in order to cooperate nicely with RemoteGPIO.

Thanks to the contribution from Thomas, RemoteGPIO is now version independent, starting with Venus OS 2.92 or later required.

For the boating community, I have some cool stuff coming up on top of RemoteGPIO, which I’ll be launching soon!

Specific setup for USB-RS485 adapters to work sine with no conflicts with other adapters such the ones used for various BMS:

I propose here a solution to better handle USB to RS485 interface with RemoteGPIO, making sure there will be no more conflicts with other services requiring the same model of USB to RS485 adapter.

The solution I Propose is to purchase an adapter based on FTDI chipset, in particular FT232R based. These are still inexpensive and have the advantage to be reprogrammed on demand.

Follow this procedure:

1/ Download FT_Prog - EEPROM Programming Utility from their website in the utilities page

As of 7th March the version is 3.12.46.653

and install it on Windows (I tried Windows 7 successfully)

2/ Connect the USB to RS485 you wish to reprogram and select the driver you just downloaded

3/ Let Windows to search on internet the right driver

4/ Run FT_Prog

5/ Press F5 to scan the USB bus (go to menu DEVICES and select Scan and Parse

It should display a device in the Device Tree

6/ Select USB String Descriptors in the Device Tree and update the Product Description with « RemoteGPIO » (original value is « FT232R USB UART »

7/ Select Program in DEVICES menu

Hit Program button

8/ Hit F5 to scan again and confirm RemoteGPIO is now the correct Product Description in the USB String Descriptors

Note:

Note: The previous version is still available, you just need to change the branch (or tag) to “old” in PackageManager. The latest version is v2.4.2 and supports Venus OS from v2.92 to v3.22.


I’m glad to announce that finally I made available the USB Relay Gateway compatible with SetupHelper Package Manager.

All Venus releases from v2.92 up to currently latest v3.12 are supported and tested. And thanks to SetupHelper it will be fairly easy to maintain and support next Venus releases.

This package is mainly targeting Cerbo GX users that wants to extend Digital Inputs and Relays on their system.

Please note that there is a conflict with Kwindrem’s RpiGpioSetup that is targeting Raspberry pi users

In order to have a reliable direct attached interface to the relay, I selected a Modbus/RTU based relai from Dingtian that attaches on the USB port of the Cerbo GX.

There are many solutions for attaching relays via Ethernet, but I didn’t the relays to rely on an external Ethernet network switch.

This Dingtian box provide 8x relays, that can be controlled with Modbus Serial, but also over IP and with various additional protocols:

They have variants of 4 or 8 relays.

A USB to RS 485 adapter will be required.

I selected this one as this is coming with a USB cable and can fit nicely on the Cerbo GX:
The RS485 must be connected on the first USB port of the Cerbo GX

SETUP:

=====

The setup is now fully automated, no more requirement to issue shell commands! :slight_smile:

It runs only with VenusOS Large with minimum version 2.92

1/ Configure the Relay Module

The Dingtian IOT Relay module needs to be configured so Modbus RTU works:

Connect the ethernet interface of the module and access to its configuration page (192.168.1.100 and admin/admin by default).

Configure the RS485 with Protocol Modbus-RTU and set address to 1 (for the first unit).

For TCP control, configure the TCP Server with ModBus-RTU over TCP

Example configuration for 1st Dingtian unit

Example configuration for 2nd Dingtian Unit. Addr in RS485 needs to be set regardless control is RS485 or TCP

2/ VenusOS Large

Install the desired VenusOS Large version (minimum v2.92)

Optional: Enable Node-RED (Settings/Venus OS Large features)

3/ Install RemoteGPIO

Make sure SetupHelper from Kwindrem is installed. If not follow instructions from kwindrem Github SetupHelper project

Add RemoteGPIO repo if not already listed in the inactive packages RemoteGPIO Lucifer06:main

Download and install the package

BE PATIENT during the Installation of the package, it can takes few minutes as it downloads few Node-RED palettes

Reboot will be required for the USB to be not anymore preempted by VenusOS services

Using RemoteGPIO:

=================

1/ RemoteGPIO can be used from VenusOS GUI to control 4x additional relays.

It is required to install Kwindrem’s GuiMods package

Go to Settings/Relay there are 4x additional relays to be enabled and then use the dedicated Relay page that should display the additional relays

2/ RemoteGPIO can also be used with Node-RED

With Node-Red it is possible to use all 8x relays as well as the 8x digital inputs

During the installation of the package, the following Node-RED palettes are automatically installed:

— node-red-dashboard

— node-red-contrib-buffer-parser

— node-red-contrib-debounce

If there was no flows yet running the RemoteGPIO flow got installed

If a flow was already installed, in order to not break anything RemoteGPIO will need to be manually imported from the local library (Menu Import / Local / RemoteGPIO.json)

The RemoteGPIO flow is also adding a Node-RED dashboard for controlling the Relays and monitoring the Digital Inputs

RemoteGPIO v2.x is backward compatible with previous venus_rgpio

Troubleshooting:

================

Any questions or suggestions about RemoteGPIO are welcome here

Most of the issues are coming from USBtoRS485 adapter been trapped by the wrong VenusOS service.

In order to make it working with default configuration file, it is important to attach it to the first USB port.

IMPORTANT If a different adpater is used, or if a different USB port is used (or connected behind a USB hub) the file /etc/udev/rules.d/serial-starter.rules will required to be tweaked accordingly so the USB-RS485 adpater is always accesible with /dev/ttyUSB0

Toubleshooting from command line with dbus

List of all dbus relays and their status:

dbus -y com.victronenergy.system /Relay GetValue

Close Relay 3:

dbus -y com.victronenergy.system /Relay/3/State SetValue %1

Toubleshooting from command line with modbus

Read Digital Inputs:

/data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -r 11 -s 1 -c 1 /dev/ttyUSB0

Close Relay 1:

/data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -1 -r 3 -s 1 -c 1 /dev/ttyUSB0 257

Open Relay 1:

/data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -1 -r 3 -s 1 -c 1 /dev/ttyUSB0 256

Check that no process are talking to USB0:

ps | grep USB0

Should return only rgpio services. If not, it may be required to reboot VenusOS for the serial-starter.rules to apply

Prevent USB0 to be used by another service:

/opt/victronenergy/serial-starter/stop-tty.sh ttyUSB0

2 Likes

I hope to able soon to update this post with all the correct links and pictures so you don’t have to go back to the Archive Community Victron page.