Translate

Saturday, 25 March 2017

Arduino LiPo charger / monitor.

I've been using 18650 LiPo cells for a while in a few gadgets.

I'd purchased a small charger module from eBay, and assembled a single cell charger.




It worked well, but it just wasn't geeky enough ... I'd like a bargraph, voltage and percentage on a nice colour screen, and the ability to charge 4 cells...




so, I bought some more charger modules from eBay....













... a high current (5A) adjustable buck converter ...











...  a super cheap 2.2" ILI9340C display ...










... and a 4 cell battery holder ...












... some tea was drunk, and a plan hatched.

Each charger module will be connected to the high-current 5V supply, and operate independently of the arduino. The battery voltage will be measured by the arduino, and will be used to produce the data for the display. When the charge complete LED on the charge module illuminates, the arduino will indicate this on the display.

Some code was created and a prototype lashed up...

First problem was the display. The ILI9340C is designed to operate on 3.3V. Mine was fitted with a 3.3V regulator. "Great" ... except the data lines need to be converted to 3.3V ...

I fabricated a small resistive divider board, and fitted it. Each line from the micro feeds a 4.7K resistor in series with a 9.1K resistor to ground. The display connects to the junction between the resistors. The 5v supply I left supplying the display, and the LED backlight was connected to 5V via 180 ohms... bingo!

Next was to modify the charger module, so we can see when then charging LED is lit. Now I looked at (what I thought was) the datasheet for the IC, and carefully soldered a wire to pin 8 of the IC, being CHRG (active low) ... great ... nope. It didn't work. It stayed happily at 5V, regardless of the state of the battery. Thankfully, after some googling, I found the correct datasheet, and reverse engineered the charger module...


I set up the buck converter to output 5.0V , and mounted it, the arduino and the charger modules on a piece of perfboard. Before connecting the charger modules, I calibrated each analogue input on the arduino to give an accurate voltage reading at 4.2 and 2.8 volts.

Connecting in the chargers, and putting a battery in gave me good results .... nice bar graph reading, pretty looking display, BUT putting another battery on charge revealed an issue.... the voltage reading was getting less accurate the more cells were on charge .... the meter actually over-reading the voltage. I messed about for a while with the code, seeing if there was a reading error (there always is a "settling time" with the arduino's analogRead function) .. but the fault wasn't there..

Measuring the output of the buck converter exposed the problem. Under load, the regulation was letting me down, the voltage falling to 4.76V. Now that doesn't effect the charger circuit, as it's designed to operate down to 4.5V... BUT it does effect the arduino's ability to make accurate measurements.. It's down to how the arduino's reference voltage is derived. The arduino's A to D uses a reference voltage, connected to the AREF pin (pin 21 on a ATMEGA328P). In arduino, this is coupled straight to the 5V supply... if the supply is moving about, so will the values from the A to D converter. Not good. Now we could put a voltage reference IC here, but I'm using a pro-mini, and modifying that tiny PCB is not an option.

A note on voltage calibration. When you first run the software, you may (probably will) need to alter the voltageCal value in the software to give accurate readings. Easiest way to do this is read the voltage at the battery compartment terminals of one unit with a meter, and compare it with the reading on the display. If the two don't marry up (it should be around 4.06V), then take the actual reading on your meter and divide it by the reading on the display. Now multiply that value by the current voltageCal and use this figure to be the new value for voltageCal. If the display is reading low, your multiplier will be greater than 1. If it's high, it will be less than 1.

Improve the power supply's regulation? OK, an option, but we're dealing with quite a high current output here , so perhaps that's not a good idea either...

Option 3, provide the Arduino with a separate regulated 5V supply. The load isn't much, and doesn't vary much either... Ideal. So, a simple 7805 and a handful of decoupling ? ... Almost ...


This is a picture of the reverse side of the power supply... the ground pin is at the bottom. See that resistor? It's 0.05 ohms. It's in series with our ground output. It's so the unit can calculate how much current is being drawn, and limit the current if required (there's a current limit pot on the top of the unit).

Whilst the module is not isolating (the output is still referenced to the input), the ground at the output of the module is not quite the same voltage as the ground at the input, and the situation gets worse as the current being drawn increases. So we need to feed our 7805 with the "raw" supply coming in, but ensure our ground (or more technically, reference pin) of our 7805 is connected to the ground on the output side of the module. Sorted.

It doesn't look nice.. it's a bit of a rat's nest..


.. except the display, which I'm rather pleased with ....










So here's the schematic...



... and the code...


... and a picture of the completed unit in use :)



One word of warning... put the batteries in the right way round. Reverse polarity will destroy the charger modules, and possibly the A to D on the ATMEGA328 too :( .. don't ask me how I know...
I've now added 4 x 1A fast acting fuses in line with each battery.