I2C1.setup({scl:B6,sda:B7});
var bmp;
var g = require("SSD1306").connect(I2C1, function() {
bmp = require("BMP085").connect(I2C1);
setInterval(function(){
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();
});
},1000);
});
So initialising the display, and then initialising everything else in its callback. If that doesn't work it could be the BMP085 is messing things up somehow when it's not initialised, so you could try doing it first:
I2C1.setup({scl:B6,sda:B7});
var g;
var bmp = require("BMP085").connect(I2C1);
setTimeout(function() {
g = require("SSD1306").connect(I2C1, function() {
setInterval(function(){
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();
});
},1000);
});
}, 1000 /* 1 sec after BMP085 init */);
Re-initialising the display each time really isn't a solution (it'll flicker massively every time you update it).
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok, try:
So initialising the display, and then initialising everything else in its callback. If that doesn't work it could be the BMP085 is messing things up somehow when it's not initialised, so you could try doing it first:
Re-initialising the display each time really isn't a solution (it'll flicker massively every time you update it).