Skip to content

Commit

Permalink
adding tests for various components
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriaclarke committed Jul 25, 2020
1 parent 7b5d85d commit 6544bb2
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
Binary file added testing/.DS_Store
Binary file not shown.
123 changes: 123 additions & 0 deletions testing/bme680Test/bme680Test.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/***************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/3660
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme0; // I2C
Adafruit_BME680 bme1; // I2C

void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println(F("BME680 test"));

// SENSOR 0 - 0X77
if (!bme0.begin(0x77, true)) ///< The default I2C address
{
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}

// Set up oversampling and filter initialization
bme0.setTemperatureOversampling(BME680_OS_8X);
bme0.setHumidityOversampling(BME680_OS_2X);
bme0.setPressureOversampling(BME680_OS_4X);
bme0.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme0.setGasHeater(320, 150); // 320*C for 150 ms


// SENSOR 1 - 0X76
if (!bme1.begin(0x76, true)) ///< The default I2C address
{
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}

// Set up oversampling and filter initialization
bme1.setTemperatureOversampling(BME680_OS_8X);
bme1.setHumidityOversampling(BME680_OS_2X);
bme1.setPressureOversampling(BME680_OS_4X);
bme1.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme1.setGasHeater(320, 150); // 320*C for 150 ms
}

void loop()
{
if (! bme0.performReading())
{
Serial.println("Failed to perform reading :(");
return;
}

Serial.print("pressure 0: ");
Serial.print(bme0.pressure / 100.0);
Serial.println(" hPa");
Serial.print(0.5 + (bme0.pressure / (98.0665 / 10)));
Serial.println();
Serial.print("temperature 0:");
Serial.print(bme0.temperature);
Serial.println(" *C");
Serial.print("humidity 0: ");
Serial.print(bme0.humidity);
Serial.println(" %");
Serial.print("approx. altitude 0:");
Serial.print(bme0.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("voc 0: ");
Serial.print(bme0.gas_resistance / 1000.0);
Serial.println(" KOhms");
Serial.println();

delay(2000);


if (! bme1.performReading())
{
Serial.println("Failed to perform reading :(");
return;
}

Serial.print("pressure 1: ");
Serial.print(bme1.pressure / 100.0);
Serial.println(" hPa");
Serial.print(0.5 + (bme1.pressure / (98.0665 / 10)));
Serial.println();
Serial.print("temperature 1:");
Serial.print(bme1.temperature);
Serial.println(" *C");
Serial.print("humidity 1: ");
Serial.print(bme1.humidity);
Serial.println(" %");
Serial.print("approx. altitude 1:");
Serial.print(bme1.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("voc 1: ");
Serial.print(bme1.gas_resistance / 1000.0);
Serial.println(" KOhms");
Serial.println();

Serial.println();


delay(2000);
}
123 changes: 123 additions & 0 deletions testing/oxygenTest/oxygenTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <Wire.h>
#include <Adafruit_ADS1015.h>

#define AVG_WINDOW 20

// channel the O2 sensor os connected to
#define O2CHANNEL 3

// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV

Adafruit_ADS1115 ads; /* Use this for the 16-bit version */

int initialO2;

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

ads.setGain(GAIN_SIXTEEN);

ads.begin();

initialO2 = avgADC(O2CHANNEL);
if(initialO2 <= 100 && initialO2 >= -100)
{
Serial.println("Oxygen Sensor is not installed. Proceeding without oxygen sensing.");
}

Serial.println(initialO2);
}

void loop(void)
{
double voltage = avgADC(O2CHANNEL);

float voltagemV = voltage * 0.0078125;

float o2 = (voltage / initialO2) * 20.9;

Serial.print("\ninital: ");
Serial.println(initialO2);
Serial.print("raw adc: ");
Serial.println(voltage);
Serial.print("mV: ");
Serial.println(voltagemV);
Serial.print("O2: ");
Serial.println(o2);

Serial.println("-----");

delay(1000);
}

void printRawmV(int adcNumber)
{
int16_t adc = 0;

adc = ads.readADC_SingleEnded(adcNumber);
Serial.print("ADC");
Serial.print(adcNumber);
Serial.print(": ");
Serial.print(adc, HEX);
Serial.print(", ");
Serial.println(adc);
}

double avgADC(int adcNumber)
{
double adc = 0;
double result;

adc = 0;

for (int i = 0; i <= AVG_WINDOW - 1; i++)
{
int16_t adsread = ads.readADC_SingleEnded(adcNumber);
adc = adc + adsread;
delay(10);
}

result = adc / AVG_WINDOW;

return result;
}

void checkAllChannels()
{
double voltage0 = 0;
double voltage1 = 0;
double voltage2 = 0;
double voltage3 = 0;

Serial.println("\n0: ");
printRawmV(0);
voltage0 = avgADC(0);
Serial.println(voltage0);

Serial.println("\n1: ");
printRawmV(1);
voltage1 = avgADC(1);
Serial.println(voltage1);

Serial.println("\n2: ");
printRawmV(2);
voltage2 = avgADC(2);
Serial.println(voltage2);

Serial.println("\n3: ");
printRawmV(3);
voltage3 = avgADC(3);
Serial.println(voltage3);
}

0 comments on commit 6544bb2

Please sign in to comment.