January 11, 2022

Victron VE.Direct with Raspberry Pi/Signal K

Updated 2022-01-11 !

During my update of the cables going from the batteries, to the distribution panel and engines, I stumbled over the Victron SmartShunt(VSS). We had a 15 year old Mastervolt battery monitor but it didn't feel "true" and it wasn't at the right place in the boat. So instead of moving the old shunt we bought a VSS. 

Introduction
The VSS don't have any display but can be used, standalone via Bluetooth, with the VictronConnect app which is available for different OS

If you want to get the data from VSS via a cable there is a serial VE.Direct(VED) output which can be connected to a 

Cables
To get the serial data, to the SK server, the most straightforward way is to buy the Victron USB interface cable, and connect it to the computer running the Signal K server.

Here we will check out two DIY ways to connect to a Raspberry Pi(RPi) but please note !! that these solutions don't have galvanic isolation as the Victron cables have.

Victron have different products with the VED interface and they have different logic levels. For the VSS it's 3,3 V so it matches the RPi inputs.

Using a "standard" USB to serial console cable you do the connection as follows. The VSS pin numbers are found in the picture above. If you want to validate this cable, check below at Cable check.    

 VSS pin         USB cable color
 Gnd, 1          GND, Black
 TX, 3      RX, White

Another way is to use a "direct cable" connected like this

 VSS pin         RPi pin
 Gnd, 1          GND, 9
 TX, 3      RX, 10

The cable could be a JST PH 4Pin cable.

USB cable
After Connecting the USB cable it will probably appear as "/dev/ttyUSB0". Check with 

dmesg | grep tty

Direct cable
Per default the RX/TX pins, on any Raspberry Pi, are setup as a serial console. This means that you can use the USB console cable, mentioned above, to log on from almost any computer, which have an USB port, to the RPi. We have to disable this function with 

sudo rasp-config


3. Interface options => 

    I6 Serial Port Enable/disable shell messages on serial connection

    

    Would you like a login shell to be accessible over serial? => No

    Would you like the serial port hardware to be enabled? => Yes


    The serial login shell is disabled

    The serial interface is enabled  => OK


Shutdown with "sudo shutdown now", connect the 2 cables, boot up and check with

dmesg | grep tty

probably it will appear as "/dev/ttyS0"

Check the output
In both cases you have to set the port baudrate, matching the output from the VSS, with 

stty -F /dev/ttyXX 19200

the "ttyXX" should be exchanged with what you got above. Then check the data with

cat /dev/ttyXX

and you will see something like

PID 0xA389

V 13515

VS -12

I -453

.........

Send to Signal K
Direct attached VSS
Via the SK Appstore install "@signalk/vedirect-serial-usb" and configure it via "Plugin Config".
Using the SK "Data Browser" check the data.

Remote VSS
In our boat the batteries are in the aft part and the SK server is ahead. So the solution was to place a Raspberry Zero W(RZ), at the VSS, avoiding long cables. The shunts serial output connects, with a "Direct cable", to the serial input on the RZ. 

With "socat"
There are several solutions to send the data from the RZ to the SK server but the solution, with the smalest footprint, is to use "socat" and forward the data via UDP.

Install "socat" with "sudo apt install socat" and test the output from VSS with 

socat /dev/ttyS0,b19200,raw,echo=0,crnl -


Interrupt the command with Ctrl +c and then issue the command 

socat -u /dev/ttyS0,b19200 UDP-SENDTO:zest:8888


where "
zest" is the hostname of the target SK server. Configure the plugin on the target SK server to receive UDP at the right port number and check the data in "Data Browser".

If you want this command to be working in the background, autostart at boot and restart if it fails I really recommend using systemd. Check this post and search for "Autostart with systemd" where you get some hints for the setup.

With Signal K
Another way could be to set up a complete SK server on the RZ with the use of the 
"@signalk/vedirect-serial-usb" plugin. When the RZ is setup it will automagically appear, at the target SK server, where you use that suggestion to set upp the connection.

Please note that Node.js 16 have to be installed via binaries on the RZ. Check below.

This approach could also be used due to that you want to use the embedded NodeRed plugin, on the RZ, where one of the use cases could be to connect an analog to digital converter ADS1115. Check this post where the node "signalk-send-pathvalue" is used.

With Node-Red
With Raspberry Pi OS Lite install Node-Red, "node node-red-node-serialport", "node-red-contrib-ads1x15_i2c" and import this flow.

The flow part with the "ADS 1015" node is from this post.

Cable check
A loopback test will check the mentioned cable. Connect the RX(white) and the TX(green), cable to each other and in a terminal window issue the receive command 

socat /dev/ttyUSB0,b19200,raw,echo=0,crnl -

In another terminal window issue the send command

echo "Test data" > /dev/ttyUSB0

If you receive the text in the listen window you have succeeded and the cable is OK.

This test also applies to testing the "direct" port on the RPi and then doing a connect between between the GPIO pin 9 and 10.

Node.js 16 on Raspberry ZW
Hints .....

https://nodejs.org/dist/
https://nodejs.org/dist/latest-v16.x/
wget https://nodejs.org/dist/latest-v16.x/node-v16.14.0-linux-armv7l.tar.gz
tar -xzf node-v16.14.0-linux-armv7l.tar.gz
node-v16.14.0-linux-armv7l/bin/node -v
v16.14.0
cd node-v16.14.0-linux-armv7l
sudo cp -R * /usr/local/

node -v
npm -v

rm node* -rf

10 comments:

  1. Good Page. Do you know what minimum RAM / SD Card you need on the Raspberry Zero just to run the Signal K server for transmitting as you do ?

    ReplyDelete
    Replies
    1. Thx. With RPi OS Lite together with Signalk and the plugins NodeRed and VE.Direct up and running the usage is
      * 1.9 Gb on the SD card
      * 60 % RAM

      Delete
  2. Thanks a lot for your page again! I followed step by step and it worked. I struggled a bit for connecting the secondary signalk server running on a pi zero w to the main server (on the main server sometimes it discovers the secondary server, sometimes not - in this case you have enter the address directly in the pluggin config interface.
    What is important is the "map remote self to local self setting".

    I have some questions / comments:

    1) I made the cable myself with an UART to USB, but I didn't connect the 5V pin as the Blue Solar Charger seems to get its power from the solar panels and produces 5V on the JST 5V pin. But in the night, of course, it switches off and I cannot get the values from the blue solar charger. DO you think I can connect the Blue Solar 5V pin to a 5V power supply (for instance the raspi zero power so it could work even with no sun?

    2) I couldn't make the pi zero recognize the serial port when I powered the Raspberry on the first USB port and plug the UART on the second USB port. After hours trying everything, I just powered the pi zero on the 5V GPIO pin and plug the UART in the first USB port, and it worked immediately.

    3)I have a Victron Blue solar 75/50. There are some values I can see in the victronconnect App on my cell phone that don't appear in the Signalk server (for instance solar current, and all the victron settings etc.). Is it because the plugging doesn't implement them or that these values are available on request from the victronconnect app, or something else? For instance, the app is able to show the history of the charging, so where are these values???

    4) What exactly are the YIELD values displayed by the pluggin, and more generally is there a reference document of the Blue Solar values?

    Cheers!

    ReplyDelete
    Replies
    1. Thx. Unfortunately I'm not familiar with the Blue Solar product so please turn to the Victron forum.

      1-2/ I had no problems, with any of the described solutions, receiving data from the shunt.
      3/ Use Slack to ask questions regarding the plugin
      4/ There is a link above for the VED protocol, it maybe helps ?

      Delete
  3. Thanks for this! I was struggling with connecting my smartshunt to my raspberry pi using a DYI cable as well. Tried just snipping the V+ wire and after that everything works!

    ReplyDelete
  4. Morten Myklebust18 May 2022 at 09:59

    Thanks. This helped me a lot. Sending data from the smartshunt with socat works like a charm. Since the rpi zero are installed in the engine compartment I'm working on using it for temp monitoring also. Thinking of using CollectD to read onewire sensor and sending to the server for processing....

    ReplyDelete
    Replies
    1. Nice ! CollectD was new to me, interesting. I'm hooked on NodeRed. Done some posts with DS18B20, just search my blog.

      Delete
  5. Hi, I achieve to connect a bmv712 to a raspberry pi 4b (signalk with openplotter) and then to a nmea2000, works perfect but weird thing: if I reboot the raspberry the plugin (@signalk/vedirect-serial-usb) seems to not work until I go to the plugin config and click somewhere as awake it? Thanks for any ideas!

    ReplyDelete
    Replies
    1. Hi, haven't had that problem myself so recommend to use Slack for direct contact with the developers. Send an invite from https://signalk.org/ found in the upper right.

      Delete

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !