-
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
-
Wed 2020.02.12
@user109290, in post #16, snippet L3, I notice a somewhat older version of Espruino. As you are well into module writing, one might benefit with newer ES6 concepts.
While there was no need to, it is I that must also apologize for being nit-picky. My request for the detail was only as the sequence of needed info wasn't appearing timely, (I'm sure from your end, you were focused on gettin' it done) and things were starting to smell a bit rotten. This concern arose from a user that also appeared a bit sketchy from a post around a year ago, and both @allObjects and I spent hours, I know I spent twenty, and I'm sure allObjects had triple that, cranking out code snippets for every exception that popped up, then the user just disappeared!! Not a total loss however, as despite all that, allObjects soldiered on completing his new concept for a game solution for his grandkids! Even shot some videos:
Both of us have learned to now be more cautious, and a few items here seemed to me that we were going down that same path to no resolution.
'final version of both library and main code, it may be helpful for someone else'
Yes indeed, but even though this content is within the 'Projects' forum heading, it may get missed, when the inquisitive are searching from the main site.
Salvatore, you have here an exceptional work that would benefit others. Once I saw the video, post #16, I now see the excitement you had, wanting to make this work. I applaud you!I know this would take yet another day of effort, but please do consider memoralizing your effort with a landing page, with your name in blazing glory, accessible from the main site,
something like:As I wrote a week ago back in post #2, 'nicely written and tidy module' and indeed exceptional at that.
@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.