DESK-XZ7-L/Peripherals/Power meter

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2024/01/31 DESK-XZ7-L-1.0.1 release



Peripheral Power meter[edit | edit source]

BORA, BORA Xpress and BORA Lite EVBs has a INA226 device connected to the I2C bus. The following commands can be saved as a shell script (e.g. read_power_values.sh) and run to collect the measurements data:

root@bora:~# cat read_power_values.sh
#!/bin/sh

path_dev=/sys/bus/iio/devices/iio\:device0/

IN_VOLT0_RAW=$(cat "$path_dev/in_voltage0_raw")
IN_VOLT0_SCALE=$(cat "$path_dev/in_voltage0_scale")
IN_VOLT1_RAW=$(cat "$path_dev/in_voltage1_raw")
IN_VOLT1_SCALE=$(cat "$path_dev/in_voltage1_scale")
IN_VOLT0=$(echo "$IN_VOLT0_RAW*$IN_VOLT0_SCALE" | bc)
IN_VOLT1=$(echo "$IN_VOLT1_RAW*$IN_VOLT1_SCALE" | bc)
VOLTAGE=`awk "BEGIN {print ($IN_VOLT1-$IN_VOLT0)/1000}"`

IN_CURRENT3_RAW=`cat $path_dev/in_current3_raw`
IN_CURRENT3_SCALE=`cat $path_dev/in_current3_scale`
CURRENT=`awk "BEGIN {print ($IN_CURRENT3_RAW*$IN_CURRENT3_SCALE)/1000}"`

IN_POWER2_RAW=`cat $path_dev/in_power2_raw`
IN_POWER2_SCALE=`cat $path_dev/in_power2_scale`
POWER=`awk "BEGIN {print ($IN_POWER2_RAW*$IN_POWER2_SCALE)/1000}"`

echo "Voltage: ${VOLTAGE}, Current: ${CURRENT}, Power: ${POWER}"
root@bora:~# ./read_power_values.sh
Voltage: 3.30573, Current: 0.72375, Power: 2.3875
root@bora:~#