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);
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.
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:
this doesnt work!
what i needed was
Many thanks for your help Gordon!