Avatar for user54499

user54499

Member since Apr 2015 • Last active Apr 2015
  • 1 conversations
  • 12 comments

Most recent activity

    • 26 comments
    • 7,534 views
  • in Interfacing
    Avatar for user54499

    Its a bit finicky at best for the BMP085.I submitted some code changes on Github which should help out a lot, instead of just locking the I2C bus permanently, it should just return null and let you try again. Previously if your BMP fails to init for some reason, you have to do a FULL reset and re-upload! Looks like the changes are now live.

  • in Interfacing
    Avatar for user54499

    its all working now, although i have to reset the pico alot as the i2c bus locks up. is there any way to safely stop the i2c stuff? and or is there a better way of reseting other than re-plugging it.

  • in Interfacing
    Avatar for user54499

    Okay, it does work thanks for your help Gordon, it was indeed because i was initialising each time. The code that eventually worked properly was

    I2C1.setup({scl:B6,sda:B7});
    var g = require("SSD1306").connect(I2C1);
    var bmp = require("BMP085").connect(I2C1);
    //... more code here
    setInterval(function(){
    bmp.getPressure(function(d) {
        //console.log("Pressure: " + d.pressure + " Pa");
        console.log("Temperature: " + d.temperature + " C");
        g.clear();
      g.setFontVector(20);
       g.drawString("Temp: ",0,0);
      g.drawString(" "+ d.temperature + " C",0,25);
       // write to the screen
       g.flip(); 
      });
    },1000);
    
  • in Interfacing
    Avatar for user54499

    unless im doing somthing wrong it no workie. Heres the code:

    I2C1.setup({scl:B6,sda:B7});
    
    
    var text ="temp";
    var fontsize =2;
    
    function getTemp()
    {
      var bmp = require("BMP085").connect(I2C1);
      if (!bmp)
      {
        console.log("bmp failed to init");
        return null;
      }
      bmp.getPressure(function(d) {
      text = "" + d.temperature + " C";
      });
      
    }
    
    function showTemp()
    {
      //require("Font8x12").add(Graphics);
      var g = require("SSD1306").connect(I2C1);
        if (!g)
      {
        console.log("g failed to init");
        return null;
      }
      g.clear();
      g.setColor(255,255,255);
      g.setFontVector(fontsize);
      //g.setFont8x12();
      g.drawString("Temperature: ",0,0);
      g.drawString(text,0,20);
      g.flip(); 
    
    }
    
    function onInit(){
    setInterval(function(){
        getTemp();
        showTemp();
     },1000);
    }
    

    if i increase the fontsize variable beyond 4 it freezes up (sometimes loops a couple of times) seems like a leak or overflow somewhere.

  • in Interfacing
    Avatar for user54499

    iv also ran into more problems with the SSD1306 display. if you increase the font size to more than about 4 (so its actually readable) it crashes.
    using :

    g.setFontVector(fontsize);
    

    very strange.

  • in Interfacing
    Avatar for user54499

    The top one doesnt work, i was doing the setup, just ommited it in my example.

  • in Interfacing
    Avatar for user54499

    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!

  • in Interfacing
    Avatar for user54499

    Okay thats good, could you give an example of doing this? I keep getting Timeout on I2C Write BUSY

  • in Interfacing
    Avatar for user54499

    Sweet, many thank!

Actions