├── README.md ├── backlightctl.sh ├── mcp3208-overlay.dtb ├── slcan.rules ├── slcan_add.sh ├── slcan_remove.sh └── venus_rpi_enablement.md /README.md: -------------------------------------------------------------------------------- 1 | # victronvenussupport 2 | This is a collection of files, configuration, and other things that I've created over time playing with Venus OS. 3 | 4 | I hope it's helpful, ask any questions if you've got them! 5 | 6 | Please see https://github.com/aaronsb/victronvenussupport/blob/master/venus_rpi_enablement.md for a more comprehsive list of tasks to make Venus OS on Raspberry PI easier to use. 7 | -------------------------------------------------------------------------------- /backlightctl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | b="$(cat /sys/class/backlight/rpi_backlight/actual_brightness)" 4 | p="$(cat /sys/class/backlight/rpi_backlight/bl_power)" 5 | if [ $# != 1 ] 6 | then 7 | echo "Use integer [1-255] to control backlight intensity." 8 | echo "Use 0 to turn off backlight." 9 | echo "Backlight intensity is set to $b." 10 | if [ $p = 1 ] 11 | then 12 | echo "Backlight is not energised." 13 | else 14 | echo "Backlight is energised." 15 | fi 16 | exit 1 17 | fi 18 | 19 | if [ $1 -eq 0 ] 20 | then 21 | echo "Turning off backlight" 22 | echo 1 > /sys/class/backlight/rpi_backlight/bl_power 23 | exit 0 24 | fi 25 | 26 | if [[ $1 -ge 1 && $1 -le 255 ]] 27 | then 28 | echo "Turning on backlight" 29 | echo 0 > /sys/class/backlight/rpi_backlight/bl_power 30 | echo "Setting backlight to $1" 31 | echo $1 > /sys/class/backlight/rpi_backlight/brightness 32 | else 33 | echo "Backlight level out of range" 34 | exit 1 35 | fi 36 | -------------------------------------------------------------------------------- /mcp3208-overlay.dtb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronsb/victronvenussupport/899114ad4f272ea19fd0337c159787d0729ec4e4/mcp3208-overlay.dtb -------------------------------------------------------------------------------- /slcan.rules: -------------------------------------------------------------------------------- 1 | ACTION=="add", ENV{ID_MODEL}=="CANtact_dev", ENV{SUBSYSTEM}=="tty", RUN+="/usr/bin/logger [udev] Canable CANUSB detected - running slcan_add.sh!", RUN+="/usr/local/bin/slcan_add.sh $kernel" 2 | ACTION=="remove", ENV{ID_MODEL}=="CANtact_dev", ENV{SUBSYSTEM}=="usb", RUN+="/usr/bin/logger [udev] Canable CANUSB removed - running slcan_remove.sh!", RUN+="/usr/local/bin/slcan_remove.sh" 3 | -------------------------------------------------------------------------------- /slcan_add.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### Bind the USBCAN device 4 | slcand -o -c -s5 /dev/serial/by-id/*CANtact* can0 5 | ip link set can0 up 6 | -------------------------------------------------------------------------------- /slcan_remove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### Remove the USBCAN device 4 | killall slcand 5 | -------------------------------------------------------------------------------- /venus_rpi_enablement.md: -------------------------------------------------------------------------------- 1 | # Victron Venus On Raspberry PI 2 | Support files for managing and deploying my Victron Venus OS stuff. Started out as a gist here: https://gist.github.com/aaronsb/3a8de2bfc6081ecda268a353125bae14 3 | 4 | ## Please issue a pull request with updated urls to links and stuff if you've found they're out of date and I'll integrate them in. 5 | 6 | * ADAC and RTC are based on the Expander Pi: https://www.abelectronics.co.uk/p/50/Expander-Pi 7 | * 16 channel digital signal: MCP23017 8 | * 2 channel adac: MCP4822 9 | * 8 channel analog to digital: MCP3208 10 | * DS1307 RTC Clock chip 11 | 12 | ### Install Device Tree Binaries ### 13 | 14 | * touch screen overlay download: https://github.com/kolargol/raspberry-minimal-kernel/raw/master/bins/4.1.8/overlays/rpi-ft5406-overlay.dtb 15 | * backlight overlay download: https://github.com/PiNet/PiNet-Boot/raw/master/boot/overlays/rpi-backlight-overlay.dtb 16 | * Copy .dtb files into /u-boot/overlays/ 17 | * ds1307 rtc overlay download: https://github.com/PiNet/PiNet-Boot/raw/master/boot/overlays/ds1307-rtc-overlay.dtb 18 | * i2c-rtc overlay download: https://github.com/PiNet/PiNet-Boot/raw/master/boot/overlays/i2c-rtc-overlay.dtb 19 | 20 | 21 | ### Modify config.txt ### 22 | Add config lines to `[all]` section of `/u-boot/config.txt` (this is the config.txt variant that the venus os uses) 23 | 24 | /u-boot/config.txt 25 | ```bash 26 | #turn on SPI interface 27 | dtparam=spi=on 28 | 29 | #turn on i2c_arm bus 30 | dtparam=i2c_arm=on 31 | 32 | #turn on i2s bus 33 | dtparam=i2s=on 34 | 35 | #set framebuffer pixles wide to 480 36 | framebuffer_width=480 37 | 38 | #set framebuffer pixles high to 272. Lower resolution than native but allows scaling of the CCGX UI to full screen, and causes touch to work correctly. 39 | framebuffer_height=272 40 | 41 | #lcd was upside down on my device, setting this configures both touch and lcd to orient correctly. 42 | lcd_rotate=2 43 | 44 | #dtoverlays - MCP3208 ADAC on spi-0-0, i2c rtc interface, and ds1307 rtc interface. (that lives on the i2c bus) 45 | dtoverlay=mcp3208:spi0-0-present,i2c-rtc,ds1307-rtc 46 | ``` 47 | 48 | ### RTC Clock for DS1307 ### 49 | Install kernel module package. 50 | ```bash 51 | opkg install kernel-module-rtc-ds1307 52 | ``` 53 | Create a file called /data/rc.local add this line to it to run on startup. 54 | I think you have to chmod 755 that file. 55 | 56 | /data/rc.local 57 | ```bash 58 | echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device 59 | hwclock -s 60 | ``` 61 | 62 | This command updates the current system time to RTC. 63 | ```bash 64 | hwclock -w 65 | ``` 66 | 67 | This command just displays the RTC clock time. 68 | ```bash 69 | hwclock -r 70 | ``` 71 | This commands writes time from RTC to the system time. 72 | ```bash 73 | hwclock -s writes rtc back to system time 74 | ``` 75 | 76 | ### Add Venus configurables for backlight and display blanking ### 77 | 78 | This is a display brightness configurable 79 | ```bash 80 | echo '/sys/class/backlight/rpi_backlight' >/etc/venus/backlight_device 81 | ``` 82 | 83 | Display blanking configurable 84 | ```bash 85 | echo '/sys/class/backlight/rpi_backlight/bl_power' >/etc/venus/blank_display_device 86 | ``` 87 | 88 | 89 | ### Install modules and packages ### 90 | 91 | Update packages to latest first. 92 | ```bash 93 | opkg update 94 | ``` 95 | Install QT4 mouse driver 96 | ```bash 97 | opkg install qt4-embedded-plugin-mousedriver-tslib 98 | ``` 99 | Install tslib (touchscreen) stuff 100 | ```bash 101 | opkg install tslib-calibrate 102 | opkg install tslib-conf 103 | opkg install tslib-tests 104 | ``` 105 | Install RPI kernel module for backlight 106 | ```bash 107 | opkg install kernel-module-rpi-backlight 108 | ``` 109 | ### Create backlightctl.sh script (optional) ### 110 | 111 | This is an optional script to control backlight and dim it to a reasonable brightness when starting. You can insert it into/save this script in `/opt/rpi-screen/backlightctl.sh` 112 | 113 | After creating the file, set the script to set it executable, then symlink script. 114 | 115 | /opt/rpi-screen/[backlightctl.sh](https://github.com/aaronsb/victronvenussupport/blob/master/backlightctl.sh) 116 | ```bash 117 | chmod 755 /opt/rpi-screen/backlightctl.sh 118 | ln -s /usr/sbin/ /opt/rpi-screen/backlightctl.sh 119 | ``` 120 | 121 | ```bash 122 | #!/bin/bash 123 | 124 | b="$(cat /sys/class/backlight/rpi_backlight/actual_brightness)" 125 | p="$(cat /sys/class/backlight/rpi_backlight/bl_power)" 126 | if [ $# != 1 ] 127 | then 128 | echo "Use integer [1-255] to control backlight intensity." 129 | echo "Use 0 to turn off backlight." 130 | echo "Backlight intensity is set to $b." 131 | if [ $p = 1 ] 132 | then 133 | echo "Backlight is not energised." 134 | else 135 | echo "Backlight is energised." 136 | fi 137 | exit 1 138 | fi 139 | 140 | if [ $1 -eq 0 ] 141 | then 142 | echo "Turning off backlight" 143 | echo 1 > /sys/class/backlight/rpi_backlight/bl_power 144 | exit 0 145 | fi 146 | 147 | if [[ $1 -ge 1 && $1 -le 255 ]] 148 | then 149 | echo "Turning on backlight" 150 | echo 0 > /sys/class/backlight/rpi_backlight/bl_power 151 | echo "Setting backlight to $1" 152 | echo $1 > /sys/class/backlight/rpi_backlight/brightness 153 | else 154 | echo "Backlight level out of range" 155 | exit 1 156 | fi 157 | ``` 158 | 159 | ### Calibrate touchscreen ### 160 | Set these variables temporarily to write the calibration file to the correct location. 161 | ```bash 162 | TSLIB_FBDEVICE=/dev/fb0 163 | TSLIB_TSDEVICE=/dev/input/touchscreen0 164 | TSLIB_CALIBFILE=/etc/pointercal 165 | TSLIB_CONFFILE=/etc/ts.conf 166 | TSLIB_PLUGINDIR=/usr/lib/ts 167 | ``` 168 | Run tslib calibration and touchy the screen in the right spots. 169 | 170 | ```bash 171 | ts_calibrate 172 | ``` 173 | 174 | ### Victron /opt/victronenergy/gui/start-gui.sh modification ### 175 | Add the following lines right after the `"when headfull "` comment block. 176 | Note that these require you to have first calibrated the screen, saving the various calibration files. backlightctl.sh is listed just above. If you didn't want to use it, omit that from your modification. 177 | 178 | /opt/victronenergy/gui/start-gui.sh 179 | ```bash 180 | export TSLIB_TSEVENTTYPE=INPUT 181 | export TSLIB_CONSOLEDEVICE=none 182 | export TSLIB_FBDEVICE=/dev/fb0 183 | export TSLIB_TSDEVICE=/dev/input/touchscreen0 184 | export TSLIB_CALIBFILE=/etc/pointercal 185 | export TSLIB_CONFFILE=/etc/ts.conf 186 | export TSLIB_PLUGINDIR=/usr/lib/ts 187 | export QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0 188 | echo "*** Setting backlight intensity to 50 ***" 189 | backlightctl.sh 50 190 | ``` 191 | 192 | ### USB GPS Device ### 193 | 194 | After a reboot, usb gps device seemed to just magically work. "that was easy" 195 | ```bash 196 | opkg install gps-dbus 197 | ``` 198 | 199 | 200 | ### canable.io canbus interface setup ### 201 | This requires slcand daemon to be installed. 202 | I bought this device from http://canable.io/, and it shows up as a "CANtact" device 203 | 204 | Create start and stop scripts for slcand. You'll need an add and remove script. 205 | 206 | /usr/local/bin/[slcan_add.sh](https://github.com/aaronsb/victronvenussupport/blob/master/slcan_add.sh) 207 | ```bash 208 | #!/bin/sh 209 | 210 | ### Bind the USBCAN device 211 | slcand -o -c -s5 /dev/serial/by-id/*CANtact* can0 212 | ip link set can0 up 213 | ``` 214 | /usr/local/bin/[slcan_remove.sh](https://github.com/aaronsb/victronvenussupport/blob/master/slcan_remove.sh) 215 | ```bash 216 | #!/bin/sh 217 | 218 | ### Remove the USBCAN device 219 | killall slcand 220 | ``` 221 | 222 | Make sure you chmod 755 (executable) both scripts. 223 | 224 | Add scripts to rules.d so it works for starting and stopping properly. 225 | 226 | Create file `/etc/udev/rules.d/slcan.rules`, which adds start and stop rules. Note that the device is called "CANtact_dev" - if you have a different device it might show up as a differently named device. 227 | 228 | /etc/udev/rules.d/[slcan.rules](https://github.com/aaronsb/victronvenussupport/blob/master/slcan.rules) 229 | ```bash 230 | ACTION=="add", ENV{ID_MODEL}=="CANtact_dev", ENV{SUBSYSTEM}=="tty", RUN+="/usr/bin/logger [udev] Canable CANUSB detected - running slcan_add.sh!", RUN+="/usr/local/bin/slcan_add.sh $kernel" 231 | ACTION=="remove", ENV{ID_MODEL}=="CANtact_dev", ENV{SUBSYSTEM}=="usb", RUN+="/usr/bin/logger [udev] Canable CANUSB removed - running slcan_remove.sh!", RUN+="/usr/local/bin/slcan_remove.sh" 232 | ``` 233 | 234 | 235 | 236 | ###Link the startup scripts for CANbus functionality. 237 | 238 | See https://groups.google.com/d/msg/victron-dev-venus/fnlzZlWCx58/uicAXiwwAwAJ that post for more details on how this came to be. 239 | 240 | ```bash 241 | ln -s /opt/victronenergy/can-bus-bms/service /service/can-bus-bms.can0 242 | ln -s /opt/victronenergy/dbus-motordrive/service /service/dbus-motordrive.can0 243 | ln -s /opt/victronenergy/dbus-valence/service /service/dbus-valence.can0 244 | ln -s /opt/victronenergy/vecan-dbus/service /service/vecan-dbus.can0 245 | ln -s /opt/victronenergy/mqtt-n2k/service /service/mqtt-n2k.can0 246 | ``` 247 | 248 | For my purposes, I needed to set the CANbus device to a speed of 250k for my BMS to talk to it properly 249 | 250 | ### Configure headless mode to disabled (enables the GUI on screen) ### 251 | You need to reboot for this setting to take effect. 252 | ```bash 253 | mv /etc/venus/headless /etc/venus/headless.off 254 | sudo reboot now 255 | ``` 256 | 257 | 258 | ### Expander Pi ADAC Board ### 259 | I got the Epander PI from here https://www.abelectronics.co.uk/p/50/Expander-Pi 260 | 261 | The trick to making this work since it's an SPI device that needs to identify as an PCM 3208, the DTB had to be modified to properly discover it. Just copy the DTB file over from here https://github.com/aaronsb/victronvenussupport/blob/master/mcp3208-overlay.dtb and save into /u-boot/overlays on the RPI. 262 | 263 | Here's an excerpt from post: (https://groups.google.com/d/msg/victron-dev-venus/mejgJbMjU34/WglmnUPQAwAJ) 264 | 265 | >I had to convert the mcp3008-overlay.dtb to a dts file, change all references to 3008 to 3208, and convert it back to a dtb file, to get it to give me 12-bits (4095). 266 | >(I've enclosed the dtb file if anyone needs it). The line in config.txt should read "dtoverlay=mcp3208:spi0-0-present" 267 | 268 | After adding that file to `/u-boot/config.txt`, install the kernel driver and set the following items executable, and link the service to the right dbus node. 269 | 270 | ```bash 271 | opkg install kernel-module-mcp320x 272 | chmod 755 /opt/victronenergy/dbus-adc/start-adc.sh 273 | chmod 755 /opt/victronenergy/dbus-adc/dbus-adc 274 | chmod 755 /opt/victronenergy/dbus-adc/service/run 275 | chmod 755 /opt/victronenergy/dbus-adc/log/run 276 | touch /var/log/dbus-adc 277 | ln -s /opt/victronenergy/dbus-adc/service /service/dbus-adc 278 | ``` 279 | 280 | ### GPIO Pins for Opto protected relay coltrol ### 281 | 282 | The original post is located here https://groups.google.com/d/msg/victron-dev-venus/nqkpANtRCBU/IeDx5lbfAAAJ I've included it for sake of completion. 283 | 284 | 285 | 1. First off, pick a suitable GPIO. It seems to me the obvious choices would be something that is not multiplexed onto another function (some pins do double duty and can be configured to be something else), so the obvious choice to me seems to be GPIO21, which is on pin 40 on the header (right at the end). What's nice about this one, is it has a ground right next to it on pin 39. 286 | 287 | 2. Next you have configure this pin as a gpio. There is some functionality built into venus to do this, but not yet enabled on the Pi, so you will have to manually install this. First create /etc/venus/gpio_list by using the following command: 288 | ```bash 289 | echo "21 out relay_1" > /etc/venus/gpio_list 290 | ``` 291 | 292 | 3. Install the setup script and make it executable, like so: 293 | ```bash 294 | wget -O /etc/init.d/gpio_pins.sh https://raw.githubusercontent.com/victronenergy/meta-victronenergy/master/meta-venus/recipes-bsp/gpio-export/files/gpio_pins.sh 295 | chmod +x /etc/init.d/gpio_pins.sh 296 | ``` 297 | 298 | 4. Create a symlink to make gpio setup run at boot: 299 | ```bash 300 | cd /etc/rcS.d 301 | ln -s ../init.d/gpio_pins.sh /etc/rcS.d/S90gpio_pins.sh 302 | ``` 303 | 304 | 5. Either reboot, or just run the script manually to set up the gpios at this time (you will reboot again later): 305 | ```bash 306 | /etc/init.d/gpio_pins.sh 307 | ``` 308 | 309 | 6. You should now have a file /dev/gpio/relay_1 configured as an output. 310 | 311 | 7. Create /etc/venus/relays and add the relevant gpio 312 | ```bash 313 | echo /sys/class/gpio/gpio21 > /etc/venus/relays 314 | ``` 315 | 316 | 8. Reboot. The relay should now show up in the list. 317 | --------------------------------------------------------------------------------