Issue with interrupting Vl6180x x proximity sensor with esp8266 nodemcu v3?

Hi …how are …do anyone works with that proximity sensor vl6180x…I do a project with that esp8266 nodemcu v3…and there a problem in the interrupting function that even the connection are right and I made sure of it …it interrupts infinitely or it didn’t interrupt at all
I used version 2 of the project and I use the esp8266 nodemcu v3 …the auther of the project told in the buildparts that I can use esp8266 nodemcu v3 even he build the connection schematics with another board
I checked the soldering that I build several and I give it to my colleagues he is professional in that and he confirmed that my connections are right and nothing wrong with that ,so the soldering part is fine
it is an open source project for an engineer called alex …he built it and uploaded it also he uploaded videos for the project after he built it as ademo …so I didnot write the code
but the project files are in software folder you will find 4 files one for the master which is ecu1 and the other 3 for the not master
he also built it except he says I can substitute this chip with esp8266 with the same pins and the same configuration so from your experience what maybe the causes that prevent the sensor from making interrupts if the code is working and the connections are right …is that may be configuration are different ?
the code in the software folder in the link and the shematics in the connection representations in the buildparts foder

Hello.

It seems like there is a lot going on in the project you linked to. If you have not already, can you simplify your setup so that the only thing connected to your ESP8266 is the VL6180X sensor and post some pictures showing their connections? Then, can you test the example programs from our VL6180X Arduino library with minimal modification and let us know if those are behaving as expected?

- Patrick

hi how are you…thank you for responding …first I test vl6180x as a unit with arduino program and it works fine …but when I connect it with the esp project it didnot operate or specifically the interrupt function didnot work even the connections are fine and my colleague checked on it …so do you think it is a matter of configuration …should I change some options in the library of vl6180x to fix the configuration of the sensor with the esp8266 nodemcu v3 ?

If you are using our VL6180X carrier and suspect there might be a hardware issue with it, then we might be able to help you check if the GPIO pins on the board are working using our library. However, it sounds like you can get basic readings from your board, so a hardware issue with our carrier seems unlikely.

That leaves your ESP8266 and the software. We do not have much direct experience working with the ESP8266, and as for the code in the repository you linked to, I took a look and it seems like the test program that uses the interrupt features on the VL6180X is using a library that we did not write. So, we cannot offer much help with that. You might consider reaching out to whoever wrote that code/library. (It sounds like you might have reached out to the creator of the repository already, but maybe the creator of the VL6180X_WE library that the project uses might have some other suggestions.)

- Patrick

Hi…how are you ….final question and I am sorry for bothering you but I need your advice….the interruption function of proximity sensor vl6180x didnot work on esp8266 nodemcu v3 ….I connect the sensor pins (vin → 3.3v , gnd → gnd , gpio → D6 , sda ->D2 , scl ->D1 )……but the results are nonstop interruptions(255) but it measure the distance to the sensor….

So what do you think should I change the connection pins or change a specific registery in your library

That is the test code so what do you think ?

#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <VL6180X_WE.h>
#define VL6180X_ADDRESS 0x29
#define LED 2
#define LEDNR 16
#define TOF_INT 12
#define SCL_PIN 5
#define SDA_PIN 4

VL6180xIdentification identification;
VL6180x TOFsensor(VL6180X_ADDRESS);

Adafruit_NeoPixel pixels(LEDNR, LED, NEO_GRB + NEO_KHZ800);
int i = 0;

volatile bool interruptReceived = false;

ICACHE_RAM_ATTR void handleInterrupt() {
  interruptReceived = true;
}



void setup() {
  Serial.begin(115200);
  Wire.begin(SDA_PIN, SCL_PIN);  //Initialize I2C for VL6180x (TOF Sensor)
  pixels.begin();                // Initialize NeoPixel ring

  pixels.clear();
  pixels.show();

  pinMode(TOF_INT, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(TOF_INT), handleInterrupt, FALLING);

  delay(1000);

  while(TOFsensor.VL6180xInit() == VL6180x_FAILURE_RESET){
    Serial.println("FAILED TO INITALIZE"); //Initialize device and check for errors

  }
  TOFsensor.VL6180xDefautSettings(); //Load default settings to get started.
  delay(1000);
    TOFsensor.VL6180xSetDistInt(10 ,10); 
    TOFsensor.getDistanceContinously();
}

void loop() {
  if (interruptReceived) {
    Serial.println("Intrerupt received");
    Serial.println(TOFsensor.getLastDistanceFromHistory());
    for (int i = 0; i < LEDNR; i++) {
      pixels.setPixelColor(i, pixels.Color(50, 0, 0));
      pixels.show();
      delay(100);
    }
    Serial.println("Light Set");
    interruptReceived = false;
    TOFsensor.VL6180xClearInterrupt();
    Serial.println("Intrerupt cleared");
  }

  pixels.clear();
  pixels.show();
    
}

Note:(from VL6180X_WE.h library I get the function names and specific parts that contian getregister and setregister values so you can have a look at the register values so maybe you can suggest I can modify the register value so the intteruption function can work properly
VL6180X_WE.h


#define VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO         0x0014
#define VL6180X_SYSTEM_INTERRUPT_CLEAR               0x0015
#define VL6180X_RESULT_INTERRUPT_STATUS_GPIO         0x004F
#define VL6180X_I2C_SLAVE_DEVICE_ADDRESS             0x0212

  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x00); // Configures interrupt on ‘New Sample Ready threshold event’ 

uint8_t VL6180x::getDistance()
{
  VL6180x_setRegister(VL6180X_SYSRANGE_START, 0x01); //Start Single shot mode (=0x01)  //ACHTUNG!!!!!!!!!!!!! gewechselt von 0x01
  delay(10);
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);
  return VL6180x_getRegister(VL6180X_RESULT_RANGE_VAL);
  //    return distance;
}
float VL6180x::getAmbientLight(vl6180x_als_gain VL6180X_ALS_GAIN)
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);



void VL6180x::VL6180xSetDistInt(uint8_t lowThres, uint8_t highThres){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x03);

void VL6180x::VL6180xSetALSInt(vl6180x_als_gain VL6180X_ALS_GAIN, uint16_t lowThres, uint16_t highThres){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x18);

uint8_t VL6180x::getDistanceContinously()
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);

float VL6180x::getAmbientLightContinously(vl6180x_als_gain VL6180X_ALS_GAIN)
{
 VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);


void VL6180x::VL6180xClearInterrupt(void){
    VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);
}

uint8_t VL6180x::changeAddress(uint8_t old_address, uint8_t new_address){
  
  //NOTICE:  IT APPEARS THAT CHANGING THE ADDRESS IS NOT STORED IN NON-VOLATILE MEMORY
  // POWER CYCLING THE DEVICE REVERTS ADDRESS BACK TO 0X29
 
  if( old_address == new_address) return old_address;
  if( new_address > 127) return old_address;
   
   VL6180x_setRegister(VL6180X_I2C_SLAVE_DEVICE_ADDRESS, new_address);
   _i2caddress = new_address;


uint8_t VL6180x::VL6180x_getRegister(uint16_t registerAddr)
{
  uint8_t data;

  Wire.beginTransmission( _i2caddress ); // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); //MSB of register address
  Wire.write(registerAddr & 0xFF); //LSB of register address
  Wire.endTransmission(false); //Send address and register address bytes
  Wire.requestFrom( _i2caddress , 1);
  data = Wire.read(); //Read Data from selected register

  return data;
}


uint16_t VL6180x::VL6180x_getRegister16bit(uint16_t registerAddr)
{
  uint8_t data_low;
  uint8_t data_high;
  uint16_t data;

  Wire.beginTransmission( _i2caddress ); // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); //MSB of register address
  Wire.write(registerAddr & 0xFF); //LSB of register address
  Wire.endTransmission(false); //Send address and register address bytes

  Wire.requestFrom( _i2caddress, 2);
  data_high = Wire.read(); //Read Data from selected register
  data_low = Wire.read(); //Read Data from selected register
  data = (data_high << 8)|data_low;

  return data;
}


void VL6180x::VL6180x_setRegister(uint16_t registerAddr, uint8_t data)
{
  Wire.beginTransmission( _i2caddress ); // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); //MSB of register address
  Wire.write(registerAddr & 0xFF); //LSB of register address
  Wire.write(data); // Data/setting to be sent to device.
  Wire.endTransmission(); //Send address and register address bytes
}

void VL6180x::VL6180x_setRegister16bit(uint16_t registerAddr, uint16_t data)
{
  Wire.beginTransmission( _i2caddress ); // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); //MSB of register address
  Wire.write(registerAddr & 0xFF); //LSB of register address
  uint8_t temp;
  temp = (data >> 8) & 0xff;
  Wire.write(temp); // Data/setting to be sent to device
  temp = data & 0xff;
  Wire.write(temp); // Data/setting to be sent to device
  Wire.endTransmission(); //Send address and register address bytes
}

void VL6180x::VL6180xDefautSettings(void){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x00); // Configures interrupt on ‘New Sample Ready threshold event’ 


uint8_t VL6180x::getDistance()
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);


float VL6180x::getAmbientLight(vl6180x_als_gain VL6180X_ALS_GAIN)
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);



void VL6180x::VL6180xSetDistInt(uint8_t lowThres, uint8_t highThres){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x01);


void VL6180x::VL6180xSetALSInt(vl6180x_als_gain VL6180X_ALS_GAIN, uint16_t lowThres, uint16_t highThres){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x18);


uint8_t VL6180x::getDistanceContinously()
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);


float VL6180x::getAmbientLightContinously(vl6180x_als_gain VL6180X_ALS_GAIN)
{
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);

void VL6180x::VL6180xClearInterrupt(void){
  VL6180x_setRegister(VL6180X_SYSTEM_INTERRUPT_CLEAR, 0x07);
}

I added your latest post to your previous thread since it is about the same topic. As I mentioned before, we are not familiar with the software (we did not write the VL6180X_WE library) or the specific microcontroller you are using, so the direct support we can offer in this situation is limited. I suggest you try to solicit help from someone more familiar with the software and/or controller you are using.

- Patrick

one ast point about connections of vl6180x…sometimes the power reached it and worked and other times the power didnot reach it and in that time i have to unplug and replug the esp to the pc port or reset the esp until the power reached it…i connect the sensor to 3.3v pin altought I found some projects connect it to 5v but I afraid to do that or it will burn …so what is the right connections?

Can you post some pictures of your board that show your current connections?

- Patrick

I don’t know if this will help you as you didn’t follow passages or check it from photo of a real project…i take some and i hope you figure out something from that…first that is the diagram


vl6180x


So what are the reasons that leads to the sensor sometimes work and sometimes not…or sometimes power reached and other times didnot reach(as sometimes i found the red led in the sensor lights and sometimes it is turned off)?

The board you are using is not one of our VL6180X carriers, so we cannot offer support for it. You might try contacting the manufacturer to see if they have any suggestions.

- Patrick