Most recent activity
-
-
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);
-
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.
-
-
-
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!
-
-
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.