Thanks for the help. I changed my code in this way, but I still have the overflow error. I do not really know why there is still this error, since the module works perfectly fine with Arduino, whit a library having the same logic flow of the one I built for Espurino.
var sensor1;
var I2C1 = new I2C();
function onTimer() {
var l1 = sensor1.readRange();
console.log("Sensor 1: "+ l1 +" mm");
}
function initHW(){
digitalWrite(D31, 0);
I2C1.setup({sda:D1, scl:D2, bitrate:400000});
}
function initSensor(){
console.log('Initialazing sensor');
digitalWrite(D31, 1);
sensor1 = require("https://github.com/SalvoCas/EspruinoDocs/blob/master/devices/VL6180X.js").connect(I2C1);
}
function doStart(){
initHW();
initSensor();
setTimeout(function() {}, 1);
var status = sensor1.readRangeStatus();
if(status == 0){
setInterval(onTimer, 500);
}
else{
console.log('Error number: '+ status);
}
}
function onInit(){
doStart();
}
setTimeout(onInit, 999);
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.
Thanks for the help. I changed my code in this way, but I still have the overflow error. I do not really know why there is still this error, since the module works perfectly fine with Arduino, whit a library having the same logic flow of the one I built for Espurino.