“This is an update to my earlier Power Deliverer project to add a current monitor that gives a continuous display of the current consumption.
The Power Deliverer allows you to use a USB-C power adapter as a power supply with a range of fixed voltages. It displays a list of the voltages and currents available from the adapter and allows you to select one. Once you’ve selected a voltage option, it monitors the current consumption and shows it on the display.
It’s based on an STUSB4500 integrated circuit, an ATtiny1604 microcontroller, and an INA181A2 current monitor, and it displays the information on a 128x32 OLED display.
In my original Power Deliverer project I suggested a possible extension which would add a current sensor, to allow you to show an active display of the current being drawn by the load. I suggested using either an I2C sensor such as the INA219, or an analogue sensor such as the INA199 which you could read with an analogue input on the ATtiny1604.
I decided to go ahead and do this, and chose the Texas Instruments INA181 current sensor  because it’s relatively cheap and, more importantly, I was able to find it in stock. The additional components fit on a PCB of the same size as the original one.
The current monitor works by measuring the small voltage drop across a current-sensing resistor, between the positive voltage output and the load, so it’s referred to as a “high-side” current monitor. Because the positive rail might be up to 20V it’s too high to read directly with an analogue input on the microcontroller, so you would need two matched high-precision voltage dividers. A simpler solution is to use an analogue sensor such as the INA181A2.
The maximum current the Power Deliverer might carry is 5A. A 0.1Ω sense resistor would drop 0.5V, which is a significant voltage drop, and at that current it will dissipate 2.5W, which means it will run pretty hot. A better choice is a 0.01Ω sense resistor which will only drop 0.05V and dissipate 0.25W.
The INA181A2 I chose has a gain of 50V/V. This allows us to use a voltage reference of VCC, or 3.3V, to get a full scale reading of 1024 with 6.6A current.”