What sensor would be best for my project

Hi Liam

I am having trouble with the example code for the piico VL53L1X and VEML6030 with my Nano33BLE. Can you help me get through these issues please?

For the VEML6030:

> 
> /*
>   This example code will walk you through how to read ambient light values.
>   Chances are good that you'll use this sensor in various environments so it'll
>   also walk you through setting the gain and integration time that allow for
>   different ranges of lux values. For example using the default gain of 100ms
>   gives you a maximum reading of 30,199 Lux. This is great for daylight
>   readings but not DIRECT sun. Higher integration times mean higher
>   resoultions but lower lux values and vice versa: the lowest integration time
>   and lowest gain should be used for mid day direct light. Check our hookup
>   guide for more information. 
>   
>   SparkFun Electronics
>   Author: Elias Santistevan
>   Date: July 2019
> 
> 	License: This code is public domain but if you use this and we meet someday, get me a beer! 
> 
> 	Feel like supporting our work? Buy a board from Sparkfun!
> 	https://www.sparkfun.com/products/15436
> 
> */
> #include <Arduino_LSM9DS1.h>
> #include <Wire.h>
> #include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
> 
> #define AL_ADDR 0x48
> 
> SparkFun_Ambient_Light light(AL_ADDR);
> 
> // Possible values: .125, .25, 1, 2
> // Both .125 and .25 should be used in most cases except darker rooms.
> // A gain of 2 should only be used if the sensor will be covered by a dark
> // glass.
> float gain = .125;
> 
> // Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
> // Higher times give higher resolutions and should be used in darker light. 
> int time = 100;
> long luxVal = 0; 
> 
> void setup(){
> 
>   Wire.begin();
>   Serial.begin(115200);
> 
>   if(light.begin())
>     Serial.println("Ready to sense some light!"); 
>   else
>     Serial.println("Could not communicate with the sensor!");
> 
>   // Again the gain and integration times determine the resolution of the lux
>   // value, and give different ranges of possible light readings. Check out
>   // hoookup guide for more info. 
>   light.setGain(gain);
>   light.setIntegTime(time);
> 
>   Serial.println("Reading settings..."); 
>   Serial.print("Gain: ");
>   float gainVal = light.readGain();
>   Serial.print(gainVal, 3); 
>   Serial.print(" Integration Time: ");
>   int timeVal = light.readIntegTime();
>   Serial.println(timeVal);
> 
> }
> 
> void loop() 

I get the following error message in Arduino IDE:

> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Example1_Read_Ambient_Basics:38:5: error: 'int time' redeclared as different kind of symbol
> 
>  int time = 100;
> 
>      ^~~~
> 
> In file included from c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:29:0,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_error.h:54,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_util_platform.h:60,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/nrfx_glue.h:182,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/nrfx.h:46,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/hal/nrf_gpio.h:44,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_ARDUINO_NANO33BLE/PinNames.h:23,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\variants\ARDUINO_NANO33BLE/pinmode_arduino.h:17,
> 
>                  from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/Arduino.h:26,
> 
>                  from sketch\Example1_Read_Ambient_Basics.ino.cpp:1:
> 
> c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\time.h:59:11: note: previous declaration 'time_t time(time_t*)'
> 
>  time_t    _EXFUN(time,     (time_t *_timer));
> 
>            ^
> 
> C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino: In function 'void setup()':
> 
> Example1_Read_Ambient_Basics:55:26: error: invalid conversion from 'time_t (*)(time_t*) {aka long long int (*)(long long int*)}' to 'uint16_t {aka short unsigned int}' [-fpermissive]
> 
>    light.setIntegTime(time);
> 
>                           ^
> 
> In file included from C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino:24:0:
> 
> C:\Users\KevB\Documents\Arduino\libraries\SparkFun_Ambient_Light_Sensor_Arduino_Library-master\src/SparkFun_VEML6030_Ambient_Light_Sensor.h:95:10: note:   initializing argument 1 of 'void SparkFun_Ambient_Light::setIntegTime(uint16_t)'
> 
>      void setIntegTime(uint16_t time);
> 
>           ^~~~~~~~~~~~
> 
> C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino: At global scope:
> 
> Example1_Read_Ambient_Basics:67:11: error: expected initializer at end of input
> 
>  void loop()
> 
>            ^
> 
> exit status 1
> 
> 'int time' redeclared as different kind of symbol
> 
> 
> 
> This report would have more information with
> "Show verbose output during compilation"
> option enabled in File -> Preferences.

```````````````````````````````````````````````````````````````````
**For the VL53L1X:**
```````````````````````````````````````````````````````````````````````
/*
This example takes range measurements with the VL53L1X and displays additional 
details (status and signal/ambient rates) for each measurement, which can help
you determine whether the sensor is operating normally and the reported range is
valid. The range is in units of mm, and the rates are in units of MCPS (mega 
counts per second).
*/

#include <Wire.h>
#include <VL53L1X.h>

VL53L1X sensor;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  sensor.setTimeout(500);
  if (!sensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }
  
  // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
  // You can change these settings to adjust the performance of the sensor, but
  // the minimum timing budget is 20 ms for short distance mode and 33 ms for
  // medium and long distance modes. See the VL53L1X datasheet for more
  // information on range and timing limits.
  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);

  // Start continuous readings at a rate of one measurement every 50 ms (the
  // inter-measurement period). This period should be at least as long as the
  // timing budget.
  sensor.startContinuous(50);
}

void loop()
{
  sensor.read();
  
  Serial.print("range: ");
  Serial.print(sensor.ranging_data.range_mm);
  Serial.print("\tstatus: ");
  Serial.print(VL53L1X::rangeStatusToString(sensor.ranging_data.range_status));
  Serial.print("\tpeak signal: ");
  Serial.print(sensor.ranging_data.peak_signal_count_rate_MCPS);
  Serial.print("\tambient: ");
  Serial.print(sensor.ranging_data.ambient_count_rate_MCPS);
  
  Serial.println();
}
``````````````````````````````````````````````````````````````````````````````````````
**I get the following errors:**
``````````````````````````````````````````````````````````````````````````````````````
> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
> 
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp: In member function 'void VL53L1X::writeReg32Bit(uint16_t, uint32_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:188:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
> 
>    bus->write((value >> 24) & 0xFF); // value highest byte
> 
>                                   ^
> 
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
> 
>                  from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
> 
>      virtual size_t write(uint8_t data);
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
> 
>      virtual size_t write(int data) {
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:189:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
> 
>    bus->write((value >> 16) & 0xFF);
> 
>                                   ^
> 
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
> 
>                  from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
> 
>      virtual size_t write(uint8_t data);
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
> 
>      virtual size_t write(int data) {
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:190:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
> 
>    bus->write((value >>  8) & 0xFF);
> 
>                                   ^
> 
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
> 
>                  from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
> 
>      virtual size_t write(uint8_t data);
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
> 
>      virtual size_t write(int data) {
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:191:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
> 
>    bus->write( value        & 0xFF); // value lowest byte
> 
>                                   ^
> 
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
> 
>                  from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
> 
>      virtual size_t write(uint8_t data);
> 
>                     ^~~~~
> 
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
> 
>      virtual size_t write(int data) {
> 
>                     ^~~~~
> 
> exit status 1
> 
> Error compiling for board Arduino Nano 33 BLE.
> 
> 
> 
> This report would have more information with
> "Show verbose output during compilation"
> option enabled in File -> Preferences.
``````````````````````````````````````````````````````````````````````````````
1 Like