How to read from the 32-bit register (0x7c) of VL6180X Time of Flight sensor

I tried to read from the 0x7c register of the VL6180X Time of Flight sensor, but i keep getting this error,

qualified-id in declaration before ‘(’ token

please can someone help know whats wrong and how to fix it. Below is my code

#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.readRangeContinuousMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(” TIMEOUT"); }

//Serial.print("Convergence time: ");
//Serial.print(uint32_t readReg32Bit(uint16_t 0x7c));

// Reads a 32-bit register
uint32_t VL6180X::readReg32Bit(uint16_t reg)
{
uint32_t value;

Wire.beginTransmission(0x7c);
Wire.write((reg >> 8) & 0xff); // reg high byte
Wire.write(reg & 0xff); // reg low byte
last_status = Wire.endTransmission();

Wire.requestFrom(0x7c, (uint8_t)4);
value = (uint32_t)Wire.read() << 24; // value highest byte
value |= (uint32_t)Wire.read() << 16;
value |= (uint16_t)Wire.read() << 8;
value |= Wire.read(); // value lowest byte
Wire.endTransmission();

return value;
}

Serial.println();
}

Thank you

Gbouna:
Wire.write((reg >> 8) & 0xff); // reg high byte

Cool code bro!

Please have a look at "How to use the forum" and edit your post accordingly, especially about the code-tags. That way we can easily copy and check the code.

its seems to me a ‘}’ is in the wrong place in the code you posted.

Should be like this I think (untested since I dont have the libs).

#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.readRangeContinuousMillimeters());
  if (sensor.timeoutOccurred()) {
    Serial.print(" TIMEOUT");
  }

  //Serial.print("Convergence time: ");
  //Serial.print(uint32_t readReg32Bit(uint16_t 0x7c));
  Serial.println();

}

// Reads a 32-bit register
uint32_t VL6180X::readReg32Bit(uint16_t reg)
{
  uint32_t value;

  Wire.beginTransmission(0x7c);
  Wire.write((reg >> 8) & 0xff);  // reg high byte
  Wire.write(reg & 0xff);         // reg low byte
  last_status = Wire.endTransmission();

  Wire.requestFrom(0x7c, (uint8_t)4);
  value = (uint32_t)Wire.read() << 24;  // value highest byte
  value |= (uint32_t)Wire.read() << 16;
  value |= (uint16_t)Wire.read() << 8;
  value |= Wire.read();                 // value lowest byte
  Wire.endTransmission();

  return value;
}

Hi,
What model Arduino have you written this code for?

Thanks.. Tom.. :slight_smile:

Hi,
Not sure what this is supposed to do?

// Reads a 32-bit register
  uint32_t VL6180X::readReg32Bit(uint16_t reg)

Tom... :slight_smile: