-
-
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
-
HI Robin, sorry for my lack in information. Right now I am using the breakout board of the module VL6180X by Adafruit (https://www.adafruit.com/product/3316). I am using the puck.js board, the wiring is as follow:
- SDA to D1
- SCL to D2
-GPIO0 to D31
-Power to 3V
-Ground to GND
They are directly connected, since the breakout board should allow it. The wiring seems to be correct, since I made it working and I checked them using the multimeter.
The result of the command process.env is:
>process.env ={ "VERSION": "1v99", "GIT_COMMIT": "f0d66ba", "BOARD": "PUCKJS", "FLASH": 524288, "RAM": 65536, "SERIAL": "6ddd0f13-64ec2540", "CONSOLE": "Bluetooth", "MODULES": "Flash,Storage,net" ... "S,crypto,neopixel", "EXPTR": 536882352 }
I believe that the hints given by allObjects can lead me to write a right code. It is my first project using the Espruino IDE and I am totally new to JavaScript, therefore I wrongly approached the problem as I was working with Arduino or any C-based processor.
Thank you for your help and I again apologize if I have been shallow in my previous posts. - SDA to D1
-
Thank you so much! I really appreciate your help. In someway I made it working using the previous code I showed you, but it is quite unstable and it still yields to errors after a while. In the next days I will implement a code using your logic. I actually had no experience using promises, but I tried to study them yesterday, I will go into more details and try to implement a version of the code using this approach. Thank you again!
-
-
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);
-
-
Thank you for your help! It's the first time I code for Espruino and I still need to get used to it. I had concern about the loop functions, since I thought that the way they work is quite different from the environment I used to work in (especially Arduino). I will try to change my code according to your suggestions, thank you!
-
Hi Robin,
Thank you for your kind reply. Here it is the link to the complete documentation regarding the VL6180X module. In particular, I focused my study on the general datasheet:
https://www.st.com/resource/en/datasheet/vl6180x.pdf
and the technical notes about the range measurement: https://www.st.com/content/ccc/resource/technical/document/application_note/d5/bb/ec/94/7d/1e/40/a0/DM00122600.pdf/files/DM00122600.pdf/jcr:content/translations/en.DM00122600.pdfThis is the main code I am currently using:
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, {address:0x29});
}function doStart(){
initHW();
initSensor();
setTimeout(function() {}, 1);
var status = sensor1.readRangeStatus();
if(status == 0){setInterval(onTimer, 500);
}
else{console.log('Error number: '+ status);
}
}doStart();
The error I am encountering is a overflow error, specified by the RangeStatus number 15.
The espruino board I am using has the latest version on it.Thank you for the help!
-
Hi everyone, I am using this sensor for my project. I looked at the libraries in internet and it seems that there is nothing targeting this module, therefore I write it by my own, following the structures of the libraries of two modules of the same family (VL53L0X and VL53L1X). My code is available on GItHub: https://github.com/SalvoCas/EspruinoDocs/blob/master/devices/VL6180X.js
Right now, I am using puck.js as board, but later I will use the MDBT42Q board. I am able to use the sensor on Arduino, but it is not working using the puck, so I think the problem is on the code I wrote. Still, I could not figure the problem out, so I am asking if anyone knows where is the problem.
I am having various issues. Firstly, the status of the sensor says that it goes on overflow, giving me 15 as error. Then, I tried to an if to control if the device is correctly read on the VL6180X function, but it is not.
Thanks to everyone that will take a look at it!
Thank you for the hints. I will keep to work on it in the next weeks, since it is part of my research project at university. I will try to follow your advice. HW initializing twice is an error, I just copied it twice. Thank you again for your efforts!