Problem getting readings from VEML7700 Sensor

I'm using a VEML7700 lux sensor board from adafruit and I am unable to get the correct readings printing to the serial monitor. The only thing that is being printed to the serial monitor is the first print statement as shown in the screenshot below.

The code provided below that I have used is an example from adafruit's library for the sensor. My problem is very similar to the one presented in this post
Problem Getting Readings from VEML7700

Here is the sensor I am using https://learn.adafruit.com/adafruit-veml7700/arduino

The board I'm using is a Arduino Nano 33 BLE Sense Rev2.
I am also on Arduino IDE Version 2.0.3.

The Arduino is being powered through the USB cable and the sensor is powered through the Arduino's +3V3 OUT pin connected to the positive voltage rail on the breadboard. I've checked for continuity between pins with a multimeter and everything seems to be connected fine. The sensor board's VIN pin gets 3.27 volts
according to my multimeter. Here is a rough sketch of a schematic of my connections as well as the Arduino pinout.


Here are pictures of my breadboard with the sensor connected & disconnected below the code (I have the wires connected under the sensor).


I think that it is also worth mentioning that while running the I2C scanner sketch the address is found as shown in the provided screenshot below

#include "Adafruit_VEML7700.h"

Adafruit_VEML7700 veml = Adafruit_VEML7700();

void setup() {
  Serial.begin(115200);
  while (!Serial) { delay(10); }
  Serial.println("Adafruit VEML7700 Test");

  if (!veml.begin()) {
    Serial.println("Sensor not found");
    while (1);
  }
  Serial.println("Sensor found");

  // == OPTIONAL =====
  // Can set non-default gain and integration time to
  // adjust for different lighting conditions.
  // =================
  // veml.setGain(VEML7700_GAIN_1_8);
  // veml.setIntegrationTime(VEML7700_IT_100MS);

  Serial.print(F("Gain: "));
  switch (veml.getGain()) {
    case VEML7700_GAIN_1: Serial.println("1"); break;
    case VEML7700_GAIN_2: Serial.println("2"); break;
    case VEML7700_GAIN_1_4: Serial.println("1/4"); break;
    case VEML7700_GAIN_1_8: Serial.println("1/8"); break;
  }

  Serial.print(F("Integration Time (ms): "));
  switch (veml.getIntegrationTime()) {
    case VEML7700_IT_25MS: Serial.println("25"); break;
    case VEML7700_IT_50MS: Serial.println("50"); break;
    case VEML7700_IT_100MS: Serial.println("100"); break;
    case VEML7700_IT_200MS: Serial.println("200"); break;
    case VEML7700_IT_400MS: Serial.println("400"); break;
    case VEML7700_IT_800MS: Serial.println("800"); break;
  }

  veml.setLowThreshold(10000);
  veml.setHighThreshold(20000);
  veml.interruptEnable(true);
}

void loop() {
  Serial.print("raw ALS: "); Serial.println(veml.readALS());
  Serial.print("raw white: "); Serial.println(veml.readWhite());
  Serial.print("lux: "); Serial.println(veml.readLux());

  uint16_t irq = veml.interruptStatus();
  if (irq & VEML7700_INTERRUPT_LOW) {
    Serial.println("** Low threshold");
  }
  if (irq & VEML7700_INTERRUPT_HIGH) {
    Serial.println("** High threshold");
  }
  delay(500);
}

Hi and welcome to the forum.

Thanks for using code tags when you posted your code, not many newbies do that.

Also I approve of your breadboarding technique. That's how I use them too.

But please don't post screen shots of, for example, serial monitor, or other screens that could be copied and pasted as text into your post (again, between code tags).

Have you tried 2x 3K3 pull-up resistors between the SDA and SCL pins and 3.3V? To be honest, if i2c scanner sketch runs ok this is probably not the problem.

The serial monitor in your picture seems to show the text "VEML7700 Demo" but this message doesn't seem to appear anywhere in the sketch you posted?

Thank you for the feedback about my post. I'll keep in mind to avoid posting screenshots in the future.

As for the pull up resistors, they didn't work. I measured the resistance between the SDA & SCL pins to VIN and they both measure 10k so I should be fine in that aspect.

However, I also have a Metro Mini purchased from Adafruit and the sketch seems to work exactly as intended. Maybe there's some compatibility issue here? I'm not sure.
https://learn.adafruit.com/adafruit-metro-mini/overview

Oh, and the "VEML7700 Demo" message was a screenshot from when I attempted uploading one of the other example sketches for an SSD1306 OLED that also didn't work. They replace the "Adafruit VEML7700 Test" print message to "VEML7700 Demo" in this one.
VEML7700_oled.ino (1.0 KB)

I don't have any other suggestions at the moment.

The Metro Mini is a 5V board and the Nano 33 is 3.3V, but the Adafruit page for the VEML7700 seems to say it works with either, and to connect it's Vin pin to the supply voltage the Arduino board you are using. (Although I don't understand how the sensor board can output 3.3V if it is only given 3.3V input).

Another difference between the Metro Mini and the Nano 33 is that one is 8 bit and the other is 32 bit. But Adafruit sell plenty of 32 bit boards, they must have tested their sensor with those too.

Okay, thank you for taking your time to try and help me out.

I guess for now I'll just use Sparkfun's library for the VEML7700, although I am a bit disappointed. I would have preferred to use Adafruit's since theirs seems to have many more configuration settings & functions.

Sparkfun's library works but Adafruit's doesn't, with the same hardware setup? That would seem to prove there's nothing wrong with the hardware.

Please post the working sketch with the Sparkfun library. Maybe the forum can spot some difference that would explain why the Adafruit version is not working.

Here is Adafruit's example sketch as well as the github link to the library if you would like to look at the source code.
https://github.com/adafruit/Adafruit_VEML7700

#include "Adafruit_VEML7700.h"

Adafruit_VEML7700 veml = Adafruit_VEML7700();

void setup() {
  Serial.begin(115200);
  while (!Serial) { delay(10); }
  Serial.println("Adafruit VEML7700 Test");

  if (!veml.begin()) {
    Serial.println("Sensor not found");
    while (1);
  }
  Serial.println("Sensor found");

  // == OPTIONAL =====
  // Can set non-default gain and integration time to
  // adjust for different lighting conditions.
  // =================
  // veml.setGain(VEML7700_GAIN_1_8);
  // veml.setIntegrationTime(VEML7700_IT_100MS);

  Serial.print(F("Gain: "));
  switch (veml.getGain()) {
    case VEML7700_GAIN_1: Serial.println("1"); break;
    case VEML7700_GAIN_2: Serial.println("2"); break;
    case VEML7700_GAIN_1_4: Serial.println("1/4"); break;
    case VEML7700_GAIN_1_8: Serial.println("1/8"); break;
  }

  Serial.print(F("Integration Time (ms): "));
  switch (veml.getIntegrationTime()) {
    case VEML7700_IT_25MS: Serial.println("25"); break;
    case VEML7700_IT_50MS: Serial.println("50"); break;
    case VEML7700_IT_100MS: Serial.println("100"); break;
    case VEML7700_IT_200MS: Serial.println("200"); break;
    case VEML7700_IT_400MS: Serial.println("400"); break;
    case VEML7700_IT_800MS: Serial.println("800"); break;
  }

  veml.setLowThreshold(10000);
  veml.setHighThreshold(20000);
  veml.interruptEnable(true);
}

void loop() {
  Serial.print("raw ALS: "); Serial.println(veml.readALS());
  Serial.print("raw white: "); Serial.println(veml.readWhite());
  Serial.print("lux: "); Serial.println(veml.readLux());

  uint16_t irq = veml.interruptStatus();
  if (irq & VEML7700_INTERRUPT_LOW) {
    Serial.println("** Low threshold");
  }
  if (irq & VEML7700_INTERRUPT_HIGH) {
    Serial.println("** High threshold");
  }
  delay(500);
}

Here is the working example sketch from Sparkfun's library as well as the github link to the library if you would like to look at the source code.
https://github.com/sparkfun/SparkFun_VEML7700_Arduino_Library

/*!
 * @file Example1_getLux.ino
 *
 * This example was written by:
 * Paul Clark
 * SparkFun Electronics
 * November 4th 2021
 * 
 * This example demonstrates how to initialize the VEML7700 and then get the ambient light lux.
 * 
 * Want to support open source hardware? Buy a board from SparkFun!
 * <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
 * 
 * Please see LICENSE.md for the license information
 * 
 */

#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700

VEML7700 mySensor; // Create a VEML7700 object

void setup()
{
  Serial.begin(115200);
  Serial.println(F("SparkFun VEML7700 Example"));

  Wire.begin();

  //mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

  // Begin the VEML7700 using the Wire I2C port
  // .begin will return true on success, or false on failure to communicate
  if (mySensor.begin() == false)
  {
    Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
    while (1)
      ;
  }

  Serial.println(F("Lux:"));
}

void loop()
{
  Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
  delay(250);
}

It's very strange. I can't see anything that would explain why this would work on some boards but not all boards.

Did you buy a genuine Adafruit sensor? If so, you could try asking for help on the Adafruit forum.

Hi Paul,
in the Adafruit sketch it seems that there is a missing row:

Serial.println("Adafruit VEML7700 Test");

  if (!veml.begin()) 

Add

  Wire.begin();

between the lines and it will work.

Regards, Snatch65

1 Like

@snatch65 I'm sure @romeo24 will be thankful for your tip. But why did the code work without that line on Metro Mini but did not work on Nano 33 BLE?

Hi, I've tested with an old Arduino Nano.
I think it is related to the initialization of the board and Adafruit libs, I guess.
<-- Not an expert^^

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.