You are reading a single comment by @fanoush and its replies. Click here to read the full conversation.
  • after reading http://forum.espruino.com/conversations/350764/ , i did some digging and have some questions.

    The pin used for voltage reading is pin 30. I used :

    console.log(analogRead(30))
    

    after it being fully charged and got the value : 0.63110351562

    /// get battery percentage
    JsVarInt jswrap_banglejs_getBattery() {
      JsVarFloat v = jshPinAnalog(BAT_PIN_VOLTAGE);
      const JsVarFloat vlo = 0.51;
      const JsVarFloat vhi = 0.62;
      int pc = (v-vlo)*100/(vhi-vlo);
      if (pc>100) pc=100;
      if (pc<0) pc=0;
      return pc;
    }
    

    from jswrap_bangle.c. Notice the upper and lower limits hard coded into the formula.
    Was this code aimed for a more weared down battery? average use case?
    I'm thinking to use analogRead instead of E.getBattery. Is this a good idea?

    Edit: I also discovered E.getAnalogVRef() which outputted a number close to 3.3 v
    So ... 0.51 * 3.3V = 1.683V
    and 0.62 * 3.3V = 2.046V

    Why are the battery volt limits for 0-100 between these 2 numbers?

  • Why are the battery volt limits for 0-100 between these 2 numbers?

    Because analog input can take only up to 3.3v and battery is up to 4.2V so there must be some resistor divider to reduce voltage below 3.3V. Resistors were chosen 'randomly' by manufacturer for this design so no reason to multiply by 3.3. Across some fitness trackers I've seen the value varied a lot for each manufacturer/device model.

    Was this code aimed for a more weared down battery?

    individual resistor tolerancies can be even few % see e.g. https://www.electronics-tutorials.ws/resistor/res_2.html , can make some difference in the voltage divider for each device

About

Avatar for fanoush @fanoush started