Bangle.js 2 - Barometer always 0 [Solved]

Posted on
  • Hi,

    I'm fiddling with the barometer on Bangle.js 2.
    On the releases 2v12, I had the issue that the first sample was always undefined (but fine after that). On 2v12.70, everything seemed to be ok, also the first sample. Then, for no good reason, I updated to 2v12.89, and now all calls to the barometer return 0 (also for temperature and altitude).

    I can't figure out which git commit Id corresponds to 2v12.70, so I can't go back to verify that everything works there still. But in the IDE, I can confirm that the barometer is on, and that this is reproducible.

    Greetings
    Indriði

  • I can't reproduce that. For example following code gives correct results for me with Bangle.js 2 and 2v12.89

    setInterval(() => {
      Bangle.getPressure().then(d => {
        console.log(d);
      });
    }, 10 * 1000);
    
  • Hi,
    I deleted all of my own code, to be sure errors in there weren't interfering. On 2v12.89, the code above results in this:

    >setInterval(() => {
    :  Bangle.getPressure().then(d => {
    :    console.log(d);
    :  });
    :}, 10 * 1000);
    =3
    { "temperature": 0, "pressure": 0, "altitude": 0 }
    { "temperature": 0, "pressure": 0, "altitude": 0 }
    { "temperature": 0, "pressure": 0, "altitude": 0 }
    { "temperature": 0, "pressure": 0, "altitude": 0 }
    { "temperature": 0, "pressure": 0, "altitude": 0 }
    

    Could the sensor have gotten damaged? Just 2 days ago, the barometer was working, and matching wonderfully with the local met office readings.
    Greetings,
    Indriði

  • I tried a firmware reset, to rule out that something I have installed was causing this. No change.

    Then I tried completely draining the battery (I understand that at least some of the components on the board always have electricity, unless the battery is dead). Leaving the GPS on for a night makes sure everything is thoroughly dead. After charging, barometer works again!

    Possibly related to this: I was working on some code that powers up the barometer, makes a reading and powers it down again every X minutes. Some logic that re-tries if the barometer returns 0 or undefined was botched, resulting in cascaded endless loops of power-on, read, power-off of the barometer. That might have put the barometer chip in a funny state.

    Indriði

  • Glad you got it sorted! It's a surprise you could completely confuse it though.

    Just so you know, Bangle.getPressure will automatically power the sensor on, read, and power it off - so you may not have to mess with power cycling yourself

  • Thank you!
    I had the exact same problem draining the battery helped!
    I did not think of trying the power-off function (i only restarted multiple times to no avail).

    My cause may be similar, although i did not try power-cycling it myself.
    Instead i tried to copy the workaround from the barometer app and apparently failed.
    My pressure handler is currently

    function handlePressure(p) {
      if (p===undefined) {
        setTimeout(() => Bangle.getPressure().then(handlePressure­), 500);
        return;
      }
      [do handling here]
    }
    

    and i call it every minute by

    Bangle.getPressure().then(handlePressure­);
    

    which seems to confuse the sensor.

  • It happened again and now i am relatively certain it is not only my code, unless i understood something fundamentally wrong.
    I changed my handler to

    function handlePressure(p) {
          if (p===undefined) {
            return;
          }
          [do handling here]
    }
    

    and it still happened.

    My best guess is, that it is a problem that my clock-face and the recorder access the pressure at the same time, but i currently do not know how to verify or circumvent this except never displaying the pressure or temperature while the recorder records it.

    Furthermore keeping the clock powered off for a while does not help, is there any other way to reset the sensors except draining the battery (which i am afraid will damage the battery)?

  • Does this happen all the time, or is it just occasional calls that give you bad readings?

    You could try calling Bangle.isBarometerOn() before you run your code, to see if some other app/widget is keeping the barometer on and causing issues?

    What firmware version do you have? I did make some improvements to setBarometerPower in a recent build, so if you try one of the 2v14.xxx cutting edge builds this may work better for you?

    is there any other way to reset the sensors except draining the battery (which i am afraid will damage the battery)?

    I'm afraid not - the sensors should be reset via software normally, but if the hardware has got 'locked up' then draining battery is the only way. I wouldn't worry about damage to the battery though - if only done a few times it's unlikely to be an issue - I let watches run flat here all the time and never have problems.

    However it's extremely rate hardware gets locked up - if something like this happens routinely then it's unlikely to be a 'hardware lockup' that is the issue

  • Does this happen all the time, or is it just occasional calls that give you bad readings?

    When it happened every reading before a reboot returned the last valid values, every reading after a reboot returned a 0 for temperature and pressure. Every single reading until the battery was flat.

    What firmware version do you have? I did make some improvements to setBarometerPower in a recent build, so if you try one of the 2v14.xxx cutting edge builds this may work better for you?

    I use 2.14. I was not aware of 2.14.149 and will try it out.

    You could try calling Bangle.isBarometerOn() before you run your code, to see if some other app/widget is keeping the barometer on and causing issues?

    I know that Recorder accesses the Barometer in the background.
    I tried turning the Recorder off and printing the result of Bangle.isBarometerOn() in my App regularly and the result confuses me.
    When i call Bangle.getPressure and get a result that is not "undefined" the sensor shuts down after performing the handler.
    If however the reading is "undefined" the sensor stays on until i stop the application, regardless of future calls with valid readings.
    This holds for 2.14 and 2.14.149.
    I do not know if this is correlated to having only readings of 0, but seems wrong either way.

    However it's extremely rate hardware gets locked up - if something like this happens routinely then it's unlikely to be a 'hardware lockup' that is the issue

    I cannot think of another explanaition since rebooting and powering off for a few minutes did not help and Indridi found that a firmware reset did not help either.
    Only draining the battery seems to help.

  • In two days on 2.14.149 i had no problems with wrong readings, so that may have solved it

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Bangle.js 2 - Barometer always 0 [Solved]

Posted by Avatar for Indridi @Indridi

Actions