What sensor would be best for my project

Hey Kevin,

Looks like we’ve got a few errors here. Can you please send through your code from loop down too?

I’m fairly sure it’s just that there’s no implicit conversion between the two data types that are being used here. You should just need to identify which line needs to be which datatype and then switch it in the code so that it compiles correctly.

Hi Bryce,

I was just trying to see if the example code in Arduino would Verify, which it didn’t. The code I am trying to incorporate these two devices into is quite extensive, but all worked with no errors. I did have an Adafruit Distance Sensor originally working, but changed to the piico. I am also still not understanding how to code in the I2c for the VEML6030 and VL53L1X, I can’t get me head around the example: [[I2C Bus and the Arduino - Tutorial]]((https://core-electronics.com.au/tutorials/i2c-with-arduino.html)

> #include <Wire.h>
> #include <Arduino_LSM9DS1.h>
> #include <SparkFun_VEML6030_Ambient_Light_Sensor.h>
> #include <VL53L1X.h>
> 
> 
> #define VL53L1X_sensor 0x29
> VL53L1X sensor (VL53L1X_sensor);
> 
> 
> const unsigned long StandingStillInterval = 5000;
> 
> const float MagnitudeThreshhold = 0.1;  // Determine by experiment
> 
> float x, y, z;
> float oldX, oldY, oldZ;
> long IsStill = false;  // board movement setting
> 
> static unsigned long timeLastMoved = 0;
> 
> float degreesX = 0;
> float degreesY = 0;
> float degreesZ = 0;
> 
> 
> #define buzzerpos D7     //D3 buzzer output
> 
> #define motorPin D3   //vibrator motor output
> int SW1 = 0;
> 
> #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() {
>   {
>     Serial.begin(9600);
>     while (!Serial);
>     Serial.println("Started");
> 
>     if (!IMU.begin())
>     {
>       Serial.println("Failed to initialize IMU!");
>       while (1);
>     }
> 
>     Serial.print("Accelerometer sample rate = ");
>     Serial.print(IMU.accelerationSampleRate());
>     Serial.println("Hz");
>   }
> 
>   {
>     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(33000);
> 
>     // 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);
>   }
> 
>   {
>     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()
> {
> 
>   if (HasMoved())
>   {
>     timeLastMoved = millis();
>     if (millis() - timeLastMoved < StandingStillInterval)
>     {
>       IsStill = false;
>       Serial.print("Started moving again at ");
>       Serial.println(timeLastMoved);
>     }
>   }
> 
>   if (millis() - timeLastMoved > StandingStillInterval)
>   {
>     if (!IsStill)
>     {
>       IsStill = true;
>       Serial.print("Stopped moving at ");
>       Serial.println(timeLastMoved);
> 
>       Serial.print("Has been still for 2 seconds at ");
>       Serial.println(millis());
> 
>     }
> 
>   }
> 
> 
>   // Move eyes whenever not still
>   if (!IsStill)
>   { Eyes();
>   }
> }
> float square(const float f)
> {
>   return f * f;
> }
> 
> boolean HasMoved()
> {
>   if (!IMU.accelerationAvailable())
>     return false;  // Can't tell if it has moved because data isn't available
> 
>   IMU.readAcceleration(x, y, z);
> 
>   float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);
>   //{ Serial.print("magnitude of change: ");
>   //Serial.println(magnitudeOfChange);
>   //}
>   oldX = x;
>   oldY = y;
>   oldZ = z;
> 
>   return magnitudeOfChange > MagnitudeThreshhold;      //measurement of board movement and comparing if greater than Magnitude Threshhold
> }
> 
> /*==============================================
>         Electronic eyes
>   ===================================================*/
> void Eyes()
> {
>   if (HasMoved())
>     ( IsStill == false);
>   { Serial.println("  Started eyes scanning  ");
>     Serial.println(timeLastMoved);
>   }
>   if (IMU.accelerationAvailable())
> 
>     IMU.readAcceleration( x, y, z );
> 
>   float fx, fy, fz;
> 
> 
>   /*==============================================
>     //Angle Measurment code
>     ===================================================*/
> 
>  
>     if (x > 0.1)          //activate angle measurement if within set boundaries
>     {
>       fx = x * 100;
>       degreesX = map(fx, 0, 97, 0, 90);
>       Serial.print("  Tilting up  ");
>       Serial.print(degreesX);
>       Serial.println("  degrees");
>       delay(500);
>     }
> 
>     if (x < -0.1)
>     {
>       fx = x * 100;
>       degreesX = map(fx, 0, -100, 0, 90);
>       Serial.print("Tilting down ");
>       Serial.print(degreesX);
>       Serial.println("  degrees");
>       delay(500);
>     }
> 
>     if (y > 0.1)
>     {
>       fy = y * 100;
>       degreesY = map(fy, 0, 97, 0, 90);
>       Serial.print("Tilting left ");
>       Serial.print(degreesY);
>       Serial.println("  degrees");
>       delay(500);
>     }
> 
>     if (y < -0.1)
>     {
>       fy = y * 100;
>       degreesY = map(fy, 0, -100, 0, 90);
>       Serial.print("Tilting right ");
>       Serial.print(degreesY);
>       Serial.println("  degrees");
>       delay(500);
>     }
> 
>     if (z > 0.1)
>     {
>       fz =  z * 100;
>       degreesZ = map(fz, 0, 97, 0, 90);
>       //   Serial.print("  Tilting up  ");
>       //   Serial.print(degreesZ);
>       //   Serial.println("  degrees");
>       //   delay(500);
>     }
> 
>     if (z < -0.1)
>     {
>       fz =  z * 100;
>       degreesZ = map(fz, 0, -100, 0, 90);
>       //    Serial.print("Tilting down ");
>       //   Serial.print(degreesZ);
>       //   Serial.println("  degrees");
>       //   delay(500);
>     }
> 
> 
>     /*==============================================
>       VL53L1X  Laser measurement
>       ===================================================*/
>     if (IsStill == false)
>     {
>     {
>       sensor.read();
> 
>       /*==============================================
>             Print Laser measurment to Serial Monitor
>         ===================================================*/
> 
> 
> 
>       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();
>     }
> 
> 
>     /*==========================================
>           Control Buzzer and Vibrator Motor
>       ================ ==================================*/
> 
>    
>     { Serial.print("  Moving and now measuring distance  ");
>     }
> 
>     if (sensor.ranging_data.range_mm > 150 && sensor.ranging_data.range_mm < 255)   //these statements activate when true the related switch
>     {
>       SW1 = 1;  //STOP, SLOW
>     }
>     else if (sensor.ranging_data.range_mm > 260 && sensor.ranging_data.range_mm < 355)
>     {
>       SW1 = 2;  //STOP,SLOW,SLOW
>     }
>     else if (sensor.ranging_data.range_mm > 360 && sensor.ranging_data.range_mm < 755)
>     {
>       SW1 = 3;  //SLOW
>     }
>     else if (sensor.ranging_data.range_mm > 760 && sensor.ranging_data.range_mm < 1000)
>     {
>       SW1 = 4; //Just vibrator motor
>     }
> 
>     else {
>       SW1 = 0;
>     }
> 
>     switch (SW1) {
>       case 1:
>         // Serial.println(" Case 1 ");
>         digitalWrite(D7, 255);
>         tone(D7, 5000, 500); // tone on pin 8 at 40000 Hz for 0.1 second
>         digitalWrite(D7, 0);
>         delay(100);     //sound buzzer every second if obstacle distance is between 20-30cm.
>         digitalWrite(motorPin, HIGH);  //vibrator buzzer on
>         delay (100);
>         digitalWrite(motorPin, LOW);   //vibrator buzzer off
>         delay(100);
>         Serial.println(" Case 1 ");
>         delay (500);
>         break;
> 
> 
> 
> 
>       case 2:
>         // Serial.println(" Case 2 ");
>         digitalWrite(D7, 255);
>         tone(D7, 3000, 300); // tone on pin 8 at 35000 Hz for 0.1 second
>         digitalWrite(D7, 0);
>         delay(300);   //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
>         digitalWrite(motorPin, HIGH);
>         delay (350);
>         digitalWrite(motorPin, LOW);
>         delay(350);
>         Serial.println(" Case 2 ");
>         delay (1000);
>         break;
> 
> 
> 
> 
> 
>       case 3:
>         // Serial.println(" Case 3 ");
>         digitalWrite(D7, 255);
>         tone(D7, 2000, 200); // tone on pin 8 at 30000 Hz for 0.2 second
>         digitalWrite(D7, 0);
>         delay(500);    //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
>         digitalWrite(motorPin, HIGH);
>         delay (250);
>         digitalWrite(motorPin, LOW);
>         delay(250);
>         Serial.println(" Case 3 ");
>         delay (1500);
>         break;
> 
> 
> 
> 
>       case 4:
>         // Serial.println(" Case 4 ");
>         digitalWrite(D7, 255);
>         tone(D7, 1000, 100); // tone on pin 8 at 25000 Hz for 0.3 second
>         digitalWrite(D7, 0);
>         delay(700);     //sound buzzer every 0.1 seconds if obstacle distance is between 0-10cm.
>         digitalWrite(motorPin, HIGH);
>         delay (100);
>         digitalWrite(motorPin, LOW);
>         delay(100);
>         Serial.println(" Case 4 ");
>         delay (2000);
>         break;
> 
> 
>       case 0:
>         // Serial.println(" Case 0 ");
>         digitalWrite(D7, 0); //do not sound the buzzer
>         Serial.println(" Case 0 ");
>         break;
> 
>       default:
>         //Serial.println(" SCdefault! ");
>         digitalWrite(D7, 0); //do not sound the buzzer
>         Serial.println(" SCdefault! ");
>         break;
> 
>     }
>   
> 
>   /*==========================================
>            Control LED locator
>        ==================================================*/
> 
>   {
>     luxVal = light.readLight();
>     Serial.print("Ambient Light Reading: ");
>     Serial.print(luxVal);
>     Serial.println(" Lux");
>     delay(1000);
>   }
>    if (luxVal >= 10);
>   {digitalWrite(D2, 255);
>     delay (1000);}
>    else  {digitalWrite(D2, 0);
>   }
>   }
> }

Errors:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"

Cyclops_V1.1:6:31: error: no matching function for call to 'VL53L1X::VL53L1X(int)'

 VL53L1X sensor (VL53L1X_sensor);

                               ^

In file included from C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:4:0:

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:1273:5: note: candidate: VL53L1X::VL53L1X()

     VL53L1X();

     ^~~~~~~

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:1273:5: note:   candidate expects 0 arguments, 1 provided

In file included from C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:4:0:

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: candidate: constexpr VL53L1X::VL53L1X(const VL53L1X&)

 class VL53L1X

       ^~~~~~~

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note:   no known conversion for argument 1 from 'int' to 'const VL53L1X&'

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: candidate: constexpr VL53L1X::VL53L1X(VL53L1X&&)

C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note:   no known conversion for argument 1 from 'int' to 'VL53L1X&&'

Cyclops_V1.1:40: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\Cyclops_V1.1.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\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: In function 'void setup()':

Cyclops_V1.1:97:28: 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\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:3: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\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: In function 'void Eyes()':

Cyclops_V1.1:404:4: error: expected '}' before 'else'

    else  {digitalWrite(D2, 0);

    ^~~~

C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: At global scope:

Cyclops_V1.1:407:1: error: expected declaration before '}' token

 }

 ^

exit status 1

no matching function for call to 'VL53L1X::VL53L1X(int)'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is my original working code with the Adafuit Distance Sensor:


#include <Arduino_LSM9DS1.h>
#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

const unsigned long StandingStillInterval = 5000;

const float MagnitudeThreshhold = 0.1;  // Determine by experiment

float x, y, z;
float oldX, oldY, oldZ;
long IsStill = false;  // board movement setting

static unsigned long timeLastMoved = 0;


float degreesX = 0;
float degreesY = 0;
float degreesZ = 0;

//#define buzzerneg 12     //pin 12 buzzer negative GND 
#define buzzerpos D7     //D3 buzzer output

//char LaserMeasurement = 0;

#define motorPin D3   //vibrator motor output
int SW1 = 0;



void setup()
{
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Started");

  if (!IMU.begin())
  {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }

  Serial.print("Accelerometer sample rate = ");
  Serial.print(IMU.accelerationSampleRate());
  Serial.println("Hz");

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin())
  {
    Serial.println(F("Failed to boot VL53L0X"));
    while (1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}

void loop()
{

  if (HasMoved())
  {
    timeLastMoved = millis();
    if (millis() - timeLastMoved < StandingStillInterval)
    {
      IsStill = false;
      Serial.print("Started moving again at ");
      Serial.println(timeLastMoved);
    }
  }

  if (millis() - timeLastMoved > StandingStillInterval)
  {
    if (!IsStill)
    {
      IsStill = true;
      Serial.print("Stopped moving at ");
      Serial.println(timeLastMoved);

      Serial.print("Has been still for 2 seconds at ");
      Serial.println(millis());

    }

  }


  // Move eyes whenever not still
  if (!IsStill)
  { Eyes();
  }
}
float square(const float f)
{
  return f * f;
}

boolean HasMoved()
{
  if (!IMU.accelerationAvailable())
    return false;  // Can't tell if it has moved because data isn't available

  IMU.readAcceleration(x, y, z);

  float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);
  //{ Serial.print("magnitude of change: ");
  //Serial.println(magnitudeOfChange);
  //}
  oldX = x;
  oldY = y;
  oldZ = z;

  return magnitudeOfChange > MagnitudeThreshhold;      //measurement of board movement and comparing if greater than Magnitude Threshhold
}

/*==============================================
        Electronic eyes
  ===================================================*/
void Eyes()
{
  if (HasMoved())
    ( IsStill == false);
  { Serial.println("  Started eyes scanning  ");
    Serial.println(timeLastMoved);
  }
  if (IMU.accelerationAvailable())

    IMU.readAcceleration( x, y, z );

  float fx, fy, fz;

  /*==============================================
    //Angle Measurment code
    ===================================================*/

  {
    if (x > 0.1)          //activate angle measurement if within set boundaries
    {
      fx = x * 100;
      degreesX = map(fx, 0, 97, 0, 90);
      Serial.print("  Tilting up  ");
     Serial.print(degreesX);
      Serial.println("  degrees");
      delay(500);
    }

    if (x < -0.1)
    {
      fx = x * 100;
      degreesX = map(fx, 0, -100, 0, 90);
      Serial.print("Tilting down ");
      Serial.print(degreesX);
     Serial.println("  degrees");
      delay(500);
    }

    if (y > 0.1)
    {
      fy = y * 100;
      degreesY = map(fy, 0, 97, 0, 90);
      Serial.print("Tilting left ");
      Serial.print(degreesY);
      Serial.println("  degrees");
      delay(500);
    }

    if (y < -0.1)
    {
      fy = y * 100;
      degreesY = map(fy, 0, -100, 0, 90);
      Serial.print("Tilting right ");
      Serial.print(degreesY);
      Serial.println("  degrees");
      delay(500);
    }

    if (z > 0.1)
    {
      fz =  z * 100;
      degreesZ = map(fz, 0, 97, 0, 90);
      //   Serial.print("  Tilting up  ");
      //   Serial.print(degreesZ);
      //   Serial.println("  degrees");
      //   delay(500);
    }

    if (z < -0.1)
    {
      fz =  z * 100;
      degreesZ = map(fz, 0, -100, 0, 90);
      //    Serial.print("Tilting down ");
      //   Serial.print(degreesZ);
      //   Serial.println("  degrees");
      //   delay(500);
    }


    /*==============================================
      VL53L0X  Laser measurement
      ===================================================*/


    VL53L0X_RangingMeasurementData_t measure;

    Serial.print("Reading a measurement... ");
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout


    /*==============================================
          Print Laser measurment to Serial Monitor
      ===================================================*/

    if (measure.RangeStatus != 4) {  // phase failures have incorrect data
      Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
      //LaserMeasurement = measure.RangeMilliMeter;
    } else {
      Serial.println(" out of range ");
    }

    delay(100);


    /*==========================================
          Control Buzzer and Vibrator Motor
      ================ ==================================*/

    if (IsStill == false)
    { Serial.print("  Moving and now measuring distance  ");
    }

    if (measure.RangeMilliMeter > 150 && measure.RangeMilliMeter < 255)   //these statements activate when true the related switch
    {                                           
      SW1 = 1;  //STOP, SLOW
    }
    else if (measure.RangeMilliMeter > 260 && measure.RangeMilliMeter < 355)
    {
      SW1 = 2;  //STOP,SLOW,SLOW
    }
    else if (measure.RangeMilliMeter > 360 && measure.RangeMilliMeter < 755)
    {
      SW1 = 3;  //SLOW
    }
    else if (measure.RangeMilliMeter > 760 && measure.RangeMilliMeter < 1000)
    {
      SW1 = 4; //Just vibrator motor
    }
      
    else {SW1 = 0;}

    switch (SW1) {
      case 1:
       // Serial.println(" Case 1 ");
        digitalWrite(D7, 255);
        tone(D7, 5000, 500); // tone on pin 8 at 40000 Hz for 0.1 second
        digitalWrite(D7, 0);
        delay(100);     //sound buzzer every second if obstacle distance is between 20-30cm.
        digitalWrite(motorPin, HIGH);  //vibrator buzzer on
        delay (100);
        digitalWrite(motorPin, LOW);   //vibrator buzzer off
        delay(100);
        Serial.println(" Case 1 ");
        break;




      case 2:
       // Serial.println(" Case 2 ");
        digitalWrite(D7, 255);
        tone(D7, 3000, 300); // tone on pin 8 at 35000 Hz for 0.1 second
        digitalWrite(D7, 0);
        delay(300);   //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
        digitalWrite(motorPin, HIGH);
        delay (350);
        digitalWrite(motorPin, LOW);
        delay(350);
        Serial.println(" Case 2 ");
        break;





      case 3:
       // Serial.println(" Case 3 ");
        digitalWrite(D7, 255);
        tone(D7, 2000, 200); // tone on pin 8 at 30000 Hz for 0.2 second
        digitalWrite(D7, 0);
        delay(500);    //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
        digitalWrite(motorPin, HIGH);
        delay (250);
        digitalWrite(motorPin, LOW);
        delay(250);
        Serial.println(" Case 3 ");
        break;




      case 4:
       // Serial.println(" Case 4 ");
        digitalWrite(D7, 255);
        tone(D7, 1000, 100); // tone on pin 8 at 25000 Hz for 0.3 second
        digitalWrite(D7, 0);
        delay(700);     //sound buzzer every 0.1 seconds if obstacle distance is between 0-10cm.
        digitalWrite(motorPin, HIGH);
        delay (100);
        digitalWrite(motorPin, LOW);
        delay(100);
        Serial.println(" Case 4 ");
        break;


       case 0:            
              // Serial.println(" Case 0 ");
              digitalWrite(D7, 0); //do not sound the buzzer
               Serial.println(" Case 0 ");
              break;

      default:               
        //Serial.println(" SCdefault! ");
        digitalWrite(D7, 0); //do not sound the buzzer
         Serial.println(" SCdefault! ");
        break;

    }
  }

}

I should of added a brief overview of how it is supposed to work.

This is an electronic eye for my newly blind dog.

The original code:
IMU algorithm detects movement of the Nano33BLE and then reads distance from objects which then turns on a buzzer, vibrator motor to indicate to the dog an object is in his way. This is done within the ‘case’ code.

The new code changes distance sensor from adafruit to piico and adds in a piico light sensor connected toI2C as well as an Adafruit FX board connected o UART.

IMU algorithm detects movement of the Nano33BLE and then reads distance from objects which then turns on a buzzer, vibrator motor and vocal commands to indicate to the dog an object is in his way. This is done within the ‘case’ code. Light sensor turns an LED on and off when dog is moving in the dark so we can see him if he goes outside.

That is as simple as I can explain it

1 Like

Any suggestions to why the example coding in Arduino IDE for the VEML6030 piico light sensor and the VL53L1X piico distance sensor as they won’t compile?
I was told to use these:

Can you post the compile error messages and what you did to install the libraries ??
There are a number of reasons why something might not compile.

I found both libraries in the Arduino IDE, installed them and compiled the examples ok.
Note: I did not use GitHub and I don’t have a VEML6030 or VL53L1X to test it further.

Getting the right library and getting it to work can be quite frustrating with the Arduino IDE. I have used the IDE extensively for many different devices, it could be something simple that is causing it not to work or it could be quite complex.

If I can see the compile messages I might be able to help.

Cheers
Jim

1 Like

Hi Kevin,

I would have a watch of chapter 5’s guide here: https://core-electronics.com.au/tutorials/arduino/arduino-workshop-for-beginners.html
Sam runs through getting an I2C sensor hooked up to the Arduino. Those two libraries are just from a couple well known Maker companies, there are plenty others and will have different function calls and even differing amounts of functionality worked into them.

2 Likes

Let me know if you need anything else.

Would I of been able to use my original code using adafruit VL53L0X with the piico VL53L1X?

Loaded your code and compiled it ok, eventually. Found 2 issues as listed in the error messages.

error one: class and I2C address assignment

#define VL53L1X_sensor 0x29
VL53L1X sensor (VL53L1X_sensor);

change to

#define VL53L1X_sensor 0x29
VL53L1X sensor;

add the I2C address assignment to setup

void setup() {
  sensor.setAddress(VL53L1X_sensor);
  {
    Serial.begin(9600);
    while (!Serial);
    Serial.println("Started");

error two: syntax

  if (luxVal >= 10);
  {digitalWrite(D2, 255);
    delay (1000);}
   else  {digitalWrite(D2, 0);
  }

change to

  if (luxVal >= 10)
  {digitalWrite(D2, 255);
    delay (1000);}
   else  {digitalWrite(D2, 0);
  }

Note: removal of ; at end of if statement

Regards
Jim

3 Likes

Thanks Jim

Its usually something small like this and you can’t see for looking. Always good to have a second set of eyes go over it. I will give that a go and post my results.

2 Likes

HI Jim

I ran the sketch with the adjustments you suggested. All those errors are gone.

However there is a new one for the light sensor:

>  Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
> 
> 
> Cyclops_V1.1:37: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\Cyclops_V1.1.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\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: In function 'void setup()':
> 
> Cyclops_V1.1:106:28: 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\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:3: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);
> 
>           ^~~~~~~~~~~~
> 
> exit status 1
> 
> 'int time' redeclared as different kind of symbol
1 Like

Hi Kevin,

The line int time = 100; redefines a variable that is used by some of the include libraries or Arduino built in libraries. There are quite a few of these variables. This has caught me out a few times too.

Simple fix, change time to time_01 or something that makes sense to you. Also you will need to change everywhere in your code where time is referenced to time_01.

Hopefully that should fix it.
Cheers
Jim

3 Likes

That is awesome, I will do that. Thanks Jim.

Is there a way to open the arduino library files to see the code?

1 Like

That seems to of worked but now it is giving an error for the Arduino Nano 33 BLE and the piico VL53L1X sensor module. Can I use coding for the VL53L0X sensor, as I used that in my original code and it works I only changed when I was referred to use the piico range to bring costs down and to use I2C to simplify wiring.

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.
3 Likes

These errors are in the libraries, not a place I would want to alter.
Usually it means the library has not been debugged enough or is not written correctly or something else.

When this has happened for me I start looking for a better library or one that works.
I would do what you say, go back to a stage that worked. VL53L0X sensor code.

This link explains the error

Regards
Jim

EDIT: Sometimes the libraries may not be valid as zip files or may be out of date.
Suggest using the Arduino Library manager to install libraries, these are kept up to date and usually don’t make it to the list unless they are fully debugged.

I think the VL53L1X library you have used is the Pololu Git Hub link, try the Adafruit one, all Adafruit libraries I have used work nicely. Pololu make excellent stuff, most of the time their libraries are good, I have experienced a couple that were not.

3 Likes

Thanks again Jim your a legend. These small things are sometimes the worst to find without a good understanding/ I am coming from a logic programming background with industrial PLC’s. No libraries just code that is a written logical story. Arduino is fantastic its just going to take me a few more mistakes to learn it better. I am glad I found Core this is a great shop a resource you guys are awesome. Lets see how I go now.

2 Likes

When combining sketches some have different serial bus speeds called on at serial.begin is only one needed for wire or for each module?

2 Likes