#!/bin/sh # Kookabus-01 through the kernel's ina2xx hwmon driver: no user-space I2C code. # Run as root once per boot (or put the first two steps in rc.local / a systemd unit): # sudo ./kookabus-hwmon.sh [i2c bus number] [address] # Afterwards any user can read the values; `sensors` (lm-sensors) shows them too. BUS=${1:-1} ADDR=${2:-0x40} DEV=/sys/bus/i2c/devices/$BUS-$(printf %04x "$ADDR") [ -d "$DEV" ] || echo ina226 "$ADDR" > /sys/bus/i2c/devices/i2c-"$BUS"/new_device HW=$(echo "$DEV"/hwmon/hwmon*) echo 5000 > "$HW"/shunt_resistor # micro-ohm while :; do # in1 = bus voltage (mV), curr1 = mA, power1 = uW awk -v v="$(cat "$HW"/in1_input)" -v i="$(cat "$HW"/curr1_input)" -v p="$(cat "$HW"/power1_input)" \ 'BEGIN { printf "%6.2f V %6.3f A %6.1f W\n", v/1000, i/1000, p/1e6 }' sleep 1 done