Bee Hive Monitoring

hello, I am in the process of building a monitoring system for my bee hives. I currently have a RedBoard qwiic, and the following sensors working together:

SEN-14348 (CCS811/BME280 Combo)

SEN-15892 (Loudness Sensor)

SEN-15242 (NAU7802 Load Sensor)

BOB-14558 (RTC)

I recently added a WRL-13287 (WiFi Shield) and it is breaking my system. The setup locks up after detecting the SEN-14348. If I remove the sensors and add the WRL-13287, I can get it connected to my network. My next troubleshooting step is to add each sensor separately to see if one in particular is conflicting with the WiFi adapter. Any help or advice would be appreciated.

The code that I’m using for the sensors is included.

/******************************************************************************

  Sketch to read from the following sensors for the purpose of monitoring

  bee hives.

  

    SEN-14348 (CCS811/BME280 Combo)

    SEN-15892 (Loudness Sensor)

    WRL-13287 (WiFi Shield)

    SEN-15242 (NAU7802 Load Sensor)



  Pulled from multiple examples found on the internet



  Author:         David Boyd

  File Name:      BeeHive_Master

  Date Created:   24MAY2019

  Date Modified:  27JAN2020

  

******************************************************************************/

#include <Wire.h>

#include <SparkFunBME280.h>

#include <SparkFunCCS811.h>

#include <EEPROM.h> //Needed to record user settings

#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h" // Click here to get the library: [http://librarymanager/All#SparkFun_NAU8702](http://librarymanager/All#SparkFun_NAU8702)





#define COMMAND_LED_OFF               0x00

#define COMMAND_LED_ON                0x01

#define COMMAND_GET_VALUE             0x05

#define COMMAND_NOTHING_NEW           0x99

#define CCS811_ADDR                   0x5B //Default I2C Address

//#define CCS811_ADDR                 0x5A //Alternate I2C Address

#define AVG_SIZE                      4

#define LOCATION_CALIBRATION_FACTOR   0 //Float, requires 4 bytes of EEPROM

#define LOCATION_ZERO_OFFSET          10 //Must be more than 4 away from previous spot. Long, requires 4 bytes of EEPROM





//Global environmental sensor objects

CCS811 myCCS811(CCS811_ADDR);

BME280 myBME280;

NAU7802 myScale; //Create instance of the NAU7802 class



//EEPROM locations to store 4-byte variables for NAU7802 Scale



bool settingsDetected = false; //Used to prompt user to calibrate their scale



// SETTINGS FOR AVERAGING

const int numReadings = 10;    // number of readings for the average

const int sketch_delay = 2000;  // delay between readings

int readings[numReadings];      // the readings from the analog input

int readIndex = 0;              // the index of the current reading

unsigned int ADC_total = 0;     // running total for ADC

unsigned int CO2_total = 0;     // running total for CO2

unsigned int TVOC_total = 0;    // running total for TVOC

unsigned int TEMP_total = 0;    // running total for TEMP

unsigned int H2O_total = 0;     // running total for H2O

unsigned int PRES_total = 0;    // running total for Pressure

unsigned int ALT_total = 0;     // running total for Altitude

unsigned int WGT_total = 0;     // running total for Scale



int ADC_average = 0;            // ADC the average (noise)

int CO2_average = 0;            // CO2 average

int TVOC_average = 0;           // TVOC average

int TEMP_average = 0;           // Temperature average

int H2O_average = 0;            // Humidity average

int PRES_average = 0;           // Barometric pressure average

int ALT_average = 0;            // Altitude average in ft.

int WGT_average = 0;            // Scale average

const byte qwiicAddress = 0x38; //Default Address

uint16_t ADC_VALUE = 0;



void setup() {

  Serial.begin(9600);

  Serial.println();

  Serial.println("Apply BME280 data to CCS811 for compensation.");

  Serial.println("Zio Qwiic Loudness Sensor Master Awake");



  Wire.begin();  //initialize I2C bus

  Wire.setClock(400000); //Qwiic Scale is capable of running at 400kHz if desired

  testForConnectivity();

//  for (int thisReading = 0; thisReading < numReadings; thisReading++) {

//    readings[thisReading] = 0;

//    }

  //Initialize BME280

  //For I2C, enable the following and disable the SPI section

  myBME280.settings.commInterface = I2C_MODE;

  myBME280.settings.I2CAddress = 0x77;

  myBME280.settings.runMode = 3; //Normal mode

  myBME280.settings.tStandby = 0;

  myBME280.settings.filter = 4;

  myBME280.settings.tempOverSample = 5;

  myBME280.settings.pressOverSample = 5;

  myBME280.settings.humidOverSample = 5;



  //Calling .begin() causes the settings to be loaded

  delay(20);  //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.

  byte id = myBME280.begin(); //Returns ID of 0x60 if successful

  if (id != 0x60)

  {

    Serial.println("Problem with BME280");

  }

  else

  {

    Serial.println("BME280 online");

  }

  if (myScale.begin() == false)

  {

    Serial.println("Scale not detected. Please check wiring. Freezing...");

    while (1);

  }

  Serial.println("Scale detected!");

  readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM



  myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate

  myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel 

  Serial.print("Zero offset: ");

  Serial.println(myScale.getZeroOffset());

  Serial.print("Calibration factor: ");

  Serial.println(myScale.getCalibrationFactor()); 

}



void loop() {

  get_value();

  delay(100); 

}





void get_value() {

  // Check EEPROM to verify that the scale is calibrated

  if(settingsDetected == false)

    {

      Serial.print("\tScale not calibrated. Press 'c'.");

    }



  //scale calibration / tare checks

  if (Serial.available())

  {

    byte incoming = Serial.read();

    if (incoming == 't') //Tare the scale

      myScale.calculateZeroOffset();

    else if (incoming == 'c') //Calibrate

    {

      calibrateScale();

    }

  }

  unsigned long currentTime = millis();

  myScale.powerUp();

  Wire.beginTransmission(qwiicAddress);

  Wire.write(COMMAND_GET_VALUE); // command for status

  Wire.endTransmission();    // stop transmitting //this looks like it was essential.

  Wire.requestFrom(qwiicAddress, 2);    // request 1 bytes from slave device qwiicAddress



  while (Wire.available()) { // slave may send less than requested

  uint8_t ADC_VALUE_L = Wire.read(); 

  uint8_t ADC_VALUE_H = Wire.read();



  //lines are needed but I don't know why

  ADC_VALUE=ADC_VALUE_H;

  ADC_VALUE<<=8;

  ADC_VALUE|=ADC_VALUE_L;



  // read various sensors

  ADC_total = ADC_total + ADC_VALUE;

  CO2_total = CO2_total + (myCCS811.getCO2());

  TEMP_total = TEMP_total + (myBME280.readTempF());

  TVOC_total = TVOC_total + (myCCS811.getTVOC());

  PRES_total = PRES_total + (myBME280.readFloatPressure());

  ALT_total = ALT_total + (myBME280.readFloatAltitudeFeet());

  H2O_total = H2O_total + (myBME280.readFloatHumidity());

  WGT_total = WGT_total + myScale.getWeight();

 

  readIndex = readIndex +1;



  // if we're at the end of the array...

  if (readIndex >= numReadings) {

    // calculate the averages:

    ADC_average = ADC_total / numReadings;

    CO2_average = CO2_total / numReadings;

    TEMP_average = TEMP_total / numReadings;

    TVOC_average = TVOC_total / numReadings;

    PRES_average = PRES_total / numReadings;

    ALT_average = ALT_total / numReadings;

    H2O_average = H2O_total  / numReadings;

    WGT_average = WGT_total / numReadings;



    // Print function to print data to serial port

    printData();



    // Reset counters to 0

    readIndex = 0;

    ADC_total = 0;

    CO2_total = 0;

    TEMP_total = 0;

    TVOC_total = 0;

    PRES_total = 0;

    ALT_total = 0;

    H2O_total = 0;

    WGT_total = 0;

  }

  delay(sketch_delay);        // delay in between reads for stability

  }

//  uint16_t x=Wire.read(); 

}



// testForConnectivity() checks for an ACK from an Sensor. If no ACK

// program freezes and notifies user.

void testForConnectivity() {

  Wire.beginTransmission(qwiicAddress);

  //check here for an ACK from the slave, if no ACK don't allow change?

  if (Wire.endTransmission() != 0) {

    Serial.println("Check connections. No slave attached.");

    while (1);

  }

}



void printData()

{

  Serial.print("\t Avg. ADC Value:\t\t");

  Serial.print(ADC_average, DEC);

  Serial.println();



  Serial.print("\t Total ADC Value:\t\t");

  Serial.print(ADC_total, DEC);

  Serial.println();

  Serial.println();

  

  Serial.print("\t Avg. CO2 Value:\t\t");

  Serial.print(CO2_average, DEC);

  Serial.println();



  Serial.print("\t Total CO2 Value:\t\t");

  Serial.print(CO2_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. Temp Value:\t\t");

  Serial.print(TEMP_average, DEC);

  Serial.println();



  Serial.print("\t Total Temp Value:\t\t");

  Serial.print(TEMP_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. TVOC Value:\t\t");

  Serial.print(TVOC_average, DEC);

  Serial.println();



  Serial.print("\t Total TVOC Value:\t\t");

  Serial.print(TVOC_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. Pressure Value:\t\t");

  Serial.print(PRES_average, DEC);

  Serial.println();



  Serial.print("\t Total Pressure Value:\t\t");

  Serial.print(PRES_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. Humidity Value:\t\t");

  Serial.print(H2O_average, DEC);

  Serial.println();



  Serial.print("\t Total Humidity Value:\t\t");

  Serial.print(H2O_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. Altitude Value:\t\t");

  Serial.print(ALT_average, DEC);

  Serial.println();



  Serial.print("\t Total Altitude Value:\t\t");

  Serial.print(ALT_total, DEC);

  Serial.println();

  Serial.println();



  Serial.print("\t Avg. Weight Value:\t\t");

  Serial.print(WGT_average, DEC);

  Serial.println();



  Serial.print("\t Total Weight Value:\t\t");

  Serial.print(WGT_total, 3);

  Serial.println();

  Serial.println();



  Serial.print("\t Number of Readings:\t\t");

  Serial.print(numReadings, DEC);

  Serial.println();



  // output as CSV format for reading by linux box

  Serial.println((String)ADC_average+","+CO2_average+","+TEMP_average+","+TVOC_average+","+PRES_average+","+H2O_average+","+ALT_average+","+WGT_average);

  Serial.println();

  Serial.println();

  

}

void printDriverError( CCS811Core::status errorCode )

{

  switch ( errorCode )

  {

    case CCS811Core::SENSOR_SUCCESS:

      Serial.print("SUCCESS");

      break;

    case CCS811Core::SENSOR_ID_ERROR:

      Serial.print("ID_ERROR");

      break;

    case CCS811Core::SENSOR_I2C_ERROR:

      Serial.print("I2C_ERROR");

      break;

    case CCS811Core::SENSOR_INTERNAL_ERROR:

      Serial.print("INTERNAL_ERROR");

      break;

    case CCS811Core::SENSOR_GENERIC_ERROR:

      Serial.print("GENERIC_ERROR");

      break;

    default:

      Serial.print("Unspecified error.");

  }

}



//Gives user the ability to set a known weight on the scale and calculate a calibration factor

void calibrateScale(void)

{

  Serial.println();

  Serial.println();

  Serial.println(F("Scale calibration"));



  Serial.println(F("Setup scale with no weight on it. Press a key when ready."));

  while (Serial.available()) Serial.read(); //Clear anything in RX buffer

  while (Serial.available() == 0) delay(1000); //Wait for user to press key



  myScale.calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings.

  Serial.print(F("New zero offset: "));

  Serial.println(myScale.getZeroOffset());



  Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));

  while (Serial.available()) Serial.read(); //Clear anything in RX buffer

  while (Serial.available() == 0) delay(1000); //Wait for user to press key



  Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));

  while (Serial.available()) Serial.read(); //Clear anything in RX buffer

  while (Serial.available() == 0) delay(1000); //Wait for user to press key



  //Read user input

  float weightOnScale = Serial.parseFloat();

  Serial.println();



  myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it

  Serial.print(F("New cal factor: "));

  Serial.println(myScale.getCalibrationFactor(), 2);



  Serial.print(F("New Scale Reading: "));

  Serial.println(myScale.getWeight(), 2);



  recordSystemSettings(); //Commit these values to EEPROM

}



void recordSystemSettings(void)

{

  //Get various values from the library and commit them to NVM

  EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());

  EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());

}



//Reads the current system settings from EEPROM

//If anything looks weird, reset setting to default value

void readSystemSettings(void)

{

  float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg

  long settingZeroOffset; //Zero value that is found when scale is tared



  //Look up the calibration factor

  EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);

  if (settingCalibrationFactor == 0xFFFFFFFF)

  {

    settingCalibrationFactor = 0; //Default to 0

    EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);

  }



  //Look up the zero tare point

  EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);

  if (settingZeroOffset == 0xFFFFFFFF)

  {

    settingZeroOffset = 1000L; //Default to 1000 so we don't get inf

    EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);

  }



  //Pass these values to the library

  myScale.setCalibrationFactor(settingCalibrationFactor);

  myScale.setZeroOffset(settingZeroOffset);



  settingsDetected = true; //Assume for the moment that there are good cal values

  if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)

    settingsDetected = false; //Defaults detected. Prompt user to cal scale.

}

Update to the post. None of the sensors work with the WiFi shield. Any help would be appreciated.

hi

can you re-post the code for easy copy. It shows a long list for me while your post does seem to have the right heading

When replying “select full editor & preview”

then copy/paste your code

select the code and use </> from the ribbon

check with preview that is showing as code.

When is it NOT working? what happens exactly and print out?

What happens if you only select ONE sensor?

Does the wireless works without the sensors ?

Did you connect Wireless directly on the Redboard and use SoftSerial?

Is the UART switch set to SW on the wifi board ?

What happens if you do NOT set I2C to 400K but leave it on 100K

Is the power supply strong enough ?

When is it NOT working? what happens exactly and print out? Included a screen shot of the print out. Normally it stops after the BME280 Online statement.

What happens if you only select ONE sensor? I have tried a four sensors individually with the WiFi shield and uploaded example code from the respective sensor’s library with no luck. Same thing happens, the first couple lines of print statements but that is it.

Does the wireless works without the sensors ? Yes, I can see it connected on my router and I can ping the address. I have not made it any further in determining how to communicate with the Arduino via WiFi though.

Did you connect Wireless directly on the Redboard and use SoftSerial? Yes, included a picture of my setup. Not sure about the SoftSerial part of this question.

Is the UART switch set to SW on the wifi board ? Yes, switch is set to SW.

What happens if you do NOT set I2C to 400K but leave it on 100K? Sketch locks up earlier in the process. Include a screenshot.

Is the power supply strong enough ? Good question. I am using it connected via USB. I would have assumed that the the laptop can supply enough for the devices. To that note even though the sketch isn’t responding the WiFi shield did connect to the network. Verififed by disconnecting power to the Arduino while doing a ping and it stops responding when power is disconnected.

/******************************************************************************
  Sketch to read from the following sensors for the purpose of monitoring
  bee hives.
  
    SEN-14348 (CCS811/BME280 Combo)
    SEN-15892 (Loudness Sensor)
    WRL-13287 (WiFi Shield)
    SEN-15242 (NAU7802 Load Sensor)

  Pulled from multiple examples found on the internet

  Author:         David Boyd
  File Name:      BeeHive_Master
  Date Created:   24MAY2019
  Date Modified:  27JAN2020
  
******************************************************************************/
#include <Wire.h>
#include <SparkFunBME280.h>                                 //library for Sparkfun SEN-14348
#include <SparkFunCCS811.h>                                 //library for Sparkfun SEN-14348
#include <EEPROM.h>                                         //Needed to record user settings
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h"   //library for Sparkfun SEN-15242
#include <SparkFun_RV1805.h>                                //library for Sparkfun BOB-14558

#define COMMAND_LED_OFF               0x00
#define COMMAND_LED_ON                0x01
#define COMMAND_GET_VALUE             0x05
#define COMMAND_NOTHING_NEW           0x99
#define CCS811_ADDR                   0x5B //Default I2C Address
//#define CCS811_ADDR                 0x5A //Alternate I2C Address
#define AVG_SIZE                      4
#define LOCATION_CALIBRATION_FACTOR   0 //Float, requires 4 bytes of EEPROM
#define LOCATION_ZERO_OFFSET          10 //Must be more than 4 away from previous spot. Long, requires 4 bytes of EEPROM


//Global environmental sensor objects
CCS811 myCCS811(CCS811_ADDR);     //initialize CCS811
BME280 myBME280;                  //initialize BME280
NAU7802 myScale;                  //initialize NAU7802 class
RV1805 rtc;                       //initialize RV1805 RTC

//EEPROM locations to store 4-byte variables for NAU7802 Scale - Do I still need this?

bool settingsDetected = false; //Used to prompt user to calibrate their scale

// SETTINGS FOR AVERAGING
const int numReadings = 20;    // number of readings for the average
const int sketch_delay = 15000;  // delay between readings
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
unsigned int ADC_total = 0;     // running total for ADC
unsigned int CO2_total = 0;     // running total for CO2
unsigned int TVOC_total = 0;    // running total for TVOC
unsigned int TEMP_total = 0;    // running total for TEMP
unsigned int H2O_total = 0;     // running total for H2O
unsigned int PRES_total = 0;    // running total for Pressure
unsigned int ALT_total = 0;     // running total for Altitude
unsigned int WGT_total = 0;     // running total for Scale

int ADC_average = 0;            // ADC the average (noise)
int CO2_average = 0;            // CO2 average
int TVOC_average = 0;           // TVOC average
int TEMP_average = 0;           // Temperature average
int H2O_average = 0;            // Humidity average
int PRES_average = 0;           // Barometric pressure average
int ALT_average = 0;            // Altitude average in ft.
int WGT_average = 0;            // Scale average
const byte qwiicAddress = 0x38; //Default Address
uint16_t ADC_VALUE = 0;

//The below variables control what the date will be set to
int hund = 50;
int sec = 2;
int minute = 55;
int hour = 20;
int date = 30;
int month = 2;
int year = 2020;
int day = 5;

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("Apply BME280 data to CCS811 for compensation.");
  Serial.println("Zio Qwiic Loudness Sensor Master Awake");

  Wire.begin();  //initialize I2C bus
  Wire.setClock(100000); //Qwiic Scale is capable of running at 400kHz if desired
  testForConnectivity();
//  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
//    readings[thisReading] = 0;
//    }
  //Initialize BME280
  //For I2C, enable the following and disable the SPI section
  myBME280.settings.commInterface = I2C_MODE;
  myBME280.settings.I2CAddress = 0x77;
  myBME280.settings.runMode = 3; //Normal mode
  myBME280.settings.tStandby = 0;
  myBME280.settings.filter = 4;
  myBME280.settings.tempOverSample = 5;
  myBME280.settings.pressOverSample = 5;
  myBME280.settings.humidOverSample = 5;

  //Calling .begin() causes the settings to be loaded
  delay(20);  //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
  byte id = myBME280.begin(); //Returns ID of 0x60 if successful
  if (id != 0x60)
  {
    Serial.println("Problem with BME280");
  }
  else
  {
    Serial.println("BME280 online");
  }
  if (myScale.begin() == false)
  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    while (1);
  }
  Serial.println("Scale detected!");
  readSystemSettings(); //Load zeroOffset and calibrationFactor from EEPROM

  myScale.setSampleRate(NAU7802_SPS_320); //Increase to max sample rate
  myScale.calibrateAFE(); //Re-cal analog front end when we change gain, sample rate, or channel 
  Serial.print("Zero offset: ");
  Serial.println(myScale.getZeroOffset());
  Serial.print("Calibration factor: ");
  Serial.println(myScale.getCalibrationFactor());

    Serial.println("Read Time from RTC Example");

  if (rtc.begin() == false) {
    Serial.println("Something went wrong, check wiring");
  }

  //Use the time from the Arduino compiler (build time) to set the RTC
  //Keep in mind that Arduino does not get the new compiler time every time it compiles. to ensure the proper time is loaded, open up a fresh version of the IDE and load the sketch.
  if (rtc.setToCompilerTime() == false) {
    Serial.println("Something went wrong setting the time");
  }

  //Uncomment the below code to set the RTC to your own time
  if (rtc.setTime(hund, sec, minute, hour, date, month, year, day) == false) {
//  if (rtc.setTime(00, 00, 31, 21, date, month, year, day) == false) {
    Serial.println("Something went wrong setting the time");
  }

  Serial.println("RTC online!");

  //end setup
}

void loop() {
  get_value();
  delay(100); 
}


void get_value() {
  // Check EEPROM to verify that the scale is calibrated
  if(settingsDetected == false)
    {
      Serial.print("\tScale not calibrated. Press 'c'.");
    }

  //scale calibration / tare checks
  if (Serial.available())
  {
    byte incoming = Serial.read();
    if (incoming == 't') //Tare the scale
      myScale.calculateZeroOffset();
    else if (incoming == 'c') //Calibrate
    {
      calibrateScale();
    }
  }
  unsigned long currentTime = millis();
  myScale.powerUp();
  Wire.beginTransmission(qwiicAddress);
  Wire.write(COMMAND_GET_VALUE); // command for status
  Wire.endTransmission();    // stop transmitting //this looks like it was essential.
  Wire.requestFrom(qwiicAddress, 2);    // request 1 bytes from slave device qwiicAddress

  while (Wire.available()) { // slave may send less than requested
  uint8_t ADC_VALUE_L = Wire.read(); 
  uint8_t ADC_VALUE_H = Wire.read();

  //lines are needed but I don't know why
  ADC_VALUE=ADC_VALUE_H;
  ADC_VALUE<<=8;
  ADC_VALUE|=ADC_VALUE_L;

  // read various sensors
  ADC_total = ADC_total + ADC_VALUE;
  CO2_total = CO2_total + (myCCS811.getCO2());
  TEMP_total = TEMP_total + (myBME280.readTempF());
  TVOC_total = TVOC_total + (myCCS811.getTVOC());
  PRES_total = PRES_total + (myBME280.readFloatPressure());
  ALT_total = ALT_total + (myBME280.readFloatAltitudeFeet());
  H2O_total = H2O_total + (myBME280.readFloatHumidity());
  WGT_total = WGT_total + myScale.getWeight();
 
  readIndex = readIndex +1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // calculate the averages:
    ADC_average = ADC_total / numReadings;
    CO2_average = CO2_total / numReadings;
    TEMP_average = TEMP_total / numReadings;
    TVOC_average = TVOC_total / numReadings;
    PRES_average = PRES_total / numReadings;
    ALT_average = ALT_total / numReadings;
    H2O_average = H2O_total  / numReadings;
    WGT_average = WGT_total / numReadings;

    // Print function to print data to serial port
    printData();

    // Reset counters to 0
    readIndex = 0;
    ADC_total = 0;
    CO2_total = 0;
    TEMP_total = 0;
    TVOC_total = 0;
    PRES_total = 0;
    ALT_total = 0;
    H2O_total = 0;
    WGT_total = 0;
  }
  delay(sketch_delay);        // delay in between reads for stability
  }
//  uint16_t x=Wire.read(); 
}

// testForConnectivity() checks for an ACK from an Sensor. If no ACK
// program freezes and notifies user.
void testForConnectivity() {
  Wire.beginTransmission(qwiicAddress);
  //check here for an ACK from the slave, if no ACK don't allow change?
  if (Wire.endTransmission() != 0) {
    Serial.println("Check connections. No slave attached.");
    while (1);
  }
}

void printData()
{
 /*
  Serial.print("\t Avg. ADC Value:\t\t");
  Serial.print(ADC_average, DEC);
  Serial.println();

  Serial.print("\t Total ADC Value:\t\t");
  Serial.print(ADC_total, DEC);
  Serial.println();
  Serial.println();
  
  Serial.print("\t Avg. CO2 Value:\t\t");
  Serial.print(CO2_average, DEC);
  Serial.println();

  Serial.print("\t Total CO2 Value:\t\t");
  Serial.print(CO2_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. Temp Value:\t\t");
  Serial.print(TEMP_average, DEC);
  Serial.println();

  Serial.print("\t Total Temp Value:\t\t");
  Serial.print(TEMP_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. TVOC Value:\t\t");
  Serial.print(TVOC_average, DEC);
  Serial.println();

  Serial.print("\t Total TVOC Value:\t\t");
  Serial.print(TVOC_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. Pressure Value:\t\t");
  Serial.print(PRES_average, DEC);
  Serial.println();

  Serial.print("\t Total Pressure Value:\t\t");
  Serial.print(PRES_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. Humidity Value:\t\t");
  Serial.print(H2O_average, DEC);
  Serial.println();

  Serial.print("\t Total Humidity Value:\t\t");
  Serial.print(H2O_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. Altitude Value:\t\t");
  Serial.print(ALT_average, DEC);
  Serial.println();

  Serial.print("\t Total Altitude Value:\t\t");
  Serial.print(ALT_total, DEC);
  Serial.println();
  Serial.println();

  Serial.print("\t Avg. Weight Value:\t\t");
  Serial.print(WGT_average, DEC);
  Serial.println();

  Serial.print("\t Total Weight Value:\t\t");
  Serial.print(WGT_total, 3);
  Serial.println();
  Serial.println();

  Serial.print("\t Number of Readings:\t\t");
  Serial.print(numReadings, DEC);
  Serial.println();
  */

if (rtc.updateTime() == false) //Updates the time variables from RTC
  {
    Serial.print("RTC failed to update");
  }
  
  String currentTime = rtc.stringTime();
  String currentDate = rtc.stringDate();
//  Serial.print(currentDate);
//  Serial.print("  ");
//  Serial.println(currentTime);
  
  // output as CSV format for reading by linux box
  Serial.println(currentDate+" "+currentTime+", "+(String)ADC_average+","+CO2_average+","+TEMP_average+","+TVOC_average+","+PRES_average+","+H2O_average+","+ALT_average+","+WGT_average);
//  Serial.println();
//  Serial.println();
  
}
void printDriverError( CCS811Core::status errorCode )
{
  switch ( errorCode )
  {
    case CCS811Core::SENSOR_SUCCESS:
      Serial.print("SUCCESS");
      break;
    case CCS811Core::SENSOR_ID_ERROR:
      Serial.print("ID_ERROR");
      break;
    case CCS811Core::SENSOR_I2C_ERROR:
      Serial.print("I2C_ERROR");
      break;
    case CCS811Core::SENSOR_INTERNAL_ERROR:
      Serial.print("INTERNAL_ERROR");
      break;
    case CCS811Core::SENSOR_GENERIC_ERROR:
      Serial.print("GENERIC_ERROR");
      break;
    default:
      Serial.print("Unspecified error.");
  }
}

//Gives user the ability to set a known weight on the scale and calculate a calibration factor
void calibrateScale(void)
{
  Serial.println();
  Serial.println();
  Serial.println(F("Scale calibration"));

  Serial.println(F("Setup scale with no weight on it. Press a key when ready."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(1000); //Wait for user to press key

  myScale.calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings.
  Serial.print(F("New zero offset: "));
  Serial.println(myScale.getZeroOffset());

  Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable."));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(1000); //Wait for user to press key

  Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): "));
  while (Serial.available()) Serial.read(); //Clear anything in RX buffer
  while (Serial.available() == 0) delay(1000); //Wait for user to press key

  //Read user input
  float weightOnScale = Serial.parseFloat();
  Serial.println();

  myScale.calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it
  Serial.print(F("New cal factor: "));
  Serial.println(myScale.getCalibrationFactor(), 2);

  Serial.print(F("New Scale Reading: "));
  Serial.println(myScale.getWeight(), 2);

  recordSystemSettings(); //Commit these values to EEPROM
}

void recordSystemSettings(void)
{
  //Get various values from the library and commit them to NVM
  EEPROM.put(LOCATION_CALIBRATION_FACTOR, myScale.getCalibrationFactor());
  EEPROM.put(LOCATION_ZERO_OFFSET, myScale.getZeroOffset());
}

//Reads the current system settings from EEPROM
//If anything looks weird, reset setting to default value
void readSystemSettings(void)
{
  float settingCalibrationFactor; //Value used to convert the load cell reading to lbs or kg
  long settingZeroOffset; //Zero value that is found when scale is tared

  //Look up the calibration factor
  EEPROM.get(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  if (settingCalibrationFactor == 0xFFFFFFFF)
  {
    settingCalibrationFactor = 0; //Default to 0
    EEPROM.put(LOCATION_CALIBRATION_FACTOR, settingCalibrationFactor);
  }

  //Look up the zero tare point
  EEPROM.get(LOCATION_ZERO_OFFSET, settingZeroOffset);
  if (settingZeroOffset == 0xFFFFFFFF)
  {
    settingZeroOffset = 1000L; //Default to 1000 so we don't get inf
    EEPROM.put(LOCATION_ZERO_OFFSET, settingZeroOffset);
  }

  //Pass these values to the library
  myScale.setCalibrationFactor(settingCalibrationFactor);
  myScale.setZeroOffset(settingZeroOffset);

  settingsDetected = true; //Assume for the moment that there are good cal values
  if (settingCalibrationFactor < 0.1 || settingZeroOffset == 1000)
    settingsDetected = false; //Defaults detected. Prompt user to cal scale.
}

do you have the sketch with your WIFI included ?

One more : when you compile the code with WIFI, how much memory is used ??

@paulvha - For your first question, the sketch that I posted is all that I have. Because the devices locks up I haven’t gotten to testing anything with the WiFi shield.

For your second question, after compiling it says, “Sketch uses 20006 bytes (62%) of program storage space. Maximum is 32256 bytes. Global variables use 1081 bytes (52%) of dynamic memory, leaving 967 bytes for local variables. Maximum is 2048 bytes”

@paulvha - One other thing, the system is be left running all day while I was doing other things and it appears that it is trying to do something but I’m not sure what. I’ve included a screen shot of my terminal session to the Arduino.

Arduino_Attempts.PNG

I would go back to basics. Take example 1 of BME280, just ONLY connect the BME280 and perform basic reading. If that works now add the WIFI-shield. No need for the code and see what happens. I have just tried that for me and the BME280 output continued

The WIFI shield is only using pin 8 and 9 as well as the power. It could easily be power. When I connect the shield on an Arduino, the power led should go on and the blue led flashing. Else there is no change to get connection with the board. Only taking power from the USB I sometime have to remove and reconnect the USB.

I have made combination of the ping-test of the ESP8266 and the BME280. output look like :

13:08:47.726 -> connecting to ESP8266.
13:08:51.905 -> Connect to ESP8266, tyring to connect to network :homelan
13:08:52.934 -> Pinging google.com
13:08:52.967 -> Reading basic values from BME280
13:08:53.962 -> 15
13:08:53.962 -> Humidity: 43 Pressure: 97730 Alt: 994.9 Temp: 72.30
13:08:55.952 -> 10
13:08:55.952 -> Humidity: 44 Pressure: 101444 Alt: -32.4 Temp: 72.37
13:08:57.976 -> 14
13:08:57.976 -> Humidity: 44 Pressure: 101442 Alt: -32.0 Temp: 72.39
13:08:59.999 -> 13
13:09:00.032 -> Humidity: 44 Pressure: 101448 Alt: -33.4 Temp: 72.39
13:09:02.056 -> 83
13:09:02.056 -> Humidity: 43 Pressure: 101445 Alt: -32.7 Temp: 72.41
13:09:04.079 -> 10
13:09:04.079 -> Humidity: 43 Pressure: 101448 Alt: -33.7 Temp: 72.43
13:09:06.102 -> 10
13:09:06.102 -> Humidity: 43 Pressure: 101450 Alt: -34.1 Temp: 72.43
13:09:08.125 -> 10
13:09:08.125 -> Humidity: 44 Pressure: 101451 Alt: -34.4 Temp: 72.45
13:09:10.148 -> 10
13:09:10.148 -> Humidity: 44 Pressure: 101449 Alt: -33.9 Temp: 72.46
13:09:12.172 -> 21
13:09:12.172 -> Humidity: 44 Pressure: 101446 Alt: -33.1 Temp: 72.45

BUT I have difficulty uploading as an txt-attachment I get HTTP errors. As code or quote it is forbidden 403), while it is very small. I will try later…

Paul, thank you for your suggestion but I have tried that with each of the four sensors and each time I get no results back from the particular sensor. I was just using the example code from each library and without the WiFi shield they work as expected. As soon as I plug in the WiFi shield it interrupts the sensors. I will give it another go though.

On a side note, do you know if it is possible to go back and edit previous posts? I would love to get rid of the long code listing from the beginning .

David

using the ESP8266_Ping_Test code from the examples I was able to ping google.com successfully. If the SEN-14348 is connected this sketch fails to upload with the error avrdud: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00. Using a combined code for the ESP8266 & the SEN-14348 results in a like error. If I remove the ESP8266 then the sketch loads but I only get “Reading basic values from BME280” repeatedly. Which is interesting because that is in the setup and not in a loop. Which would tell me the Arduino is restarting repeatedly.

It looks to me this is caused by hardware. Check the bottom-side of ESP8266 is not hitting the Redboard. Else I suspect either the power supply is to weak or maybe even the switch on the ESP8266.

For the power supply: some PC’s allow USB port power settings. (in windows device manage or BIOS setup). Maybe also try different USB cable. Try different USB port (if any) and a USB3 port allows for higher power than USB1 and USB2. Else maybe try to connect an extra power supply to extra connector.

For the UART switch suspicion , bend pin 0 (HW-TX) and 1 (HW-RX) out a bit so they do not connect to the Redboard. (personally I have cut off those 2). I suspect it is unlikely, but I have experienced even stranger things happening.

I will verify how the ESP8266 is sitting when I get home. If I plug the Arudino into a battery pack that I know can supply it with power, will I be able to connect via Putty to the IP address and still get the println() statements? I believe I have an external power also so I can try that.

After checking the the ESP8266 placement one side was in contact with the 6-pin header to the side of the qwiic connector and the other side was pressed against the barrel connector. It doesn’t seem as though that would have had much bearing on the performance as there is metal surface near the header and the barrel connector is plastic. I plugged the Arduino into a USB 3 port and it showed a little more promise. With just the ESP8266 and the SEN-14348 I was able to get some reading from the sensor. The only problem was that it was very intermittent and the Arduino restarted often. I then bent pins 0 & 1 out of the way and had my best success but nothing that I would call stable. With all four sensors connected and the ESP8266 installed I was able to get past all of the startup statement and it appeared as though it was pulling data but before it made it through the loop and print the averages the Arduino would restart. I have ordered a 5v 4W power supply from SparkFun and it should be here by the end of the week. Hopefully that will move me in the right direction.

Thank you for your help and suggestions.

David

I received my external power supply yesterday afternoon and anxiously ran up to my office to get my system up and running. Plug in the power supply and the USB cable, load up the serial monitor and BAM! Nothing. Damn thing still locks up. So two questions; 1) should I try re-soldering the headers on the ESP8266 2) should I order a new shield?

It is weird and disappointing. I have tried on my arduino R3 and have no problem.

Do you have a voltmeter? if so can you check the 5V on the ESP8266?

Instead of connecting the board directly on the Redboard, can you try to connect with loose wire. GND, 5 VCC first to see what happens ? if that works later add pin 8 and pin 9?

Some how I am still not able to add an attachment or include the test code that i have written. I will drop you a PM and will try to include there.

Paul, it took me a while to find my multimeter but it appears that the 5v line is low at 4.05v. Taking your advice though I removed the shield and hardwired GND, 5v, 8 & 9 and things are looking good. I can load the SEN-14348 (CCS811/BME280 Combo), SEN-15242 (NAU7802 Load Sensor) and the BOB-14558 (RTC) sensor along with the WiFi shield and it complains about memory but runs the basic script. If I try to add the SEN-15892 (Loudness Sensor) to the mix I hit 83% utilization and everything crashes.

So, is there a way to optimize the code to reduce its footprint or is there another board with more memory that would be better suited for this project. I do have an Particle Argon that I could look into.

Thanks again for your support.

David

first things first… good progress !

Hardware: the fact that it runs when you connect loose wires, gives me the impression that there is a short circuit around any of the pins on the wireless shield. Double, triple check the soldering around the pins. You can also check with a ohm measurement on the multi meter. If you set the switch to SW UART, NONE of the pins except for 5V, GND , reset and pin 8 and pin 9 should have a low resistance.

Software : If you are running low on memory and as the program is executed it can crash. 32KB is full quickly There are other board, like a MEGA2560 that have more memory, BUT the are not pin-compatible ( e.g. you can place the Wifi shield on the Mega… but it will not work with pin 8 and 9 as they do not support PCINT ) I don’t know if the Redboard Artemis does, never tried. If you connect with loose wire however these, and many other boards, could be options.

If you have a Particle Argon, is has 1MB flash and has already WIFI onboard as it has an ESP32. No need for a separate WIFI board

Thank you. I’ll check the board with my multimeter again to test resistance and see what is happening. I was also playing with the Argon last night and researching to see if I can get my QWIIC sensors connected. From what I found on the web it appears that I can but it was too late to really dig into it. That’ll be for this weekend since our weather isn’t conducive to being outdoors.

David

Paul, I’ve given up on the Ethernet shield and instead have gone with a Pi to connect to my computer and network. The Pi reads the output from the Arduino and then populates a database. I appreciate all the advice but I’m running out of time and didn’t want to waste it going down that road.