Program not printing

Hello everyone, once again requesting assistance from the comunity.

I managed to put a few libraries together, the code is complete, and it does compile, however the loop stops at the VL6180X TOF sensor.
I will appreciate any help figuring out what is wrong with the code.

The program works when I run it alone.

This is the main code:

#include <Adafruit_MLX90614.h>
#include <DistanceSensor.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_VL6180X.h"
#include <Wire.h>
#include <Adafruit_AMG88xx.h>

// Define pins
const int echoPin = 12;
const int trigPin = 13;
const int buzzer = 9;  //buzzer to arduino pin 9
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
DistanceSensor sensor(trigPin, echoPin);
Adafruit_VL6180X vl = Adafruit_VL6180X();
Adafruit_AMG88xx amg;

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(buzzer, OUTPUT);  // Set buzzer - pin 9 as an output

  if (!mlx.begin()) {
    while (1)
      ;

    Serial.println("Adafruit VL6180x test!");
    if (!vl.begin()) {
      Serial.println("Failed to find sensor");
      while (1)
        ;
    }
    Serial.println("Sensor found!");
    ;
  };

/***************************************************************
 TOF continuous mode to take range measurements with the VL6180X.
The range readings are in units of mm. 
 ***************************************************************/
  bool status;

  // default settings
  status = amg.begin();
}
void loop() {
/***********************************************************
  This is a library example for the MLX90614 Temp Sensor
 ***************************************************************/
  int ambient0 = 32;
  int ambient1 = mlx.readAmbientTempF();
  int delta_ambient = ambient1 - ambient0;

  if (delta_ambient > 0) {
    delay(1000);

 /***************************************************************
 Ultra Sonic HC-SR04 sensor and prints it to the serial port.
 Get distance in cm
 ***************************************************************/
    int distance0 = 14;
    int distance1 = sensor.getCM();
    int delta_distance = distance0 - distance1;

    if (delta_distance > .3) {

/***************************************************************
 TOF continuous mode to take range measurements with the VL6180X.
The range readings are in units of mm. 
 ***************************************************************/
      float lux = vl.readLux(VL6180X_ALS_GAIN_5);

      uint8_t range1 = vl.readRange();
      float range0 = 1;
      float deltarange = range0 - range1;

      uint8_t status = vl.readRangeStatus();

      if (status == VL6180X_ERROR_NONE) {
        if (deltarange <= 3) {
          Serial.println("ICE ");
          Serial.println(range1);

          delay(100);

/***************************************************************
 AMG88xx GridEYE 8x8 IR camera.
 Celsius Degrees
 ***************************************************************/
         //read all the pixels
          amg.readPixels(pixels);


          for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
             if (pixels[i - 1] <= 0) {

              //delay a second
              delay(1000);

/***************************************************************
 Photocell
 ***************************************************************/
              int photo0 = 1;
              int photo1 = analogRead(A0);
              int delta_photo = photo1 - photo0;
              Serial.println(analogRead(A0));

              if (delta_photo >= 5) {
                Serial.println("***ICE***ICE***");
                delay(1000);

/***************************************************************
 BUZZER
 ***************************************************************/
                tone(buzzer, 10);  // Send 1KHz sound signal...
                delay(1000);       // ...for 1 sec
              }
              ///PHOTOCELL
              else {
                Serial.println("WARM CHANGO");
                delay(1000);
              }
            }
          }
        }
      }
    }
  }
}

This is the code by itself

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_VL6180X.h"

Adafruit_VL6180X vl = Adafruit_VL6180X();

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

  Serial.println("Adafruit VL6180x test!");
  if (!vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1)
      ;
  }
  Serial.println("Sensor found!");
}

void loop() {
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  uint8_t range1 = vl.readRange();
  float range0 = 117;
  float deltarange = range0 - range1;

  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {
    if (deltarange <= 3) {
      Serial.println("ICE ");
      Serial.println(range1);
      //Serial.println(deltarange);
      Serial.println();
      delay(100);

    } else Serial.println("NO ICE ");
    Serial.println(range1);
    delay(100);
    return;
  }
}

At the instanciation or the call to use?

It stops after this line.

float lux = vl.readLux(VL6180X_ALS_GAIN_5);

I print text after each block to check that the logic is working.

As you can see, I'm using a bunch of nested ifs.
Basically when all the conditions are met the buzzes goes off.

Maybe something is sending the sketch back to the "readLux" function, which has some 100ms delays to add to your code's 3000ms delay. Follow your parameters into the CPP.

float Adafruit_VL6180X::readLux(uint8_t gain) {
  uint8_t reg;

  reg = read8(VL6180X_REG_SYSTEM_INTERRUPT_CONFIG);
  reg &= ~0x38;
  reg |= (0x4 << 3); // IRQ on ALS ready
  write8(VL6180X_REG_SYSTEM_INTERRUPT_CONFIG, reg);

  // 100 ms integration period
  write8(VL6180X_REG_SYSALS_INTEGRATION_PERIOD_HI, 0);
  write8(VL6180X_REG_SYSALS_INTEGRATION_PERIOD_LO, 100);

  // analog gain
  if (gain > VL6180X_ALS_GAIN_40) {
    gain = VL6180X_ALS_GAIN_40;
  }
  write8(VL6180X_REG_SYSALS_ANALOGUE_GAIN, 0x40 | gain);

  // start ALS
  write8(VL6180X_REG_SYSALS_START, 0x1);

  // Poll until "New Sample Ready threshold event" is set
  while (4 != ((read8(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO) >> 3) & 0x7))
    ;

  // read lux!
  float lux = read16(VL6180X_REG_RESULT_ALS_VAL);

  // clear interrupt
  write8(VL6180X_REG_SYSTEM_INTERRUPT_CLEAR, 0x07);

  lux *= 0.32; // calibrated count/lux
  switch (gain) {
  case VL6180X_ALS_GAIN_1:
    break;
  case VL6180X_ALS_GAIN_1_25:
    lux /= 1.25;
    break;
  case VL6180X_ALS_GAIN_1_67:
    lux /= 1.67;
    break;
  case VL6180X_ALS_GAIN_2_5:
    lux /= 2.5;
    break;
  case VL6180X_ALS_GAIN_5:
    lux /= 5;
    break;
  case VL6180X_ALS_GAIN_10:
    lux /= 10;
    break;
  case VL6180X_ALS_GAIN_20:
    lux /= 20;
    break;
  case VL6180X_ALS_GAIN_40:
    lux /= 40;
    break;
  }
  lux *= 100;
  lux /= 100; // integration time in ms

  return lux;
}

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