I like LiFePO4 batteries. They have a rather flat discharge at around 3.2V, which is ideal for powering 3.3V devices without a regulator. You can also use them in devices that take 2 standard AA cells by using a blank shunt in the 2nd battery slot since 2 fresh alkaline cells in series provide 3.2-3.3V. And since they are readily available in the 14x50mm AA size, you can use cheap AA holders for them in electronics projects.
When it comes to chargers, things can be a bit problematic. LiFePO4 batteries should be charged to 3.6V, rather than 4.2V like regular lithium-ion batteries. A good charger costs $10-$15, but charging at a high current will reduce the number of recharge cycles. The Soshine batteries I bought indicate on the label a standard charging current of 300mA to 3.6V. Rather than search for a charger to fit the bill, I decided to make one.
From my experiments with TL431 regulators, I remembered the regulator circuit above. My idea was to take a 5V USB supply, and regulate it to 3.6V for charging the LiFePO4 cells. For the NPN transistor, I wanted to use something more powerful than the usual 2N3904 which has a collector current rating of 200mA. I found some old PN2222a transistors which are rated for 600mA, more than enough for the 300mA I needed. Another thing to keep in mind when choosing a transistor is power dissipation. TO92 packages are good for about 500mW before they get hot enough to burn flesh. With the voltage drop across the transistor around 1.45V (5.05V - 3.6V), up to 350mA should be fine with a TO92 transistor.
Having chosen the transistor, I needed to figure out R1 and R2 such that I would get the desired 3.6V at Vout. With Vref = 2.5, R1/R2 = 0.44, I needed to find 2 resistors close to that ratio. After sorting through my resistor collection, I found some 1.2K and 2.7K resistors, which gives a ratio of 0.444. The capacitor between the reference and cathode of the tl431 can be omitted, so the only other component I needed to figure out was unlabeled resistor between the transistor collector and base. The amount of base current required will depend on the gain of the transistor. With 300mA of collector current the gain could be anywhere from 15 to 50. I had some 68Ohm resistors handy which I decided to try. Vbe of the transistor is around 0.7V, so with V+ at 5.05 and Vout at 3.6, using a 68Ohm resistor would give me a base current of 11mA. I tested it with a partially discharged battery, and measured 290-300mA! Things weren't quite perfect though, as after 10 minutes the voltage passed 3.6, and kept rising toward 4V. I disconnected the power, and after some debugging I realized I had R1 and R2 mixed up. I discovered this by measuring the reference voltage, and finding it was around 1.3V when Vout was 4.2. After swapping the resistors, with no battery connected I was getting 3.61 for Vout and 2.5V on the reference - just what I wanted.
One other word of warning - be careful using the cheap little 170-hole breadboards for projects with more than 20-30mA of power. I had started with one of them until I remembered the problematic high-resistance contacts on them.
Before getting out the soldering iron and making the circuit permanent, I wanted a way to tell when charging was complete. After toying with a couple ideas, my final solution is a 2V green LED in series with the TL431 cathode. When Vout reaches 3.6, the tl431 shunts almost all of the base current (a small base current is still required due to the ~1mA of leakage through R1 + R2). When I tested it out, I found an unexpected benefit of the LED glowing dimly as charging starts, and then turning bright when charging completes. This can be explained by looking at the cathode current graph from the datasheet:
With a fully-discharged battery, Vout will start at around 3V, and Vref will be about 2.1V. The cathode current will be about 250uA, and since the LED is in series with the cathode, that will be the LED current as well. This is enough to make a dim but visible glow. When Vout reaches 3.6V, the tl431 will shunt most of the 11mA from the transistor base, making the LED glow brightly.
The last thing I tried while I had everything in the breadboard was substituting at 2N3904 for the PN2222a. Suprisingly, I was able to get 200mA of charging current. So if all you have are 3904s, you can still get a reasonable amount of current. You could probably even use 2 3904s in parallel for close to 400mA of current.
For the permanent version of the circuit I used a small 7x4 piece of stripboard. By planning out the layout on paper first, I was able to use 7 strips without any breaks. I got a little too rushed doing the assembly and put the tl431 in the wrong way around (cathode and reference swapped). After fixing it, I tested for continuity on all my solder connections. One needed to be re-worked, and with a bit of flux, a dab more solder, everything was good. After some hot glue to attach the battery holder, I plugged it into a USB power port, and it worked perfectly.
Here's my final BOM:
AA battery holder: 15c
1/12th of a stripboard: 6c
USB male connector: 22c ( or 10c from other sources)
Old pn2222a: 5c (replacement cost; paid $3 for a package of 15 at RadioShack almost 30 yrs ago)
3mm green led: 1c
Satisfaction of building your own battery charger: priceless :-)