Hey All,
Running a script that is supposed to detect what I2C sensors are/are not connected. Then, after finding all of the ones on the board, it should go into the body code to gather data.
However, the for loop just keeps repeating. It goes back up to the serial print statement of Senior design code.
edit. The body code works if I replace the for loop with the individual begin statements that are commented out.
Thanks,
#include <Wire.h>
#include "Adafruit_MCP9808.h"
#include "Adafruit_MPL115A2.h"
#include "Adafruit_Si7021.h"
#include "Adafruit_VCNL4010.h"
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808(); // Address defauts to 0x18
//Adafruit_MCP9808 tempsensor2 = Adafruit_MCP9808(); // Second object created for second object
Adafruit_MPL115A2 mpl115a2 = Adafruit_MPL115A2(); // Object Created for Barometric Pressure
Adafruit_Si7021 si7021 = Adafruit_Si7021(); // Object Created for Humidity Sensor
Adafruit_VCNL4010 vcnl; // Object Created for Proximity Sensor
// FOR ANY COMMANDS DEALING WITH SENSOR 2, tempsensor2 must replace tempsensor for operations.
// FOR EXAMPLE - tempsensor.readTempC() READS CELSIUS TEMPERATURE OF SENSOR 1
// FOR EXAMPLE - tempsensor2.readTempF() READS FARHENHEIGHT TEMPERATURE OF SENSOR 2
// Si7021 - Temperature and Humidity sensor: Address - 0x40
// MPL115A2 - Barometric Pressure/Temperature Sensor: Address - 0x60
// VCNL4010 - Proximity Sensor: Address - 0x13
byte address;
void setup() {
Serial.begin(9600);
while (!Serial);
//Waits for Serial Terminal to be Open Prior to Running Script
Serial.println("Senior Design / ESP32 Module Code");
delay(500);
Serial.println("Finding attached sensors now..");
delay(500);
// Make sure the correct sensors are found using the I2C addresses
for(address = 0; address < 127; address++)
{
// if (address == 0x10) Serial.print("UV sensor found, but more code needed to run in current project state.");
delay(5);
if (address == 0x13){ Serial.println("Found VCNL4010 Proximity Sensor / Address (0x13)");
delay(5);
}
if (address == 0x18){ Serial.println("Found MCP9808 / Address (0x18)");
delay(5);
}
// if (address == 0x19) Serial.println("Found LSM303 Accelerometer / Address (0x19). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x20) Serial.println("Found Chirp! Water Sensor / Address (0x20). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x28) Serial.println("Found PCT2075 Temperature Sensor / Address (0x28). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x29) Serial.println("Found TSL2591 Light Sensor / Address (0x29). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x1E) Serial.println("Found 9DOF / Address (0x1E). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x31) Serial.println("Found CAP1188 8 Channel Capacitive Touch Sensor / Address (0x31). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x33) Serial.println("Found MLX90640 IR Thermal Camera / Address (0x33). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x38) Serial.println("Found VEML6070 UV Index / Address (0x38). More Code/Library is Required to run this Sensor.");
delay(5);
// if (address == 0x39) Serial.println("Found APDS-9960 IR/Color/Proximity Sensor / Address (0x39). More Code/Library is Required to run this Sensor.");
delay(5);
if (address == 0x40){ Serial.println("Found Si7021 Humidity/Temp Sensor / Address (0x40)");
delay(5);
}
if (address == 0x60) Serial.println("Found MPL115A2 Barometric Pressure/Temperature Sensor / Address (0x60)");
delay(5);
// if (address == 0x6B) Serial.println("Found 9DOF / Address (0x6B). More Code/Library is Required to run this Sensor.");
delay(5);
}
/*
if (!tempsensor.begin(0x18)) { // 0x19 is address when VCC is connected to A0.
Serial.println("Couldn't find MCP9808!");
while (1);
}
Serial.println("Found MCP9808 / Address (0x18)");
delay(2000);
Serial.print("\n");
mpl115a2.begin();
Serial.println("Found MPL115A2 / Address (0x60)");
delay(2000);
Serial.print("\n");
if (!si7021.begin()) {
Serial.println("Couldn't find Humidity (Si7021) Sensor!");
while (1);
}
Serial.println("Found Si7021 / Address (0x40)");
Serial.print("\n");
delay(2000);
if (!vcnl.begin()) {
Serial.println("Couldn't find Proximity (VCNL4010) Sensor!");
while (1);
}
Serial.println("Found VCNL4010 / Address (0x13)");
delay(2000);
*/
}
void loop() {
// Start Code for Temperature Sensor MCP9808
tempsensor.setResolution(1); // sets the resolution mode of reading, int number defines accuracy
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
// 2 0.125°C 130 ms
// 3 0.0625°C 250 ms
Serial.println("Wake up Device MCP9808 ");
tempsensor.wake(); // WAKES THE DEVICE UP FROM STANDBY MODE (power consumption ~200 uA)
Serial.print("\n");
delay(500);
float c = tempsensor.readTempC();
float f = tempsensor.readTempF();
Serial.print("Temperature Inside Module: ");
Serial.print(c, 4); Serial.print("*C\t and ");
Serial.print(f, 4); Serial.println("*F.");
delay(2000);
Serial.print("\n");
Serial.println("Shutdown MCP9808 for Power Consumption ");
Serial.print("\n");
tempsensor.shutdown_wake(1); // PUTS THE DEVICE INTO STANDBY MODE (power consumption ~4 uA)
delay(1000);
// Start Code for Barometric Sensor MPL115A2
Serial.println("Reading Device MPL115A2 ");
Serial.print("\n");
delay(500);
float pressureKPA = 0, temperatureC = 0;
pressureKPA = mpl115a2.getPressure();
Serial.print("Pressure (kPa): "); Serial.print(pressureKPA, 4); Serial.println(" kPa");
delay(2000);
//Optional Command to get temperature as well
//temperatureC = mpl115a2.getTemperature();
//Serial.print("Temp (*C): "); Serial.print(temperatureC, 1); Serial.println(" *C");
Serial.print("\n");
// Start Code for Humidity (Si7021) Sensor
Serial.println("Reading Device Si7021 ");
Serial.print("\n");
delay(500);
Serial.print("Humidity: ");
Serial.print("\n");
Serial.print(si7021.readHumidity(), 2);
delay(2000);
Serial.print("\n");
//Optional Read Temperature Again
//Serial.print("\tTemperature: ");
//Serial.println(si7021.readTemperature(), 2);
//Start Code for Proximity (VCNL4010) Sensor
Serial.println("Reading Device VCNL4010 ");
Serial.print("\n");
delay(500);
Serial.print("Ambient: "); Serial.println(vcnl.readAmbient());
Serial.print("Proximity: "); Serial.println(vcnl.readProximity());
delay(2000);
Serial.print("\n");
}