I am trying to connect a distance sensor VL6180x to Arduino Pro Mini via I2C. Yesterday it was working without any problems, but today it refuses to work, even though I haven't changed anything. The sensor has a logic level shifter and pullup resistors onboard. I tested it with Arduino Uno and works perfectly again. However I can't get it to work with Pro Mini again. I am using the Wire library and the VL6180x library. Pins are A4-SDA, A5-SCL, VCC-VIN, GND-GND. Here is the code I am using. It is giving TIMEOUT all the time. I am using an FTDI USB to serial converter to program the Pro Mini.

#include <Wire.h>
#include <VL6180X.h>

VL6180X sensor;

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  sensor.init();
  sensor.configureDefault();

  // Reduce range max convergence time and ALS integration
  // time to 30 ms and 50 ms, respectively, to allow 10 Hz
  // operation (as suggested by Table 6 ("Interleaved mode
  // limits (10 Hz operation)") in the datasheet).
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
  sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);

  sensor.setTimeout(500);

   // stop continuous mode if already active
  sensor.stopContinuous();
  // in case stopContinuous() triggered a single-shot
  // measurement, wait for it to complete
  delay(300);
  // start interleaved continuous mode with period of 100 ms
  sensor.startInterleavedContinuous(100);

}

void loop()
{
  Serial.print("Ambient: ");
  Serial.print(sensor.readAmbientContinuous());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.print("\tRange: ");
  Serial.print(sensor.readRangeContinuous());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

This is the code bit I suspect the problem originates form in the VL6180x library:

uint8_t VL6180X::readRangeContinuous()
{
  uint16_t millis_start = millis();
  while ((readReg(RESULT__INTERRUPT_STATUS_GPIO) & 0x04) == 0)
  {
    if (io_timeout > 0 && ((uint16_t)millis() - millis_start) > io_timeout)
    {
      did_timeout = true;
      return 255;
    }
  }

  uint8_t range = readReg(RESULT__RANGE_VAL);
  writeReg(SYSTEM__INTERRUPT_CLEAR, 0x01);

  return range;
}

Here is my serial monitor:

   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
.....

Any help would be greatly appreciated.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.