-
-
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!
-
-
-
Okay not a problem, it started because I couldn't talk to two I2C devices at once on the same I2C1 bus. And when i say cant, i mean it really messes things up. If i try to communicate with another devices it locks up the stream and i get "Timeout on I2C Write BUSY". Im wondering if its because the whole I2C way of communicating is a singleton. Looking into now.
-
No pullups no, although can try tonight.
It did work fine, hence not trying any pullups, unless I2C2 doesnt have any?PS. You may get a few pull requests from me on github for a couple of modules, not having I2C working properly has forced me to make a few changes so they dont hang and break the rest of the execution.
-
Hi All!
Impressed with the pico so far, but im stuggling to get the I2C2 bit working. Testing with the following code for an OLED, but iv tried other I2C devices to no avail on the second bus.function onInit() { I2C2.setup({scl:B10,sda:B3}); var g = require("SSD1306").connect(I2C2); if(!g) console.log("error initing oled"); else console.log("init SUCCESS"); }
any help appreciated
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.