Avatar for user109290

user109290

Member since Feb 2020 • Last active Feb 2020
  • 1 conversations
  • 11 comments

Most recent activity

  • in Projects
    Avatar for user109290

    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!

  • in Projects
    Avatar for user109290

    Hi Robin, thank you again for your help. I completely understand you, there is no need to apologize. I will try to make a landing page over the weekend.

  • in Projects
    Avatar for user109290

    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

  • in Projects
    Avatar for user109290

    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.

  • in Projects
    Avatar for user109290

    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!

  • in Projects
    Avatar for user109290

    Yes, I am talking about this error.

    I agree with you, but I could not find the error on the library I wrote. I will keep looking at it, thanks!

  • in Projects
    Avatar for user109290

    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);
    
  • in Projects
    Avatar for user109290

    Thank you! I will definitely look into it.

  • in Projects
    Avatar for user109290

    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!

Actions