• @calebbrewer,

    you may have noticed the other Espruino forum conversation about MPL3115A2 Troubleshooting?

    It talks about pull-up resistors among other things. If they are missing, I2C communication fails usually completely, but some capacities on the lines and too weak / strong pull-ups may still yield some results but not reliable ones and can mess with some bits... May be pull-up resistors - or their absence - could be the culprit(s).

    Some other things that bothered me when glancing again over the source code of the https://espruino.com/modules/MPL3115A2.j­s module:

    1. The brief source code inline documentation about usage implies the module request to return a constructor, where as setting/updating the export object shows definitively just addition of the .connect() method. And your code confirms that the latter is correct.

    2. The .connect() does actually (write) something to the sensor AND even to the connector object (initialize busy=false; that controls communication w/ the sensor)... Therefore, the .connect() has also to be in the onInit(){ ... } function when you plan to save() your code and expect it to work on power cycling. For that reason I never directly connect to the requested module ('outside' - location-wise or 'before' time-wise / execution-wise) onInit(){ ... }:

      var i2c = new I2C();
      I2C1.setup({scl: D20, sda: D22});
      i2c.setup({sda:D30,scl:D29});
      var mpl, mplMode = require("MPL3115A2");
      var lcd, lcdMod = require("HD44780");
      
      const onInit = ()=> {
      
      lcd = lcdMod.connectI2C(I2C1, 0x3F);
      
      lcd.setCursor(0, 0);
      lcd.print("Starting...");
      
      mpl = mplMod.connect(i2c);
      setInterval(() => {
      mpl.getPressure(function(x) {
        console.log("Pressure "+x+" pa");
        mpl.getAltitude(function(x) {
          console.log("Altitude "+x+" m");
            mpl.getTemperature(function(x) {
            console.log("Temperature "+x+" C");
          });
        });
      });
      
      }, 5000);
      };
      
      setTimeout(onInit, 3000);
      

    In above code example I applied the same pattern also for the lcd instance / lcd module, even though it could work the other way as well... I try to have fewer patterns of doing things in place to include robustness against changes or differences.

    I do though not believe that any of my code changes fix the issue you face. That a single read was close to what other driving boards read makes me think of the pull-up resistors and may be the wiring... I'm sure you grounded all things well together (have not just ground via power supply but also for signal board to board)... since it is not the first time you do electronics... but I having been fooled by a missing wire or a breadboard contact not doing right would not be the first time...

About

Avatar for allObjects @allObjects started