The Alpha Geek – Geeking Out

SparkFun Environmental Combo CCS811/BME280

Project #28 – Sensors – SparkFun Environmental Combo CCS811/BME280 – Mk09

——

#DonLucElectronics #DonLuc #Sensors #CCS811 #BME280 #TSOP85 #TMP102 #LineSensor #AlcoholGasSensor #MinIMU9 #Pololu #Adafruit #SparkFun #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo – CCS811/BME280

The SparkFun CCS811/BME280 Environmental Combo Breakout takes care of all your atmospheric-quality sensing needs with the popular CCS811 and BME280 ICs. This unique breakout provides a variety of environmental data, including barometric pressure, humidity, temperature, TVOCs and equivalent eCO2 levels.

The CCS811 is an exceedingly popular sensor, providing readings for equivalent eCO2 in the parts per million (PPM) and total volatile organic compounds in the parts per billion (PPB). The CCS811 also has a feature that allows it to fine-tune its readings if it has access to the current humidity and temperature. Luckily for us, the BME280 provides humidity, temperature and barometric pressure. This allows the sensors to work together to give us more accurate readings than they’d be able to provide on their own. We also made it easy to interface with them via I2C.

DL2309Mk03

1 x Adafruit METRO M0 Express
1 x DS3231 Precision RTC FeatherWing
1 x Pololu MinIMU-9 v5 Gyro, Accelerometer, and Compass
1 x Pololu Carrier for MQ Gas Sensors
1 x Alcohol Gas Sensor – MQ-3
1 x SparkFun Line Sensor – QRE1113
1 x SparkFun Digital Temperature Sensor – TMP102
1 x SparkFun IR Receiver – TSOP85
1 x SparkFun Environmental Combo – CCS811/BME280
1 x LED Red
1 x ProtoScrewShield
1 x Rocker Switch – SPST
2 x Resistor 10K Ohm
1 x CR1220 3V Lithium Coin Cell Battery
1 x SparkFun Cerberus USB Cable

Adafruit METRO M0 Express

LED – LED_BUILTIN
SDA – Digital 20
SCL – Digital 21
IRR – Digital 11
LER – Digital 3
SW1 – Digital 2
MQ3 – Analog 0
LSB – Analog 1
ALE = Analog 3
VIN – +3.3V
VIN – +5V
GND – GND

——

DL2309Mk03p.ino

/****** Don Luc Electronics © ******
Software Version Information
Project #28 - Sensors - SparkFun Environmental Combo CCS811/BME280 - Mk09
28-09
DL2309Mk03p.ino
1 x Adafruit METRO M0 Express
1 x DS3231 Precision RTC FeatherWing
1 x Pololu MinIMU-9 v5 Gyro, Accelerometer, and Compass
1 x Pololu Carrier for MQ Gas Sensors
1 x Alcohol Gas Sensor - MQ-3
1 x SparkFun Line Sensor - QRE1113
1 x SparkFun Digital Temperature Sensor - TMP102
1 x SparkFun IR Receiver - TSOP85
1 x SparkFun Environmental Combo - CCS811/BME280
1 x LED Red
1 x ProtoScrewShield
1 x Rocker Switch - SPST
2 x Resistor 10K Ohm
1 x CR1220 3V Lithium Coin Cell Battery
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// DS3231 Precision RTC 
#include <RTClib.h>
// Two Wire Interface (TWI/I2C)
#include <Wire.h>
// Keyboard
#include <Keyboard.h>
// Includes and variables for IMU integration
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
#include <LSM6.h>
// STMicroelectronics LIS3MDL Magnetometer
#include <LIS3MDL.h>
// SparkFun Digital Temperature Sensor TMP102
#include <SparkFunTMP102.h>
// SparkFun IR Receiver - TSOP85
#include <IRremote.h>
// SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude
#include <SparkFunBME280.h>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>

// Keyboard
String sKeyboard = "";

// DS3231 Precision RTC 
RTC_DS3231 rtc;
String dateRTC = "";
String timeRTC = "";

// Pololu 9DoF IMU
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
LSM6 imu;
// Accelerometer and Gyroscopes
// Accelerometer
int imuAX;
int imuAY;
int imuAZ;
// Gyroscopes 
int imuGX;
int imuGY;
int imuGZ;
// STMicroelectronics LIS3MDL Magnetometer
LIS3MDL mag;
// Magnetometer
int magX;
int magY;
int magZ;

// Gas Sensors MQ
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A0;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// SparkFun Line Sensor - QRE1113 (Analog)
int iLine = A1;
int iLineSensor = 0;

// SparkFun Digital Temperature Sensor TMP102
const int ALERT_PIN = A3;
TMP102 sensor0;
float temperature;
boolean alertPinState;
boolean alertRegisterState;

// SparkFun IR Receiver - TSOP85
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
String IRValue = "";
int iLEDRed = 3;

// SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude
BME280 myBME280;
float BMEtempC = 0;
float BMEhumid = 0;
float BMEpressure = 0;
float BMEaltitudeM = 0;

// SparkFun CCS811 - eCO2 & tVOC
// Default I2C Address
#define CCS811_ADDR 0x5B 
CCS811 myCCS811(CCS811_ADDR);
float CCS811CO2 = 0;
float CCS811TVOC = 0;

// The number of the Rocker Switch pin
int iSwitch = 2;
// Variable for reading the button status
int SwitchState = 0;

// Software Version Information
String sver = "28-09";

void loop() {

  // Date and Time RTC
  isRTC ();

  // Pololu Accelerometer and Gyroscopes
  isIMU();

  // Pololu Magnetometer
  isMag();

  // Gas Sensors MQ
  isGasSensor();

  // SparkFun Line Sensor
  isLineSensor();

  // SparkFun Temperature TMP102
  isTMP102();

  // SparkFun IR Receiver - TSOP85
  isIR();

  // SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude
  isBME280();

  // SparkFun CCS811 - eCO2 & tVOC
  isCCS811();

  // Read the state of the Switch value:
  SwitchState = digitalRead(iSwitch);

  // Check if the button is pressed. If it is, the SwitchState is HIGH:
  if (SwitchState == HIGH) {

     Keyboard.println(sKeyboard);
    
  }

  // Delay 1 Second
  delay(1000);

}

getAccelGyro.ino

// Accelerometer and Gyroscopes
// Setup IMU
void setupIMU() {

  // Setup IMU
  imu.init();
  // Default
  imu.enableDefault();
  
}
// Accelerometer and Gyroscopes
void isIMU() {

  // Accelerometer and Gyroscopes
  imu.read();
  // Accelerometer x, y, z
  imuAX = imu.a.x;
  imuAY = imu.a.y;
  imuAZ = imu.a.z;
  // Gyroscopes x, y, z
  imuGX = imu.g.x;
  imuGY = imu.g.y;
  imuGZ = imu.g.z;

  // Keyboard
  sKeyboard = sKeyboard + String(imuAX) + "|" + String(imuAY) + "|"
  + String(imuAZ) + "|";
  sKeyboard = sKeyboard + String(imuGX) + "|" + String(imuGY) + "|"
  + String(imuGZ) + "|";
  
}

getBME280.ino

// SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude
// isBME280 - Temperature, Humidity, Barometric Pressure, and Altitude
void isBME280(){

  // Temperature Celsius
  BMEtempC = myBME280.readTempC();
  // Humidity
  BMEhumid = myBME280.readFloatHumidity();
  // Barometric Pressure
  BMEpressure = myBME280.readFloatPressure();
  // Altitude Meters
  BMEaltitudeM = (myBME280.readFloatAltitudeMeters(), 2);

  // Keyboard
  sKeyboard = sKeyboard + String(BMEtempC) + "|" + String(BMEhumid) + "|" +
  String(BMEpressure) + "|" + String(BMEaltitudeM) + "|";

}

getCCS811.ino

// CCS811 - eCO2 & tVOC
// isCCS811 - eCO2 & tVOC
void isCCS811(){

  // This sends the temperature & humidity data to the CCS811
  myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);

  // Calling this function updates the global tVOC and eCO2 variables
  myCCS811.readAlgorithmResults();

  // eCO2 Concentration
  CCS811CO2 = myCCS811.getCO2();
  
  // tVOC Concentration
  CCS811TVOC = myCCS811.getTVOC();

  // Keyboard
  sKeyboard = sKeyboard + String(CCS811CO2) + "|" + String(CCS811TVOC) + "|*";

}

getGasSensorMQ.ino

// Gas Sensors MQ
// Gas Sensor
void isGasSensor() {

  // Read in analog value from each gas sensors
  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw );

  // Keyboard
  sKeyboard = sKeyboard + String(iMQ3ppm) + "|";

}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue;
  // % BAC = breath mg/L * 0.21
  double bac = RvRo * 0.21;
  return bac;
  
}

getIMUMagnetometer.ino

// IMU Magnetometer
// Setup Magnetometer
void setupMag() {

  // Setup Magnetometer
  mag.init();
  // Default
  mag.enableDefault();
  
}
// Magnetometer
void isMag() {

  // Magnetometer
  mag.read();
  // Magnetometer x, y, z
  magX = mag.m.x;
  magY = mag.m.y;
  magZ = mag.m.z;

  // Keyboard
  sKeyboard = sKeyboard + String(magX) + "|" + String(magY) + "|" 
  + String(magZ) + "|";
  
}

getIRRemote.ino

// SparkFun IR Receiver - TSOP85
// Setup
void isSetupIR(){

  // Initialize digital pin LED Red as an output
  pinMode(iLEDRed, OUTPUT);
  
  // Start the receiver
  irrecv.enableIRIn();
  
}
//
void isIR(){

  if (irrecv.decode(&results))
  {
    
    // LED Red HIGH
    digitalWrite(iLEDRed, HIGH);
    
    //Serial.print("IR RECV Code = 0x ");
    //Serial.println(results.value, HEX);

    IRValue = "0x ";
    IRValue = IRValue + String(results.value, HEX);

    // LED Red LOW
    digitalWrite(iLEDRed, LOW);

    // IR Resume
    irrecv.resume();
    
  }
  else {

    IRValue = "0";
    
  }

  // Keyboard
  sKeyboard = sKeyboard + String(IRValue) + "|";
  
}

getLineSensor.ino

// Line Sensor
// isLine Sensor
void isLineSensor(){

  // Line Sensor
  iLineSensor = analogRead(iLine);

  // Keyboard
  sKeyboard = sKeyboard + String(iLineSensor) + "|";
  
}

getRTC.ino

// Date & Time
// DS3231 Precision RTC
void setupRTC() {

  // DS3231 Precision RTC
  if (! rtc.begin()) {
    //Serial.println("Couldn't find RTC");
    //Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    //Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2023, 8, 10, 11, 0, 0));
  }
  
}
// Date and Time RTC
void isRTC () {

  // Date and Time
  dateRTC = "";
  timeRTC = "";
  DateTime now = rtc.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;

  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;

  // Keyboard
  sKeyboard = "SEN|" + sver + "|" + String(dateRTC) + "|" + 
  String(timeRTC) + "|";
  
}

getTempTMP102.ino

// SparkFun Digital Temperature Sensor TMP102
// Setup TMP102
void isSetupTMP102(){

  // Declare alertPin as an input
  pinMode(ALERT_PIN,INPUT);
  
  // Begin
  //It will return true on success or false on failure to communicate
  if(!sensor0.begin())
  {
    
    while(1);
    
  }
  
  // set the Conversion Rate
  //0-3: 0:0.25Hz, 1:1Hz, 2:4Hz, 3:8Hz
  sensor0.setConversionRate(2);
  
  //set Extended Mode.
  //0:12-bit Temperature(-55C to +128C) 1:13-bit Temperature(-55C to +150C)
  sensor0.setExtendedMode(0);
  
  // Set T_HIGH, the upper limit to trigger the alert on
  // Set T_HIGH in C
  sensor0.setHighTempC(29.4);
  
  // Set T_LOW, the lower limit to shut turn off the alert
  // set T_LOW in C
  sensor0.setLowTempC(27.67);

}
// is TMP102
void isTMP102(){

  // Turn sensor on to start temperature measurement.
  // Current consumtion typically ~10uA.
  sensor0.wakeup();

  // read temperature data C
  temperature = sensor0.readTempC();

  // Check for Alert
  // Read the Alert from pin
  alertPinState = digitalRead(ALERT_PIN);
  
  // Read the Alert from register
  alertRegisterState = sensor0.alert();
  
  // Place sensor in sleep mode to save power.
  // Current consumtion typically <0.5uA.
  sensor0.sleep();

  // Keyboard
  sKeyboard = sKeyboard + String(temperature) + "|" + 
  String(alertPinState) + "|" + String(alertRegisterState) + "|";

}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);
  
  // Wire - Inialize I2C Hardware
  Wire.begin();

  // Give display time to power on
  delay(100);

  // Date & Time RTC
  // DS3231 Precision RTC 
  setupRTC();
  
  // Initialize control over the keyboard:
  Keyboard.begin();

  // Pololu Setup IMU
  setupIMU();

  // Pololu Setup Magnetometer
  setupMag();

  // Setup TMP102
  isSetupTMP102();

  // SetupTSOP85
  isSetupIR();

  // SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude 
  myBME280.begin();

  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

  // Initialize the Switch pin as an input
  pinMode(iSwitch, INPUT);

  // Initialize digital pin LED_BUILTIN as an output
  pinMode(LED_BUILTIN, OUTPUT);
  // Turn the LED on HIGH
  digitalWrite(LED_BUILTIN, HIGH);

  // Delay 5 Second
  delay( 5000 );

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Programming Language
  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Wireless (Radio Frequency, Bluetooth, WiFi, Etc…)
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Machine Learning
  • RTOS
  • Research & Development (R & D)

Instructor, E-Mentor, STEAM, and Arts-Based Training

  • Programming Language
  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

Luc Paquin – Curriculum Vitae – 2023
https://www.donluc.com/luc/

Web: https://www.donluc.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/@thesass2063
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #19: Time – SparkFun Environmental Combo CCS811/BME280 – Mk06

——

#DonLucElectronics #DonLuc #Time #RTC #Display #Adalogger #MicroSD #GPSReceiver #CCS811 #BME280 #Arduino #ESP32 #SparkFunESP32WROOM #Project #Programming #Electronics #Microcontrollers #Consultant #VideoBlog

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo CCS811/BME280

——

SparkFun Environmental Combo Breakout – CCS811/BME280 (Qwiic)

The SparkFun CCS811/BME280 Environmental Combo Breakout takes care of all your atmospheric-quality sensing needs with the popular CCS811 and BME280 ICs. This unique breakout provides a variety of environmental data, including barometric pressure, humidity, temperature, TVOCs and equivalent eCO2 levels. To make it even easier to use this breakout, all communication is enacted exclusively via I2C, utilizing our handy Qwiic system. However, we still have broken out 0.1″ spaced pins in case you prefer to use a breadboard.

Bosch Sensortec BME280

The BME280 is as combined digital humidity, pressure and temperature sensor based on proven sensing principles. Its small dimensions and its low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches. The BME280 achieves high performance in all applications requiring humidity and pressure measurement. These emerging applications of home automation control, indoor navigation, health care as well as GPS refinement require a high accuracy and a low TCO at the same time. The humidity sensor provides an extremely fast response time for fast context awareness applications and high overall accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with extremely high accuracy and resolution.

Typical Application

-Context awareness, e.g. skin detection, room change detection
-Health monitoring / well-being
-Warning regarding dehydration or heat stroke
-Spirometry (measurement of lung volume and air flow)
-Home automation control
-Control heating, venting, air conditioning (HVAC)
-Internet of Things
-GPS enhancement (e.g. time-to-first-fix improvement, dead reckoning, slope detection)
-Indoor navigation (change of floor detection, elevator detection)
-Outdoor navigation, leisure and sports applications
-Weather forecast
-Vertical velocity indication (rise/sink speed)

Target devices

-Handsets such as mobile phones, tablet PCs, GPS devices
-Navigation systems
-Gaming, e.g flying toys
-Camera (DSC, video)
-Portable health care devices
-Home weather stations
-Flying toys
-Watches

ams AG CCS811

The CCS811 is an exceedingly popular sensor, providing readings for equivalent eCO2 in the PPM and total volatile organic compounds in the PPB. The CCS811 is an ultra-low power digital gas sensor solution which integrates a metal oxide (MOX) gas sensor to detect a wide range of Volatile Organic Compounds (VOCs) for indoor air quality monitoring with a microcontroller unit (MCU), which includes an Analog-to-Digital converter (ADC), and an I²C interface.

DL2108Mk07

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x Adalogger FeatherWing – RTC + SD
1 x SparkFun Environmental Combo CCS811/BME280 (Qwiic)
1 x Qwiic Cable – 100mm
1 x CR1220 3V Lithium Coin Cell Battery
1 x 32Gb microSD Card
1 x LED Green
1 x Rocker Switch – SPST (Round)
1 x Terminal Block Breakout FeatherWing
1 x Lithium Ion Battery – 850mAh
1 x GPS Receiver – GP-20U7
1 x Rotary Switch – 10 Position
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
2 x Spring Terminals – PCB Mount (6-Pin)
2 x Breadboard Solderable
12 x 1K Ohm
1 x FeatherWing Proto
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

Qwiic – 0x77
Qwiic – 0x5B
SCK – Digital 13
MSI – Digital 12
SS0 – Digital 27
GRX – Digital 16
GTX – Digital 17
SDA – Digital 23
SDL – Digital 22
SCK – Digital 5
MSO – Digital 19
MSI – Digital 18
SS1 – Digital 33
LEG – Digital 21
SW0 – Digital 32
ROT – Analog A0
VIN – +3.3V
GND – GND

——

DL2108Mk07p.ino

/* 
***** Don Luc Electronics © *****
Software Version Information
Project #19: Time - SparkFun Environmental Combo CCS811/BME280 - Mk06
08-07
DL2108Mk07p.ino
1 x SparkFun Thing Plus - ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x Adalogger FeatherWing - RTC + SD
1 x SparkFun Environmental Combo CCS811/BME280 (Qwiic)
1 x CR1220 3V Lithium Coin Cell Battery
1 x 32Gb microSD Card
1 x LED Green
1 x Rocker Switch - SPST (Round)
1 x Terminal Block Breakout FeatherWing
1 x Lithium Ion Battery - 850mAh
1 x GPS Receiver - GP-20U7
1 x Rotary Switch - 10 Position
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
2 x Spring Terminals - PCB Mount (6-Pin)
2 x Breadboard Solderable
12 x 1K Ohm
1 x FeatherWing Proto
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include "EEPROM.h"
// Wire
#include <Wire.h>
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// Date and time RTC
#include "RTClib.h"
// GPS Receiver
#include <TinyGPS++.h>
// ESP32 Hardware Serial
#include <HardwareSerial.h>
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>

// SHARP Memory Display
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here, e.g. 144x168!
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
// The currently-available SHARP Memory Display (144x168 pixels)
// requires > 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno
// or other <4K "classic" devices.
#define BLACK 0
#define WHITE 1

// Date and Time
// PCF8523 Precision RTC 
RTC_PCF8523 rtc;
// Date
String dateRTC = "";
// Time
String timeRTC = "";

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 16
// This one is unused and doesnt have a conection
#define gpsTXPIN 17
// The TinyGPS++ object
TinyGPSPlus gps;
// Latitude
float TargetLat;
// Longitude
float TargetLon;
// GPS Date, Time, Speed, Altitude
// GPS Date
String TargetDat;
// GPS Time
String TargetTim;
// GPS Speeds M/S
String TargetSMS;
// GPS Speeds Km/h
String TargetSKH;
// GPS Altitude Meters
String TargetALT;
// GPS Status
String GPSSt = "";

// Rotary Switch - 10 Position
// Number 1 => 10
int iRotNum = A0;
// iRotVal - Value 
int iRotVal = 0;
// Number
int z = 0;

// MicroSD Card
const int chipSelect = 33;
String zzzzzz = "";

// LED Green
int iLEDGreen = 21;

// Rocker Switch - SPST (Round)
int iSS1 = 32;
// State
int iSS1State = 0;

// SparkFun CCS811 - eCO2 & tVOC
// Default I2C Address
#define CCS811_ADDR 0x5B 
CCS811 myCCS811(CCS811_ADDR);
// eCO2
float CCS811CO2 = 0;
// TVOC
float CCS811TVOC = 0;

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
BME280 myBME280;
// Temperature Celsius
float BMEtempC = 0;
// Humidity
float BMEhumid = 0;
// Altitude Meters
float BMEaltitudeM = 0;
// Barometric Pressure
float BMEpressure = 0;

// Software Version Information
// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";
// Version
String sver = "19-06";

void loop()
{
     
  // Dates and Time
  isRTC();

  // isGPS
  isGPS();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

  // SparkFun CCS811 - eCO2 & tVOC
  isCCS811();

  // Rotary Switch
  isRot();

  // Slide Switch
  // Read the state of the iSS1 value
  iSS1State = digitalRead(iSS1);
  
  // If it is the Slide Switch State is HIGH
  if (iSS1State == HIGH) {

    // iLEDGreen HIGH
    digitalWrite(iLEDGreen,  HIGH );
    
    // MicroSD Card
    isSD();

  } else {

    // iLEDGreen LOW
    digitalWrite(iLEDGreen,  LOW );
  
  }

  delay( 1000 );
 
}

getBME280.ino

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
// isBME280 - Humidity, Temperature, Altitude and Barometric Pressure
void isBME280(){

  // Temperature Celsius
  BMEtempC = myBME280.readTempC();
  // Humidity
  BMEhumid = myBME280.readFloatHumidity();
  // Altitude Meters
  BMEaltitudeM = (myBME280.readFloatAltitudeMeters(), 2);
  // Barometric Pressure
  BMEpressure = myBME280.readFloatPressure();
  
}

getCCS811.ino

// CCS811 - eCO2 & tVOC
// isCCS811 - eCO2 & tVOC
void isCCS811(){

  // This sends the temperature & humidity data to the CCS811
  myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);

  // Calling this function updates the global tVOC and eCO2 variables
  myCCS811.readAlgorithmResults();

  // eCO2 Concentration
  CCS811CO2 = myCCS811.getCO2();
  
  // tVOC Concentration
  CCS811TVOC = myCCS811.getTVOC();
  
}

getDisplay.ino

// SHARP Memory Display
// SHARP Memory Display - UID
void isDisplayUID() {

    // Text Display 
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Don Luc Electronics
    display.setCursor(0,10);
    display.println( "Don Luc" );
    display.setTextSize(2);
    display.setCursor(0,40);
    display.println( "Electronics" );
    // Version
    //display.setTextSize(3);
    display.setCursor(0,70);
    display.println( "Version" );
    //display.setTextSize(2);
    display.setCursor(0,95);   
    display.println( sver );
    // EEPROM
    display.setCursor(0,120);
    display.println( "EEPROM" );
    display.setCursor(0,140);   
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Date
void isDisplayDate() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Date
    display.setCursor(0,5);
    display.println( "Date" );
    display.setCursor(0,30);
    display.println( dateRTC );
    // Time
    display.setCursor(0,55);
    display.println( "Time" );
    display.setCursor(0,75);
    display.println( timeRTC );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display GPS
void isDisplayGPS() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // GPS Status
    display.setCursor(0,5);
    display.print( "GPS: " );
    display.println( GPSSt );
    // Target Latitude
    display.setCursor(0,25);
    display.println( "Latitude" );
    display.setCursor(0,45);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,65);
    display.println( "Longitude" );
    display.setCursor(0,90);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// GPS Date, Time, Speed, Altitude
void isDisplayGPSDate() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // GPS
    display.setCursor(0,5);
    display.println( "GPS" );
    // Date
    display.setCursor(0,30);
    display.println( TargetDat );
    // Time
    display.setCursor(0,55);
    display.println( TargetTim );
    // Speed
    display.setCursor(0,75);
    display.print( "M/S: " );
    display.println( TargetSMS );
    display.setCursor(0,95);
    display.print( "Km/h: " );
    display.println( TargetSKH );
    display.setCursor(0,115);
    display.print( "Alt: " );
    display.println( TargetALT );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280 - Humidity, Temperature, Altitude and Barometric Pressure
void isDisplayBME280() {

     // Text Display BME280
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,10);
    display.println( "Temperature" );
    display.setCursor(0,30);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,50);
    display.println( "Humidity" );
    display.setCursor(0,70);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,90);
    display.println( "Altitude M" );
    display.setCursor(0,110);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,130);    
    display.println( "Barometric" );
    display.setCursor(0,150);
    display.print( BMEpressure );
    display.println( "Pa" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display CCS811 - eCO2 & tVOC
void isDisplayCCS811() {

    // Text Display CCS811
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // eCO2 Concentration
    display.setCursor(0,10);
    display.println( "eCO2" );
    display.setCursor(0,30);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,60);
    display.println( "tVOC" );
    display.setCursor(0,80);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display Z
void isDisplayZ() {
    // Text Display Z
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Z
    display.setCursor(0,10);
    display.print( "Z: " );
    display.println( z );
    // Refresh
    display.refresh();
    delay( 100 );
}

getEEPROM.ino

// EEPROM
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGPS.ino

// GPS Receiver
// Setup GPS
void setupGPS() {

  // Setup GPS
  tGPS.begin(  9600 , SERIAL_8N1 , gpsRXPIN , gpsTXPIN );
  
}
// isGPS
void isGPS(){

  // Receives NEMA data from GPS receiver
  // This sketch displays information every time a new sentence is correctly encoded
  while ( tGPS.available() > 0)
    
    if (gps.encode( tGPS.read() ))
    {
     
       // GPS Vector Pointer Target
       displayInfo();
       // GPS Date, Time, Speed, Altitude
       displayDTS();
       
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
   
     while(true);
    
  }

}
// GPS Vector Pointer Target
void displayInfo(){

  // Location
  if (gps.location.isValid())
  {
    
     // Latitude
     TargetLat = gps.location.lat();
     // Longitude
     TargetLon = gps.location.lng();
     // GPS Status 2
     GPSSt = "Yes";
    
  }
  else
  {

     // GPS Status 0
     GPSSt = "No";
    
  }

}
// GPS Date, Time, Speed, Altitude
void displayDTS(){

  // Date
  TargetDat = ""; 
  if (gps.date.isValid())
  {
    
     // Date
     // Year
     TargetDat += String(gps.date.year(), DEC);
     TargetDat += "/";
     // Month
     TargetDat += String(gps.date.month(), DEC);
     TargetDat += "/";
     // Day
     TargetDat += String(gps.date.day(), DEC);
    
  }

  // Time
  TargetTim = "";
  if (gps.time.isValid())
  {
    
     // Time
     // Hour
     TargetTim += String(gps.time.hour(), DEC);
     TargetTim += ":";
     // Minute
     TargetTim += String(gps.time.minute(), DEC);
     TargetTim += ":";
     // Secound
     TargetTim += String(gps.time.second(), DEC);
    
  }

  // Speed
  TargetSMS = "";
  TargetSKH = "";
  if (gps.speed.isValid())
  {
    
     // Speed
     // M/S
     int x = gps.speed.mps();
     TargetSMS = String( x, DEC);
     // Km/h
     int y = gps.speed.kmph();
     TargetSKH = String( y, DEC);

  }

  // Altitude
  TargetALT = "";
  if (gps.altitude.isValid())
  {
    
     // Altitude
     // Meters
     int z = gps.altitude.meters();
     TargetALT = String( z, DEC);

  }
  
}

getRTC.ino

// Date & Time
// PCF8523 Precision RTC
void setupRTC() {

  // Date & Time
  // pcf8523 Precision RTC   
  if (! rtc.begin()) {
    while (1);
  }  
  
  if (! rtc.initialized()) {
    
    // Following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
    // rtc.adjust(DateTime(2021, 8, 18, 8, 48, 0));
    
  }
  
}
// Date and Time RTC PCF8523
void isRTC () {

  // Date and Time
  dateRTC = "";
  timeRTC = "";
  DateTime now = rtc.now();
  
  // Date
  // Year
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  // Month
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  // Day
  dateRTC = dateRTC + now.day(), DEC;
  
  // Time
  // Hour
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  // Minute
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  // Second
  timeRTC = timeRTC + now.second(), DEC;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {
  
  // Rotary Switch
  z = analogRead( iRotNum );
  
  // Rotary Switch - 10 Position
  // Number 1 => 10
  if ( z >= 3600 ) {

    // Z
    iRotVal = 10;
    
  } else if ( z >= 3200 ) {

    // Z
    iRotVal = 9;
    
  } else if ( z >= 2700 ) {

    // Z
    iRotVal = 8;
    
  } else if ( z >= 2400 ) {

    // Z
    iRotVal = 7;
    
  } else if ( z >= 2000 ) {

    // Z
    iRotVal = 6;
    
  } else if ( z >= 1600 ) {

    // Z
    iRotVal = 5;
    
  } else if ( z >= 1200 ) {

    // Z
    iRotVal = 4;
    
  } else if ( z >= 900 ) {

    // Z
    iRotVal = 3;
    
  } else if ( z >= 500 ) {

    // Z
    iRotVal = 2;
    
  } else {

    // Z
    iRotVal = 1;
    
  }

  // Range Value
  switch ( iRotVal ) {
    case 1:

      // Display Date, Time
      isDisplayDate();
       
      break;
    case 2:

      // Display GPS
      isDisplayGPS();
         
      break;
    case 3:

      // GPS Date, Time, Speed, Altitude
      //isDisplayGPSDate();
      
      break;  
    case 4:
      
      // GPS Display Date, Time, Speed
      isDisplayGPSDate();
      
      break;
    case 5:
      
      // Display BME280
      isDisplayBME280();
      
      break;
    case 6:
      
      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;       
    case 7:

      // Z
      isDisplayZ();
      
      break; 
    case 8:
         
      // Z
      isDisplayZ();
      
      break; 
    case 9:
      
      // Z
      isDisplayZ();
      
      break;
    case 10:

      // Z
      isDisplayZ();
      
      break;
  }
  
}

getSD.ino

// MicroSD Card
// MicroSD Setup
void setupSD() {

    // MicroSD Card
    pinMode( chipSelect , OUTPUT );
    if(!SD.begin( chipSelect )){
        ;  
        return;
    }
    
    uint8_t cardType = SD.cardType();

    // CARD NONE
    if(cardType == CARD_NONE){
        ; 
        return;
    }

    // SD Card Type
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

    // Size
    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
 
}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|GPS Date|GPS Time|GPS Speed M/S|GPS Speed Km/h|GPS Altitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|\r
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSSt + "|" + TargetLat + "|" + TargetLon + "|" + TargetDat + "|" + TargetTim + "|" + TargetSMS + "|" + TargetSKH + "|" + TargetALT  + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC +  + "|\r";

  // msg + 1
  char msg[zzzzzz.length() + 1];

  zzzzzz.toCharArray(msg, zzzzzz.length() + 1);

  // Append File
  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    // List Dir
    dirname;
    
    File root = fs.open(dirname);
    
    if(!root){
        return;
    }
    
    if(!root.isDirectory()){
        return;
    }

    File file = root.openNextFile();
    
    while(file){
        if(file.isDirectory()){
            file.name();
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            file.name();
            file.size();
        }
        file = root.openNextFile();
    }
    
}
// Write File
void writeFile(fs::FS &fs, const char * path, const char * message){
    
    // Write File
    path;
    
    File file = fs.open(path, FILE_WRITE);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}
// Append File
void appendFile(fs::FS &fs, const char * path, const char * message){
    
    // Append File
    path;
    
    File file = fs.open(path, FILE_APPEND);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}

setup.ino

// Setup
void setup()
{
  
  // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);
  
  // EEPROM Unique ID
  isUID();
  
  // GPS Receiver
  // Setup GPS
  setupGPS();

  // Set up I2C bus
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();

  // Date & Time RTC
  // PCF8523 Precision RTC
  isDisplayUID();
  
  // Setup RTC
  setupRTC();

  //MicroSD Card
  setupSD();

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);

  // Slide Switch
  pinMode(iSS1, INPUT);

  delay( 5000 );
  
}

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2021 English & Español
https://www.jlpconsultants.com/CV/LucPaquinCVEngMk2021c.pdf
https://www.jlpconsultants.com/CV/LucPaquinCVEspMk2021c.pdf

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Web: https://zoom.us/
Patreon: https://www.patreon.com/DonLucElectronics
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Categories
Archives