-
• #2
After upload, did you a) run it and then save it? - or b) save it right away?
Save will after completion call onInit, can you verify that?
I 'm sure you already worked through the Troubleshooting section...
-
• #3
After upload, did you a) run it and then save it? - or b) save it right away?
I have tried both options.Save will after completion call onInit, can you verify that?
Yes it does, in fact while connected it works very well. The problem happens when I connect it without a console, but in the code I do not have any call to write to the console.Compacting Flash... Calculating Size... Writing.. Compressed 81600 bytes to 19967 Running onInit()...
if force the running mode with load(), works ok...
>load() =undefined Loading 20034 bytes from flash... Running onInit()...
I 'm sure you already worked through the Troubleshooting section...
Yes I did but without success.Thanks for your help.
-
• #4
This is the full code
1 Attachment
-
• #5
Looking further, The problem apparently lies in the initialization of SSD1306.
-
• #6
if I plug the USB, connect the IDE and execute "g = require("SSD1306").connect(i2c, start, { height : 32 });" from the console the display update all the information. Looking further to understand why...
-
• #7
OK, i found it. This SSD1306 module, apparently, need at least 1.5 seconds to stabilize.
-
• #8
Ic... you try to use it too early and then it fails.... this 1.5+ secs is probably to initialize all its components.
-
• #9
OK, i found it. This SSD1306 module, apparently, need at least 1.5 seconds to stabilize.
Glad it's working now - so was the issue that you were calling
g.flip
before the SSD1306 had initialised? Or that you actually had to wait a few seconds before even initialising the SSD1306? -
• #10
Tried to look at your uploaded compete code 'Fermentadora'... but don't kow how to look at it.
I though did lookup the SSD1306 module and I found that the
.connect(...)
accepts a callback function as second argument... and when using this callback to call your code that has to be executed afterwards, it should time just right! (The module does internally already a lot ofsetTimeout(...)
to manage timing... for you... when using the callback. If it still does not work, the times used in thesesetTimeout(...)
should be adjusted in the module.)PS: ...could it be that
start
in connect should be something like theStart_read()
?Without knowing all the details, I would give this restructured code a shot:
var dht, i2c, g; function initializeall() { pinMode(B15,'input_pullup'); pinMode(B14,'input_pullup'); pinMode(B13,'input_pullup'); dht = require("DHT22").connect(B5); require("Font6x8").add(Graphics); require("Font8x16").add(Graphics); i2c = new I2C(); i2c.setup({ scl : B6, sda: B7, bitrate: 1000000 }); g = require("SSD1306").connect(i2c, start, { height : 32 }); } function start() { setWatch(selection, B15, { repeat: true, edge:'falling', debounce:20}); setWatch(BtnUP , B14, { repeat: true, edge:'falling', debounce:20}); setWatch(BtnDown , B13, { repeat: true, edge:'falling', debounce:20}); Start_read(); } // ..... function onInit() { USB.setConsole(true); setTimeout(function () { initializeall(); }, 1000); }
-
• #11
I will try to clean the code, and trace the callĀ“s order, and come back again tomorrow. But basically the call to start is in the require(ssd1306) callback.
Thanks for your help.
I think a my be doing something wrong, when run the code from the IDE, everything runs fine. But, when i try to save the code, wrapping the initialization code in a function and calling it from the onInit function does not run unless I call it manually with load(). When I run manually load() everything runs fine too.
The code is uggly, but it's working when i run it manually.
Does anyone has a hint?
Thanks