You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I'm not sure I understand you - If you're putting a higher voltage on the input to the battery then it'll charge, even without a diode. If you're leaving the charger plugged in when the charger's power is off, you may have to think about how to make it work though.

    Assuming you're charging a single cell battery, you could use two PFETs to charge the battery up:

    • One between 5v and the battery, via a resistor - this will be the 'constant current' (ish) source for charging the battery
    • One from 4.1v (maintained via a voltage regulator) - which will be the 'constant voltage' source

    You'd need to put high value resistors between the source and gate, but then as long as you use 5v tolerant pins on Espruino you can turn the PFETs on and off from Espruino. digitalWrite(pin,0) will turn them hard on, and digitalRead(pin) will make the pin open circuit, which will turn the FET off.

    Charging more than a single cell is harder, because then the voltage on the PFET's gate needs to be above 5v, and so it can't be connected straight to the Espruino. You'd then have to use a normal n channel FET to get the voltage swing you need for the PFET.

    ... but if you're using multiple cells then you also ought to think about cell balancing, as you don't want to overcharge one cell while undercharging another... and then it gets a lot more interesting!

About

Avatar for Gordon @Gordon started