You are reading a single comment by @user54499 and its replies. Click here to read the full conversation.
  • Ahhh i see, so for others reading this here is where i went wrong.

    I2C1 needs to be called within scope of what your communicating with, im guessing its a state machine, so when you call ".connect(I2C1)" you taking control away from other modules that are using. When i see "require" i automatically think they need to be grouped at the top all pretty, but they dont.

    I was trying to do:

    var g = require("SSD1306").connect(I2C1);
    var bmp = require("BMP085").connect(I2C1);
    //... more code here
    
    bmp.getPressure(function(d) {
        //console.log("Pressure: " + d.pressure + " Pa");
        console.log("Temperature: " + d.temperature + " C");
    	g.clear();
       g.drawString("Temperature: " + d.temperature + " C",2,2);
       // write to the screen
       g.flip(); 
    
      });
    
    

    this doesnt work!

    what i needed was

    I2C1.setup({scl:B6,sda:B7});
    
    var text ="";
    
    function getTemp()
    {
      var bmp = require("BMP085").connect(I2C1);
      if (!bmp)
      {
        console.log("bmp failed to init");
        return null;
      }
      bmp.getPressure(function(d) {
        text = "Temperature: " + d.temperature + " C";
      });
      
    }
    
    function showTemp()
    {
      var g = require("SSD1306").connect(I2C1);
        if (!g)
      {
        console.log("g failed to init");
        return null;
      }
      g.clear();
      g.drawString(text,2,2);
      g.flip(); 
    
    }
    
    setInterval(function(){
        getTemp();
        showTemp();
     },1000);
    
    

    Many thanks for your help Gordon!

About

Avatar for user54499 @user54499 started