Skip to content
Vince edited this page Jun 1, 2023 · 4 revisions

Shunt - Battery Monitor

Short: A shunt is a device that creates a low-resistance path for electric current. We are measuring the voltage drop of the current and then recalculate the current. Measured over time we can track the state of charge from the battery.

Hardware

We are using an ADS1115 to measure the voltage drop and the battery voltage. The ADS1115 is 16bit ADC with an adjustable gain. The chip is connected via I2C-bus on address 0x4a. We are using two of them, the second one on address 0x48 is used for the waterlevel sensors.

Our shunt PCB is OpenSource, you can find it below. A 4pin Rj11 connection transfers the voltage from the shunt to the board.

The current is measured in differential mode (gain16 +/-0.256V) between channel 0-1.
The voltage is measured in differential mode (gain2 +/-2.048V) between channel 2-3.

Channels 0 and 1 are directly connected to the shunt main connection points. Channels 2 and 3 are connected to a voltage divider of 50k/4,7k. This voltagedivider scales the 12v input to a measurable voltage value.

Schematic Download PDF

Software

To read the values a Python3 script and Bottle web server are served to transfer the data into Node-RED. Main reason for this is that we can use all cpu cores with it, while Node-RED itself uses only one core for now, as NodeJS is a single-core application. The measuring is time critical, so we had to care about the cpu usage. Of course you can call this data from other software too, the webserver uses port 8080. Check the "Pekaway Shunt + WaterLevel Python" flow in the Node-RED backend for further details. The script itself is located at ~/pekaway/ads_py/web1.py (with interpreter python3)

GET requests on localhost:8080

/shunt
-> gives {watthours, factorI, amps, volts, MaxWatthours}

/setWH/<value>
-> set SOC in watthours of the battery

/levels
-> gives level1 -> level4 ADC values

/check
-> gives a random number to proof is the ads thread running

/setMaxWH/<value>
-> set the battery capacity in watthours

/setI/<value>
-> set the shunt factor value 100a/75mv 200a/75mv 300a/75mv

Database

Every 2 minutes the battery SOC is stored in a sqlite3 database (~/home/pi/pythonsqlite.db). These values hold the state of the battery and are loaded from the database after a reboot.

Clone this wiki locally