You are reading a single comment by @allObjects and its replies.
Click here to read the full conversation.
-
Hi allObject, I worked on it today and I made it working using your logic. I changed something on the code, but nothing relevant. I needed a bit of troubleshooting, but your help was essential. Thank you very much!
I attach the final version of both library and main code, it may be helpful for someone else.
var sensor1; var I2C1 = new I2C(); var sensor1IID; 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, {address:0x29}); } function doStart(){ initHW(); initHW(); initSensor(); var status = sensor1.readRangeStatus(); if (status==0){ setTimeout(function(){ sensor1IID = setInterval(function(){ sensor1.readRange(function(err,val){ if(err){ console.log("ModuleError:", err, " - DeviceError:", val); } else{ console.log("Sensor 1: ",val,"mm"); } }); },200); },1); } else{ console.log("Err status: ", status); } } function onInit(){ doStart(); } setTimeout(onInit, 999);
Library: https://github.com/SalvoCas/EspruinoDocs/blob/master/devices/VL6180X.js
@Robin, somehow noticed only Arduino... even though in same line / phrase PuckJS and MDBT42Q show. @user109290, sorry for that.
@Robin, regarding the error: it's the 3 aspects of it: error value, name and description in bullet list.
@user109290, what is the power supply setup for the sensor?
I'm looking forward to the feedback about success / suitability of my solution examples.