I understood the problem.
In order to have a local filesystem stored on a SD card and being able to use the "require " method on the needed files an initial delay must be setup inside the onInit() function.
This is needed not when the code is executed from the terminal, but for the code saved in flash after the execution of the save() function.
On my STM32F4Discovery board 1 second was not enough so I setup for a 2s delay.
After having down this, all worked pretty fine. non garbage on the LCD even restarting
It would be however interesting to know why such a delay is needed.
My code was the following :
var fs ;
var lcd ;
// ============== LCD ======================
var lcd;
var l = false; // var ON =1, OFF = 0;
var tmo_id1;
var root;
// LCD background LED
function LCD_bckgnd(pin,status ) { digitalWrite(pin,status); }
// var lcd_on = LCD_bckgnd(ON,E7); var lcd_off = LCD_bckgnd(OFF,E7);
/* var DELAY(func,interval) = */
function onInit() {
// delay a while …(2s)
setTimeout(function(){
fs = require('fs');
root = fs.readdir();
console.log("onInit(): OK.");
console.log("SD card File System:",root );
console.log("--------------------------------");
var files = fs.readdir(root);
(function(){
for(var i=0;i<files.length;i++){ console.log(" -->",files[i]); }
})();
lcd = require("HD44780").connect(C5,C4,C0,C1,C2,C3);
console.log("--------------------------------");
LCD_bckgnd(E7,true);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(""); // bug fist char lost
lcd.print("Board OK ...");
lcd.setCursor(0,1);
lcd.print("flashing LED1..."); },2000);
tmo_id1 = setInterval( function() { l = !l; LED1.write(l);} , 500);
function logo(){ lcd.setCursor(0,1); lcd.print("G.Varasano @2014"); }
setTimeout(logo,5000);
}
// clearInterval(tmo_id1);
onInit();
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.
I understood the problem.
In order to have a local filesystem stored on a SD card and being able to use the "require " method on the needed files an initial delay must be setup inside the onInit() function.
This is needed not when the code is executed from the terminal, but for the code saved in flash after the execution of the save() function.
On my STM32F4Discovery board 1 second was not enough so I setup for a 2s delay.
After having down this, all worked pretty fine. non garbage on the LCD even restarting
It would be however interesting to know why such a delay is needed.
My code was the following :