The Alpha Geek – Geeking Out

Display

Project #19: Time – GPS Receiver – GP-20U7 – Mk03

——

#DonLucElectronics #DonLuc #Time #DS3231PrecisionRTC #SHARPMemoryDisplay #GPSReceiver #Arduino #ESP32 #SparkFunThingPlusESP32WROOM #Project #Programming #Electronics #Microcontrollers #Consultant #VideoBlog

——

GPS Receiver

——

GPS Receiver

——

GPS Receiver

——

GPS Receiver

——

GPS Receiver

——

GPS Receiver – GP-20U7

The GP-20U7 is a compact GPS receiver with a built-in high performances all-in-one GPS chipset. The GP-20U7 accurately provides position, velocity, and time readings as well possessing high sensitivity and tracking capabilities. Thanks to the low power consumption this receiver requires, the GP-20U7 is ideal for portable applications such as tablet PCs, smart phones, and other devices requiring positioning capability.

This 56-channel GPS module, that supports a standard NMEA-0183 and uBlox 7 protocol, has low power consumption of 40mA@3.3V (max), an antenna on board, and -162dBm tracking sensitivity. With 56 channels in search mode and 22 channels “all-in-view” tracking, the GP-20U7 is quite the work horse for its size.

This one is unused and doesnt have a conection TX pin.

NMEA V3.01 Protocol

  • Its output signal level is TTL: 9600bps (default), 8 bit data, 1 stop bit and no parity
  • It supports the following NMEA-0183
  • Messages: GGA, GLL, GSA, GSV, RMC and VTG

NMEA-0183 Output Messages

  • NMEA: Record Description
  • GGA: Global positoning system fixed data
  • GLL: Geogrphic position – latitude / longitude
  • GSA: GNSS DOP and active satellites
  • GSV: GNSS satellites in view
  • RMC: Recommended minimum specific GNSS data
  • VTG: Course over ground and ground speed

DL2108Mk03

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Lithium Ion Battery – 850mAh
1 x GPS Receiver – GP-20U7
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

SCK – Digital 13
MSI – Digital 12
SS0 – Digital 27
GRX – Digital 16
GTX – Digital 17
SDA – Digital 23
SDL – Digital 22
VIN – +3.3V
GND – GND

DL2108Mk03p.ino

/* 
***** Don Luc Electronics © *****
Software Version Information
Project #19: Time -GPS Receiver - GP-20U7 - Mk03
08-03
DL2108Mk03p.ino
1 x SparkFun Thing Plus - ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Lithium Ion Battery - 850mAh
1 x GPS Receiver - GP-20U7
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Wire
// #include <Wire.h>
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// Date and time DS3231 RTC
#include <RTClib.h>
// GPS Receiver
#include <TinyGPS++.h>
// ESP32 Hardware Serial
#include <HardwareSerial.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 functions using a DS3231 RTC
RTC_DS3231 RTC;
String sDate;
String sTime;

// 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;
float TargetLat;
float TargetLon;
int GPSStatus = 0;
String GPSSt = "";

// Software Version Information
// Version
String sver = "19-03";

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

  // isGPS
  isGPS();

  // Display Date, Time, GPS
  isDisplayDate();

  delay( 1000 );
 
}

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,100);   
    display.println( sver );
    // 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( sDate );
    // Time
    display.setCursor(0,30);
    display.println( sTime );
    // GPS Status
    display.setCursor(0,55);
    display.print( "GPS: " );
    display.println( GPSSt );
    // Target Latitude
    display.setCursor(0,75);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,145);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}

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();
      
    }
  
  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
     GPSStatus = 2;
     GPSSt = "Yes";
    
  }
  else
  {

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

}

getRTCDS3231.ino

// DS3231 Precision RTC
// Setup RTC
void setupRTC() {

  // DS3231 Precision RTC   
  RTC.begin();
  if (! RTC.begin()) {
    while (1);
  }
  
  // Date Time
  DateTime now = RTC.now();

  if (RTC.lostPower()) {
    
    // 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
    // August 2, 2021 at 13:53:0 you would call:
    // RTC.adjust(DateTime(2021, 8, 2, 14, 11, 0));
    
  }
  
}
// timeRTC
void timeRTC() {

    // DS3231 Precision RTC
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = RTC.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);

}

setup.ino

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

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

  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();

  // Display UID
  isDisplayUID();
  
  // Setup RTC
  setupRTC();

  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

Project #19: Time – SHARP Memory Display – Mk02

——

#DonLucElectronics #DonLuc #Time #DS3231PrecisionRTC #SHARPMemoryDisplay #Arduino #ESP32 #SparkFunThingPlusESP32WROOM #Project #Programming #Electronics #Microcontrollers #Consultant #VideoBlog

——

SHARP Memory Display

——

SHARP Memory Display

——

SHARP Memory Display

——

SHARP Memory Display

——

Adafruit SHARP Memory Display Breakout – 1.3 Inches – 168 Pixels x 144 Pixels Monochrome

The 1.3 inches 168 pixels x 144 pixels SHARP Memory LCD display is a cross between an eInk display and an LCD. It has the ultra-low power usage of eInk and the fast-refresh rates of an LCD. This model has a gray background, and pixels show up as black-on-gray for a nice e-reader type display. It does not have a backlight, but it is daylight readable. For dark/night reading you may need to illuminate the LCD area with external LEDs.

The display is write only which means that it only needs 3 pins to send data. However, the downside of a write-only display is that the entire 168×144 bits must be buffered by the microcontroller driver. That means you cannot use this with an ATmega328 or ATmega32u4. You must use a high-RAM chip such as ATSAMD21, Teensy 3, ESP8266, ESP32, etc. On those chips, this display works great and looks wonderful.

DL2108Mk02

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Lithium Ion Battery – 850mAh
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

SCK – Digital 13
MSI – Digital 12
SS0 – Digital 27
SDA – Digital 23
SDL – Digital 22
VIN – +3.3V
GND – GND

DL2108Mk02p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #19: Time -SHARP Memory Display - Mk02
08-02
DL2108Mk02p.ino
1 x SparkFun Thing Plus - ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Qwiic Cable - 50mm
1 x Lithium Ion Battery - 850mAh
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
#include <Wire.h>
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// Date and time DS3231 RTC
#include <RTClib.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

// Set this to 1000 to get _about_ 1 second timing
const int CLOCK_SPEED = 1000;
// Last Draw
unsigned long lastDraw = 0;

// Date and time functions using a DS3231 RTC
RTC_DS3231 RTC;
String sDate;
String sTime;

// Software Version Information
// Version
String sver = "19-02";

void loop()
{
  
  // Check if we need to update date, time
  if (lastDraw + CLOCK_SPEED < millis())
  {
    
    // Last Draw
    lastDraw = millis();
    
    // Dates and Time
    timeRTC();

    // is OLED
    //isOLED();
    isDisplayDate();
    
  }
  
}

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,100);   
    display.println( sver );
    // 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( sDate );
    // Time
    display.setCursor(0,30);
    display.println( sTime );
    // Refresh
    display.refresh();
    delay( 100 );

}

getRTCDS3231.ino

// DS3231 Precision RTC
// Setup RTC
void setupRTC() {

  // DS3231 Precision RTC   
  RTC.begin();
  if (! RTC.begin()) {
    while (1);
  }
  
  DateTime now = RTC.now();

  if (RTC.lostPower()) {
    
    // 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
    // August 2, 2021 at 13:53:0 you would call:
    // RTC.adjust(DateTime(2021, 8, 2, 14, 11, 0));
    
  }
  
}
// timeRTC
void timeRTC() {

    // DS3231 Precision RTC
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = RTC.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);

}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);

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

  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();

  // Display UID
  isDisplayUID();
  
  // Setup RTC
  setupRTC();

  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

Project #19: Time – DS3231 Precision RTC – Mk01

——

#DonLucElectronics #DonLuc #Time #DS3231PrecisionRTC #Arduino #ESP32 #SparkFunThingPlusESP32WROOM #Project #Programming #Electronics #Microcontrollers #Consultant #VideoBlog

——

Time

——

Time

——

Time

——

Time

——

DS3231 Precision RTC FeatherWing

A Feather board without ambition is a Feather board without FeatherWings. This is the DS3231 Precision RTC FeatherWing: it adds an extremely accurate I2C-integrated Real Time Clock (RTC) with a Temperature Compensated Crystal Oscillator (TCXO) to any Feather main board. This RTC is the most precise you can get in a small, low power package. Most RTCs use an external 32kHz timing crystal that is used to keep time with low current draw. And that’s all well and good, but those crystals have slight drift, particularly when the temperature changes. This RTC is in a beefy package because the crystal is inside the chip. And right next to the integrated crystal is a temperature sensor. That sensor compensates for the frequency changes by adding or removing clock ticks so that the timekeeping stays on schedule.

SparkFun Micro OLED Breakout (Qwiic)

The SparkFun Qwiic Micro OLED Breakout is a Qwiic-enabled version of our popular Micro OLED display. The small monochrome, blue-on-black OLED screen presents incredibly clear images for your viewing pleasure. The OLED display is crisp, and you can fit a deceivingly large amount of graphics on there. This breakout is perfect for adding graphics to your next project and displaying diagnostic information without resorting to a serial output, all with the ease of use of our own Qwiic Connect System.

DL2108Mk01

1 x SparkFun Thing Plus – ESP32 WROOM
1 x SparkFun Micro OLED Breakout (Qwiic)
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Qwiic Cable – 50mm
1 x Lithium Ion Battery – 850mAh
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

DIS – Qwiic
SDA – Digital 23
SDL – Digital 22
VIN – +3.3V
GND – GND

DL2108Mk01p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #19: Time - DS3231 Precision RTC - Mk01
08-01
DL2108Mk01p.ino
1 x SparkFun Thing Plus - ESP32 WROOM
1 x SparkFun Micro OLED Breakout (Qwiic)
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 3V Lithium Coin Cell Battery
1 x Terminal Block Breakout FeatherWing
1 x Qwiic Cable - 50mm
1 x Lithium Ion Battery - 850mAh
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
#include <Wire.h>
// OLED
#include <SFE_MicroOLED.h>
// Date and time DS3231 RTC
#include <RTClib.h>

// OLED
// DC Jumper
#define DC_JUMPER 1
// Optional - Connect RST on display to pin 9 on Arduino
#define PIN_RESET 9
MicroOLED oled(PIN_RESET, DC_JUMPER);

// Set this to 1000 to get _about_ 1 second timing
const int CLOCK_SPEED = 1000;
// Last Draw
unsigned long lastDraw = 0;

// Date and time functions using a DS3231 RTC
RTC_DS3231 RTC;
String sDate;
String sTime;

// Software Version Information
// Version
String sver = "19-01";

void loop()
{
  // Check if we need to update date, time
  if (lastDraw + CLOCK_SPEED < millis())
  {
    
    // Last Draw
    lastDraw = millis();
    
    // Dates and Time
    timeRTC();

    // is OLED
    isOLED();
    
  }
  
}

getOLED.ino

// OLED
// Setup OLED
void setupOLED(){

  // Initialize the OLED
  oled.begin();
  // Clear the display's internal memory
  oled.clear(PAGE);
  // Clear the library's display buffer
  oled.clear(ALL);
  // Display what's in the buffer
  oled.display();
  
}
// isOLED
void isOLED(){

    // Clear the buffer
    oled.clear(PAGE);
    // Set font to type 0
    oled.setFontType(0);
    
    // Date
    // Set cursor to top-left
    oled.setCursor(0, 18);
    oled.print( sDate );
    
    // Time
    // Set cursor to top-left
    oled.setCursor(0, 32);
    oled.print( sTime );
    
    // Draw the memory buffer
    oled.display();
  
}

getRTCDS3231.ino

// DS3231 Precision RTC
// Setup RTC
void setupRTC() {

  // DS3231 Precision RTC   
  RTC.begin();
  if (! RTC.begin()) {
    while (1);
  }
  
  DateTime now = RTC.now();

  if (RTC.lostPower()) {
    
    // 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
    // August 2, 2021 at 13:53:0 you would call:
    // RTC.adjust(DateTime(2021, 8, 2, 14, 11, 0));
    
  }
  
}
// timeRTC
void timeRTC() {

    // DS3231 Precision RTC
    sDate = "";
    sTime = "";
    // Date Time
    DateTime now = RTC.now();

    // sData
    sDate += String(now.year(), DEC);
    sDate += "/";
    sDate += String(now.month(), DEC);
    sDate += "/";
    sDate += String(now.day(), DEC);
  
    // sTime
    sTime += String(now.hour(), DEC);
    sTime += ":";
    sTime += String(now.minute(), DEC);
    sTime += ":";
    sTime += String(now.second(), DEC);

}

setup.ino

// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);

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

  // Initialize the OLED
  setupOLED();

  // Setup RTC
  setupRTC();
  
}

——

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

Project #15: Environment – PIR Motion Sensor – Mk12

——

#DonLuc #Environment #ESP32 #MQ #GPS #EMF #PIR #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Consultant #Electronics #Microcontrollers #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

PIR Motion Sensor (JST)

SparkFun Item: SEN-13285

This is a simple to use motion sensor. Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room. If anything moves after that period, the ‘alarm’ pin will go low. The alarm pin is an open collector meaning you will need a pull up resistor on the alarm pin. The open drain setup allows multiple motion sensors to be connected on a single input pin. If any of the motion sensors go off, the input pin will be pulled low.

We’ve finally updated the connector! Gone is the old “odd” connector, now you will find a common 3-pin JST! This makes the PIR Sensor much more accessible for whatever your project may need. Red = Power, White = Ground, and Black = Alarm.

DL2006Mk02

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x Telescopic Antenna SMA – 300 MHz to 1.1 GHz (ANT700)
1 x SMA Connector
1 x Humidity and Temperature Sensor – RHT03
1 x PIR Motion Sensor (JST)
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
1 x 200k Ohm
1 x 3.3m Ohm
12 x Jumper Wires 3in M/M
13 x Jumper Wires 6in M/M
20 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A1
MH1 – Analog A0
MC1 – Analog A2
MC2 – Analog A3
MA1 – Analog A4
EMF – Analog A5
GPS – Digital 14
RHT – Digital 15
PIR – Digital 17
VIN – +3.3V
GND – GND

DL2006Mk02p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - PIR Motion Sensor (JST) - Mk12
// 06-02
// DL2006Mk02p.ino 15-12
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 4 x Pololu Carrier for MQ Gas Sensors
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x SparkFun Alcohol Gas Sensor - MQ-3
// 1 x Telescopic Antenna SMA - 300 MHz to 1.1 GHz (ANT700)
// 1 x SMA Connector
// 1 x Humidity and Temperature Sensor - RHT03
// 1 x PIR Motion Sensor (JST)
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 2 x 10K Ohm
// 1 x 20k Ohm
// 1 x 200k Ohm
// 1 x 3.3m Ohm
// 12 x Jumper Wires 3in M/M
// 13 x Jumper Wires 6in M/M
// 20 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>
// RHT Humidity and Temperature Sensor
#include <SparkFun_RHT03.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A4;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// EMF Meter (Single Axis)
int iEMF = A5;
// Raise this number to increase data smoothing
#define NUMREADINGS 15
// Raise this number to decrease sensitivity (up to 1023 max)
int senseLimit = 15;
// EMF Value
int valEMF = 0;
// Readings from the analog input
int readings[ NUMREADINGS ];
// Index of the current reading
int indexEMF = 0;
// Running total
int totalEMF = 0;
// Final average of the probe reading
int averageEMF = 0;
int iEMFDis = 0;
int iEMFRect = 0;

// RHT Humidity and Temperature Sensor
// RHT03 data pin Digital 15
const int RHT03_DATA_PIN = 15;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;
float latestTempF;

// PIR Motion
// Motion detector
const int iMotion = 17;
// Proximity
int proximity = LOW;
String Det = "";

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // EMF Meter (Single Axis)
  isEMF();

  // RHT03 Humidity and Temperature Sensor
  isRHT03();

  // isPIR Motion
  isPIR();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    digitalWrite(iLEDGreen,  LOW );
  
  }

  delay( 1000 );
  
}

getBME280.ino

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
// isBME280 - Temperature, Humidity, 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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,30);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,50);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,70);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,90);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,110);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    display.setCursor(0,130);
    display.println( "BAC MQ3" );
    display.setCursor(0,150);
    display.print( iMQ3ppm );
    display.println( "%" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// EMF Meter (Single Axis)
void isDisplayEMF() {

    // Text Display EMF Meter
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // EMF Meter
    display.setCursor(0,10);
    display.println( "EMF Meter" );
    display.setCursor(0,30);
    display.print( "EMF: " );
    display.println( averageEMF );
    display.setCursor(0,50);
    display.println( iEMFDis );
    display.setCursor(0,70);
    display.setTextSize(1);
    display.println( "0  1 2 3 4 5 6 7 8 9  10" );
    display.setCursor(0,90);
    display.drawRect(0, 90, iEMFRect , display.height(), BLACK);
    display.fillRect(0, 90, iEMFRect , display.height(), BLACK);
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display PIR Motion
void isDisplayPIR() {

    // Text Display PIR
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // PIR Motion
    display.setCursor(0,10);
    display.println( "PIR Motion" );
    display.setCursor(0,30);
    display.println( Det );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display RHT
void isDisplayRHT() {

    // Text Display RHT
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature
    display.setCursor(0,10);
    display.println( "Temp C" );
    display.setCursor(0,30);
    display.print( latestTempC );
    display.println( "C" );
    // Temp F
    display.setCursor(0,60);
    display.println( "Temp F" );
    display.setCursor(0,80);
    display.print( latestTempF );
    display.println( "F" );
    // Humidity
    display.setCursor(0,110);
    display.println( "Humidity" );
    display.setCursor(0,130);
    display.print( latestHumidity );
    display.println( " %" );    
    // 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));
  }
  
}

getEMF.ino

// EMF Meter (Single Axis)
// Setup EMF Meter
void isSetupEMF() {

  // EMF Meter (Single Axis)
  pinMode( iEMF, OUTPUT );
  for (int i = 0; i < NUMREADINGS; i++){
    readings[ i ] = 0;     // Initialize all the readings to 0
  }
  
}
// EMF Meter
void isEMF() {

  // Probe EMF Meter
  // Take a reading from the probe
  valEMF = analogRead( iEMF );

  // If the reading isn't zero, proceed
  if( valEMF >= 1 ){

    // Turn any reading higher than the senseLimit value into the senseLimit value
    valEMF = constrain( valEMF, 1, senseLimit );
    // Remap the constrained value within a 1 to 1023 range
    valEMF = map( valEMF, 1, senseLimit, 1, 1023 );
    
    // Subtract the last reading
    totalEMF -= readings[ indexEMF ];
    // Read from the sensor
    readings[ indexEMF ] = valEMF;
    // Add the reading to the total
    totalEMF += readings[ indexEMF ];
    // Advance to the next index
    indexEMF = ( indexEMF + 1 );
    
    // If we're at the end of the array...
    if ( indexEMF >= NUMREADINGS ) {

      // Wrap around to the beginning
      indexEMF = 0;
      
    }  

    // Calculate the average
    averageEMF = totalEMF / NUMREADINGS;

    iEMFDis = averageEMF;
    iEMFRect = map( averageEMF, 1, 1023, 1, 144 );

  }
  else
  {

    averageEMF = 0;
    
  }
  
}

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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getPIR.ino

// PIR Motion
// Setup PIR
void setupPIR() {

  // Setup PIR Montion
  pinMode(iMotion, INPUT_PULLUP);
  
}
// isPIR Motion
void isPIR() {

  // Proximity
  proximity = digitalRead(iMotion);
  if (proximity == LOW) 
  {

    // PIR Motion Sensor's LOW, Motion is detected
    Det = "Motion Yes";
    
  }
  else
  {

    // PIR Motion Sensor's HIGH
    Det = "No";
    
  }
  
}

getRHT.ino

// RHT03 Humidity and Temperature Sensor
// setup RTH03 Humidity and Temperature Sensor
void setupRTH03() {

  // RHT03 Humidity and Temperature Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT03 Humidity and Temperature Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();
  latestTempF = rht.tempF();
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

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

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // RHT03 Humidity and Temperature Sensor
      isDisplayRHT();
      
      break;
    case 4:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 5:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;       
    case 6:

      // EMF Meter (Single Axis)
      isDisplayEMF();
      
      break; 
    case 7:
         
      // Display PIR Motion
      isDisplayPIR();
      
      break; 
    case 8:

      // Display UID
      isDisplayUID();
      
      break;
    case 9:

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|Latest Temp C|Latest Temp F|Latest Humidity|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7|Alcohol Gas Sensor MQ-3|EMF Meter (Single Axis)|PIR Motion
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + latestTempC + "|" + latestTempF + "|" + latestHumidity + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + iMQ9ppm + "|" + iMQ3ppm + "|" + averageEMF + "|" + Det + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  // EMF Meter (Single Axis) - Setup
  isSetupEMF();

  // RHT03 Humidity and Temperature Sensor
  // setup RTH03 Humidity and Temperature Sensor
  setupRTH03();

  // PIR Motion
  // Setup PIR
  setupPIR();

  delay( 5000 );

}

Technology Experience

  • Single-Board Microcontrollers (Arduino, Raspberry Pi,Espressif, etc…)
  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/luc.paquin/

Don Luc

Project #15: Environment – Humidity and Temperature Sensor – RHT03 – Mk11

——

#DonLuc #Environment #ESP32 #MQ #GPS #EMF #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Consultant #Electronics #Microcontrollers #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

Humidity and Temperature Sensor – RHT03

SparkFun Item: SEN-10167

The RHT03 is a low cost humidity and temperature sensor with a single wire digital interface. The sensor is calibrated and doesn’t require extra components so you can get right to measuring relative humidity and temperature.

DL2006Mk01

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x Telescopic Antenna SMA – 300 MHz to 1.1 GHz (ANT700)
1 x SMA Connector
1 x Humidity and Temperature Sensor – RHT03
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
1 x 200k Ohm
1 x 3.3m Ohm
10 x Jumper Wires 3in M/M
12 x Jumper Wires 6in M/M
20 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A1
MH1 – Analog A0
MC1 – Analog A2
MC2 – Analog A3
MA1 – Analog A4
EMF – Analog A5
GPS – Digital 14
RHT – Digital 15
VIN – +3.3V
GND – GND

DL2006Mk01p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - Humidity and Temperature Sensor - RHT03 - Mk11
// 06-01
// DL2006Mk01p.ino 15-11
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 4 x Pololu Carrier for MQ Gas Sensors
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x SparkFun Alcohol Gas Sensor - MQ-3
// 1 x Telescopic Antenna SMA - 300 MHz to 1.1 GHz (ANT700)
// 1 x SMA Connector
// 1 x Humidity and Temperature Sensor - RHT03
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 2 x 10K Ohm
// 1 x 20k Ohm
// 1 x 200k Ohm
// 1 x 3.3m Ohm
// 10 x Jumper Wires 3in M/M
// 12 x Jumper Wires 6in M/M
// 20 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>
// RHT Humidity and Temperature Sensor
#include <SparkFun_RHT03.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A4;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// EMF Meter (Single Axis)
int iEMF = A5;
// Raise this number to increase data smoothing
#define NUMREADINGS 15
// Raise this number to decrease sensitivity (up to 1023 max)
int senseLimit = 15;
// EMF Value
int valEMF = 0;
// Readings from the analog input
int readings[ NUMREADINGS ];
// Index of the current reading
int indexEMF = 0;
// Running total
int totalEMF = 0;
// Final average of the probe reading
int averageEMF = 0;
int iEMFDis = 0;
int iEMFRect = 0;

// RHT Humidity and Temperature Sensor
// RHT03 data pin Digital 15
const int RHT03_DATA_PIN = 15;
// This creates a RTH03 object, which we'll use to interact with the sensor
RHT03 rht;
float latestHumidity;
float latestTempC;
float latestTempF;

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // EMF Meter (Single Axis)
  isEMF();

  // RHT03 Humidity and Temperature Sensor
  isRHT03();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    digitalWrite(iLEDGreen,  LOW );
  
  }

  delay( 1000 );
  
}

getBME280.ino

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
// isBME280 - Temperature, Humidity, 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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,30);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,50);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,70);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,90);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,110);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    display.setCursor(0,130);
    display.println( "BAC MQ3" );
    display.setCursor(0,150);
    display.print( iMQ3ppm );
    display.println( "%" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// EMF Meter (Single Axis)
void isDisplayEMF() {

    // Text Display EMF Meter
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // EMF Meter
    display.setCursor(0,10);
    display.println( "EMF Meter" );
    display.setCursor(0,30);
    display.print( "EMF: " );
    display.println( averageEMF );
    display.setCursor(0,50);
    display.println( iEMFDis );
    display.setCursor(0,70);
    display.setTextSize(1);
    display.println( "0  1 2 3 4 5 6 7 8 9  10" );
    display.setCursor(0,90);
    display.drawRect(0, 90, iEMFRect , display.height(), BLACK);
    display.fillRect(0, 90, iEMFRect , display.height(), BLACK);
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display RHT
void isDisplayRHT() {

    // Text Display RHT
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Temperature
    display.setCursor(0,10);
    display.println( "Temp C" );
    display.setCursor(0,30);
    display.print( latestTempC );
    display.println( "C" );
    // Temp F
    display.setCursor(0,60);
    display.println( "Temp F" );
    display.setCursor(0,80);
    display.print( latestTempF );
    display.println( "F" );
    // Humidity
    display.setCursor(0,110);
    display.println( "Humidity" );
    display.setCursor(0,130);
    display.print( latestHumidity );
    display.println( " %" );    
    // 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));
  }
  
}

getEMF.ino

// EMF Meter (Single Axis)
// Setup EMF Meter
void isSetupEMF() {

  // EMF Meter (Single Axis)
  pinMode( iEMF, OUTPUT );
  for (int i = 0; i < NUMREADINGS; i++){
    readings[ i ] = 0;     // Initialize all the readings to 0
  }
  
}
// EMF Meter
void isEMF() {

  // Probe EMF Meter
  // Take a reading from the probe
  valEMF = analogRead( iEMF );

  // If the reading isn't zero, proceed
  if( valEMF >= 1 ){

    // Turn any reading higher than the senseLimit value into the senseLimit value
    valEMF = constrain( valEMF, 1, senseLimit );
    // Remap the constrained value within a 1 to 1023 range
    valEMF = map( valEMF, 1, senseLimit, 1, 1023 );
    
    // Subtract the last reading
    totalEMF -= readings[ indexEMF ];
    // Read from the sensor
    readings[ indexEMF ] = valEMF;
    // Add the reading to the total
    totalEMF += readings[ indexEMF ];
    // Advance to the next index
    indexEMF = ( indexEMF + 1 );
    
    // If we're at the end of the array...
    if ( indexEMF >= NUMREADINGS ) {

      // Wrap around to the beginning
      indexEMF = 0;
      
    }  

    // Calculate the average
    averageEMF = totalEMF / NUMREADINGS;

    iEMFDis = averageEMF;
    iEMFRect = map( averageEMF, 1, 1023, 1, 144 );

  }
  else
  {

    averageEMF = 0;
    
  }
  
}

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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

getRHT.ino

// RHT03 Humidity and Temperature Sensor
// setup RTH03 Humidity and Temperature Sensor
void setupRTH03() {

  // RHT03 Humidity and Temperature Sensor
  // Call rht.begin() to initialize the sensor and our data pin
  rht.begin(RHT03_DATA_PIN);
  
}
// RHT03 Humidity and Temperature Sensor
void isRHT03(){

  // Call rht.update() to get new humidity and temperature values from the sensor.
  int updateRet = rht.update();

  // The humidity(), tempC(), and tempF() functions can be called -- after 
  // a successful update() -- to get the last humidity and temperature value 
  latestHumidity = rht.humidity();
  latestTempC = rht.tempC();
  latestTempF = rht.tempF();
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

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

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // RHT03 Humidity and Temperature Sensor
      isDisplayRHT();
      
      break;
    case 4:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 5:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;       
    case 6:

      // EMF Meter (Single Axis)
      isDisplayEMF();
      
      break; 
    case 7:
         
      // Display UID
      isDisplayUID();
      
      break; 
    case 8:

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

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|Latest Temp C|Latest Temp F|Latest Humidity|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7|Alcohol Gas Sensor MQ-3|EMF Meter (Single Axis)
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + latestTempC + "|" + latestTempF + "|" + latestHumidity + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + iMQ9ppm + "|" + iMQ3ppm + "|" + averageEMF + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  // EMF Meter (Single Axis) - Setup
  isSetupEMF();

  // RHT03 Humidity and Temperature Sensor
  // setup RTH03 Humidity and Temperature Sensor
  setupRTH03();

  delay( 5000 );

}

Technology Experience

  • Single-Board Microcontrollers (Arduino, Raspberry Pi,Espressif, etc…)
  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/luc.paquin/

Don Luc

Project #15: Environment – EMF Meters – Mk10

——

#DonLuc #Environment #Microcontrollers #EMF #ESP32 #MQ #GPS #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Electronics #Consultant #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

DL2005Mk012

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x Telescopic Antenna SMA – 300 MHz to 1.1 GHz (ANT700)
1 x SMA Connector
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
1 x 200k Ohm
1 x 3.3m Ohm
10 x Jumper Wires 3in M/M
10 x Jumper Wires 6in M/M
18 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A1
MH1 – Analog A0
MC1 – Analog A2
MC2 – Analog A3
MA1 – Analog A4
EMF – Analog A5
GPS – Digital 14
VIN – +3.3V
GND – GND

DL2005Mk12p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - EMF Meters - Mk10
// 05-12
// DL2005Mk12p.ino 15-10
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 4 x Pololu Carrier for MQ Gas Sensors
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x SparkFun Alcohol Gas Sensor - MQ-3
// 1 x Telescopic Antenna SMA - 300 MHz to 1.1 GHz (ANT700)
// 1 x SMA Connector
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 1 x 10K Ohm
// 1 x 20K Ohm
// 1 x 200k Ohm
// 1 x 3.3m Ohm
// 10 x Jumper Wires 3in M/M
// 10 x Jumper Wires 6in M/M
// 18 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A4;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

// EMF Meter (Single Axis)
int iEMF = A5;
// Raise this number to increase data smoothing
#define NUMREADINGS 15
// Raise this number to decrease sensitivity (up to 1023 max)
int senseLimit = 15;
// EMF Value
int valEMF = 0;
// Readings from the analog input
int readings[ NUMREADINGS ];
// Index of the current reading
int indexEMF = 0;
// Running total
int totalEMF = 0;
// Final average of the probe reading
int averageEMF = 0;
int iEMFDis = 0;
int iEMFRect = 0;

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // EMF Meter (Single Axis)
  isEMF();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    digitalWrite(iLEDGreen,  LOW );
  
  }

  delay( 1000 );
  
}

getBME280.ino

// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
// isBME280 - Temperature, Humidity, 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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas Sensors" );
    display.setCursor(0,30);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,50);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,70);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,90);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,110);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,130);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    display.setCursor(0,150);
    display.println( "BAC MQ3" );
    display.setCursor(0,170);
    display.print( iMQ3ppm );
    display.println( "%" );
    // Refresh
    display.refresh();
    delay( 100 );

}
// EMF Meter (Single Axis)
void isDisplayEMF() {

    // Text Display EMF Meter
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // EMF Meter
    display.setCursor(0,10);
    display.println( "EMF Meter" );
    display.setCursor(0,30);
    display.print( "EMF: " );
    display.println( averageEMF );
    display.setCursor(0,50);
    display.println( iEMFDis );
    display.setCursor(0,70);
    display.setTextSize(1);
    display.println( "0  1 2 3 4 5 6 7 8 9  10" );
    display.setCursor(0,90);
    display.drawRect(0, 90, iEMFRect , display.height(), BLACK);
    display.fillRect(0, 90, iEMFRect , display.height(), BLACK);
    // 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));
  }
  
}

getEMF.ino

// EMF Meter (Single Axis)
// Setup EMF Meter
void isSetupEMF() {

  // EMF Meter (Single Axis)
  pinMode( iEMF, OUTPUT );
  for (int i = 0; i < NUMREADINGS; i++){
    readings[ i ] = 0;     // Initialize all the readings to 0
  }
  
}
// EMF Meter
void isEMF() {

  // Probe EMF Meter
  // Take a reading from the probe
  valEMF = analogRead( iEMF );

  // If the reading isn't zero, proceed
  if( valEMF >= 1 ){

    // Turn any reading higher than the senseLimit value into the senseLimit value
    valEMF = constrain( valEMF, 1, senseLimit );
    // Remap the constrained value within a 1 to 1023 range
    valEMF = map( valEMF, 1, senseLimit, 1, 1023 );
    
    // Subtract the last reading
    totalEMF -= readings[ indexEMF ];
    // Read from the sensor
    readings[ indexEMF ] = valEMF;
    // Add the reading to the total
    totalEMF += readings[ indexEMF ];
    // Advance to the next index
    indexEMF = ( indexEMF + 1 );
    
    // If we're at the end of the array...
    if ( indexEMF >= NUMREADINGS ) {

      // Wrap around to the beginning
      indexEMF = 0;
      
    }  

    // Calculate the average
    averageEMF = totalEMF / NUMREADINGS;

    iEMFDis = averageEMF;
    iEMFRect = map( averageEMF, 1, 1023, 1, 144 );

  }
  else
  {

    averageEMF = 0;
    
  }
  
}

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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * 3.3 / 4095;

  double bac = RvRo * 0.21;
  return bac;
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

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

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 4:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;
    case 5:

      // EMF Meter (Single Axis)
      isDisplayEMF();
      
      break;       
    case 6:

      // Display UID
      isDisplayUID();
      
      break; 
    case 7:
         
      // Z
      isDisplayZ();
      
      break; 
    case 8:

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

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7|Alcohol Gas Sensor MQ-3|EMF Meter (Single Axis)
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + iMQ9ppm + "|" + iMQ3ppm + "|" + averageEMF + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  // EMF Meter (Single Axis) - Setup
  isSetupEMF();

  delay( 5000 );

}

Technology Experience

  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/luc.paquin/

Don Luc

Project #15: Environment – SparkFun Alcohol Gas Sensor – MQ-3 – Mk09

——

#DonLuc #Environment #Microcontrollers #ESP32 #MQ #GPS #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Electronics #Consultant #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

DL2005Mk010

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
4 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x SparkFun Alcohol Gas Sensor – MQ-3
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
1 x 220k Ohm
10 x Jumper Wires 3in M/M
10 x Jumper Wires 6in M/M
16 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A1
MH1 – Analog A0
MC1 – Analog A2
MC2 – Analog A3
MA1 – Analog A4
GPS – Digital 14
VIN – +3.3V
GND – GND

DL2005Mk10p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - SparkFun Alcohol Gas Sensor - MQ-3 - Mk09
// 05-09
// DL2005Mk10p.ino 15-09
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 4 x Pololu Carrier for MQ Gas Sensors
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x SparkFun Alcohol Gas Sensor - MQ-3
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 1 x 10K Ohm
// 1 x 20K Ohm
// 1 x 220k Ohm
// 10 x Jumper Wires 3in M/M
// 10 x Jumper Wires 6in M/M
// 16 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;
// Alcohol Gas Sensor - MQ-3
int iMQ3 = A4;
int iMQ3Raw = 0;
int iMQ3ppm = 0;

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,30);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,50);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,70);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,90);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,110);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    display.setCursor(0,130);
    display.println( "BAC MQ3" );
    display.setCursor(0,150);
    display.print( iMQ3ppm );
    display.println( "%" );
    // 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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );

  // Alcohol Gas Sensor - MQ-3
  iMQ3Raw = analogRead( iMQ3 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9ppm = isMQ9( iMQ9Raw ); 

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7ppm = isMQ7( iMQ7Raw ); 

  // Alcohol Gas Sensor - MQ-3
  iMQ3ppm = isMQ3( iMQ3Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int isMQ9(double rawValue) {

  double RvRo = rawValue * (3.3 / 4095);

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7(double rawValue) {

  double RvRo = rawValue * (3.3 / 4095);

  double ppm = 3.027*exp(1.0698*( RvRo ));
  return ppm;
  
}
// Alcohol Gas Sensor - MQ-3
int isMQ3(double rawValue) {

  double RvRo = rawValue * (3.3 / 4095);

  double bac = RvRo * 0.21;
  return bac;
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

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

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 4:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;
    case 5:

      // Display UID
      isDisplayUID();
      
      break;       
    case 6:

      // Z
      isDisplayZ();
      
      break; 
    case 7:
         
      // Z
      isDisplayZ();
      
      break; 
    case 8:

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

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7|Alcohol Gas Sensor MQ-3
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|" + iMQ9ppm + "|" + iMQ3ppm + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  delay( 5000 );

}

Technology Experience

  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/

Don Luc

Project #15: Environment – SparkFun Carbon Monoxide Gas Sensor – MQ-7 – Mk08

——

#DonLuc #Environment #Microcontrollers #ESP32 #MQ-X #GPS #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Electronics #Consultant #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

DL2005Mk08

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
3 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x SparkFun Carbon Monoxide Gas Sensor – MQ-7
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
2 x 10K Ohm
1 x 20k Ohm
8 x Jumper Wires 3in M/M
9 x Jumper Wires 6in M/M
16 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A0
MH1 – Analog A1
MC1 – Analog A2
MC2 – Analog A3
GPS – Digital 14
VIN – +3.3V
GND – GND

DL2005Mk08p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - SparkFun Carbon Monoxide Gas Sensor - MQ-7 - Mk08
// 05-08
// DL2005Mk08p.ino 15-08
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 3 x Pololu Carrier for MQ Gas Sensors
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x SparkFun Carbon Monoxide Gas Sensor - MQ-7
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 1 x 10K Ohm
// 1 x 20K Ohm
// 8 x Jumper Wires 3in M/M
// 9 x Jumper Wires 6in M/M
// 16 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;
// Carbon Monoxide Gas Sensor - MQ-7
int iMQ7 = A3;
int iMQ7Raw = 0;
int iMQ7ppm = 0;

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas Sensors" );
    display.setCursor(0,30);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,50);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,70);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,90);
    display.print( iMQ9ppm );
    display.println( " ppm" );
    display.setCursor(0,110);
    display.println( "Gas CO MQ7" );
    display.setCursor(0,130);
    display.print( iMQ7ppm );
    display.println( " ppm" );
    // 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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );  

  // Carbon Monoxide Gas Sensor - MQ-7
  iMQ7Raw = analogRead( iMQ7 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  isMQ8(); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  isMQ9(); 

  // Carbon Monoxide Gas Sensor - MQ-7
  isMQ7(); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
void isMQ8() {

  double RvRo = iMQ8Raw * (3.3 / 1023);

  iMQ8ppm = (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
void isMQ9() {

  double RvRo = iMQ9Raw * (3.3 / 4095);

  iMQ9ppm = 3.027*exp(1.0698*( RvRo ));
  
}
// Carbon Monoxide Gas Sensor - MQ-7
int isMQ7() {

  double RvRo = iMQ7Raw * (3.3 / 4095);

  iMQ7ppm = 3.027*exp(1.0698*( RvRo ));
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);
  
  // Range Value
  switch ( iRotVal ) {
    case 0:

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 4:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;
    case 5:

      // Display UID
      isDisplayUID();
      
      break;       
    case 6:

      // Z
      isDisplayZ();
      
      break; 
    case 7:
         
      // Z
      isDisplayZ();
      
      break; 
    case 8:

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

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9|CO Gas Sensor MQ-7
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|" + iMQ9ppm + "|" + iMQ7ppm + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  delay( 5000 );

}

Technology Experience

  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/

Don Luc

Project #15: Environment – Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9 – Mk07

——

#DonLuc #Environment #Microcontrollers #ESP32 #MQ-X #GPS #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Electronics #Consultant #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

Environment

——

DL2005Mk06

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
2 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Pololu Carbon Monoxide & Flammable Gas Sensor – MQ-9
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
1 x 10K Ohm
1 x 20k Ohm
6 x Jumper Wires 3in M/M
8 x Jumper Wires 6in M/M
16 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x DC Power Supply

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A0
MH1 – Analog A1
MC1 – Analog A2
GPS – Digital 14
VIN – +3.3V
GND – GND

DL2005Mk06p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9 - Mk07
// 05-06
// DL2005Mk06p.ino 15-07
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 2 x Pololu Carrier for MQ Gas Sensors
// 1 x Pololu Carbon Monoxide & Flammable Gas Sensor - MQ-9
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 1 x 10K Ohm
// 1 x 20K Ohm
// 6 x Jumper Wires 3in M/M
// 8 x Jumper Wires 6in M/M
// 16 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x DC Power Supply

// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
int iMQ9 = A2;
int iMQ9Raw = 0;
int iMQ9ppm = 0;

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,10);
    display.println( "Gas Sensors" );
    display.setCursor(0,30);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,50);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    display.setCursor(0,70);
    display.println( "Gas CO MQ9" );
    display.setCursor(0,90);
    display.print( iMQ9ppm );
    display.println( " ppm" );    
    // 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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  iMQ9Raw = analogRead( iMQ9 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  isMQ8(); 

  // Carbon Monoxide & Flammable Gas Sensor - MQ-9
  isMQ9();
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
void isMQ8() {

  // RvRo
  double RvRo = iMQ8Raw * (3.3 / 1023);

  iMQ8ppm = (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}
// Carbon Monoxide & Flammable Gas Sensor - MQ-9
void isMQ9() {

  double RvRo = iMQ9Raw * (3.3 / 4095);

  iMQ9ppm = 3.027*exp(1.0698*( RvRo ));
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

getRot.ino

// Rotary Switch
// isRot - iRotVal - Value
void isRot() {

  // Rotary Switch
  z = analogRead( iRotNum );
  x = map(z, 0, 4095, 0, 9);
  iRotVal = map(z, 0, 4095, 0, 10);

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

      // Display Environmental
      isDisplayEnvironmental();
      
      break;
    case 1:

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

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 3:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 4:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;
    case 5:

      // Display UID
      isDisplayUID();
      
      break;       
    case 6:

      // Z
      isDisplayZ();
      
      break; 
    case 7:
         
      // Z
      isDisplayZ();
      
      break; 
    case 8:

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

      // Z
      isDisplayZ();
      
      break;
    default:

      // 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();

    if(cardType == CARD_NONE){
        ; 
        return;
    }

    //Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

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

  zzzzzz = "";

  // EEPROM Unique ID|Version|Date|Time|GPS Status|Target Latitude|Target Longitude|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8|CO Gas Sensor MQ-9
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + + "|" + iMQ9ppm + "|\r";

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

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

  appendFile(SD, "/espdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    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){
    
    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){
    
    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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  delay( 5000 );

}

Technology Experience

  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/

Don Luc

Project #15: Environment – SparkFun Hydrogen Gas Sensor – MQ-8 – Mk06

——

#DonLuc #Environment #Microcontrollers #ESP32 #MQ-8 #GPS #SparkFun #Adafruit #Pololu #Fritzing #Programming #Arduino #Electronics #Consultant #Vlog #Aphasia

——

Environment

——

Environment

——

Environment

——

DL2005Mk04

1 x SparkFun Thing Plus – ESP32 WROOM
1 x Adafruit SHARP Memory Display
1 x SparkFun Environmental Combo Breakout – CCS811/BME280
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x SparkFun GPS Receiver – GP-20U7
1 x CR1220 12mm Lithium Battery
1 x 32Gb microSD Card
1 x Mountable Slide Switch
1 x SparkFun Rotary Switch – 10 Position
1 x Black Knob
1 x Breadboard Solderable
1 x Pololu Adjustable Boost Regulator 2.5-9.5V
1 x Pololu Carrier for MQ Gas Sensors
1 x SparkFun Hydrogen Gas Sensor – MQ-8
1 x Qwiic Cable – 100mm
1 x LED Green
11 x 1K Ohm
1 x 4.7K Ohm
1 x 10K Ohm
4 x Jumper Wires 3in M/M
8 x Jumper Wires 6in M/M
16 x Wire Solid Core – 22 AWG
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable

SparkFun Thing Plus – ESP32 WROOM

LEG – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
SD1 – Digital 33
SC2 – Digital 5
MO2 – Digital 18
MI2 – Digital 19
SS1 – Digital 16
ROT – Analog A0
MH1 – Analog A1
GPS – Digital 14
VIN – +3.3V
GND – GND

DL2005Mk04p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #15: Environment - SparkFun Hydrogen Gas Sensor - MQ-8 - Mk06
// 05-04
// DL2005Mk04p.ino 15-06
// EEPROM with Unique ID
// 1 x SparkFun Thing Plus - ESP32 WROOM
// 1 x Adafruit SHARP Memory Display
// 1 x SparkFun Environmental Combo Breakout - CCS811/BME280
// 1 x Adafruit Adalogger FeatherWing - RTC + SD
// 1 x SparkFun GPS Receiver - GP-20U7
// 1 x CR1220 12mm Lithium Battery
// 1 x 32Gb microSD Card
// 1 x Mountable Slide Switch
// 1 x SparkFun Rotary Switch - 10 Position
// 1 x Black Knob
// 1 x Breadboard Solderable
// 1 x Pololu Adjustable Boost Regulator 2.5-9.5V
// 1 x Pololu Carrier for MQ Gas Sensors
// 1 x SparkFun Hydrogen Gas Sensor - MQ-8
// 1 x Qwiic Cable - 100mm
// 1 x LED Green
// 11 x 1K Ohm
// 1 x 4.7K Ohm
// 1 x 10K Ohm
// 4 x Jumper Wires 3in M/M
// 8 x Jumper Wires 6in M/M
// 16 x Wire Solid Core - 22 AWG
// 2 x Full-Size Breadboard
// 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>
// SparkFun CCS811 - eCO2 & tVOC
#include <SparkFunCCS811.h>
// SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
#include <SparkFunBME280.h>
// Date and Time
#include "RTClib.h"
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// GPS Receiver
#include <TinyGPS++.h>
// Hardware Serial
#include <HardwareSerial.h>

// LED Green
int iLEDGreen = 21;

// SHARP Memory Display
// any pins can be used
#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   27
// Set the size of the display here - 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
// 1/2 of lesser of display width or height
int minorHalfSize; 

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

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

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

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

// Mountable Slide Switch
int iSS1 = 16;
// State
int iSS1State = 0;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 14
// This one is unused and doesnt have a conection
#define gpsTXPIN 32
// The TinyGPS++ object
TinyGPSPlus gps;
float TargetLat;
float TargetLon;
int GPSStatus = 0;

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

// Gas Sensors MQ
// Hydrogen Gas Sensor - MQ-8
int iMQ8 = A1;
int iMQ8Raw = 0;
int iMQ8ppm = 0;
// Two points are taken from the curve in datasheet
// With these two points, a line is formed which is "approximately equivalent" to the original curve
float H2Curve[3] = {2.3, 0.93,-1.44};

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

void loop() {

  // Receives NEMA data from GPS receiver
  isGPS();
  
  // Date and Time 
  isRTC();
  
  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  isBME280();

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

  // Gas Sensors MQ
  isGasSensor();

  // 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
    digitalWrite(iLEDGreen,  HIGH );
    
    // microSD Card
    isSD();

  } else {

    // iLEDGreen
    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

// 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,100);   
    display.println( sver );
    // EEPROM Unique ID
    display.setTextSize(1);
    display.setCursor(0,130);
    display.println( "EEPROM Unique ID" );
    display.setTextSize(2);
    display.setCursor(0,145);
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Display Environmental
void isDisplayEnvironmental(){

    // Text Display Environmental
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(1);
    display.setTextColor(BLACK);
    // Temperature Celsius
    display.setCursor(0,0);
    display.println( "Temperature Celsius" );
    display.setCursor(0,10);
    display.print( BMEtempC );
    display.println( " C" );
    // Humidity
    display.setCursor(0,20);
    display.println( "Humidity" );
    display.setCursor(0,30);
    display.print( BMEhumid );
    display.println( "%" );
    // Altitude Meters
    display.setCursor(0,40);
    display.println( "Altitude Meters" );
    display.setCursor(0,50);
    display.print( BMEaltitudeM );
    display.println( " m" );
    // Pressure
    display.setCursor(0,60);    
    display.println( "Barometric Pressure" );
    display.setCursor(0,70);
    display.print( BMEpressure );
    display.println( " Pa" );
    // eCO2 Concentration
    display.setCursor(0,80);
    display.println( "eCO2 Concentration" );
    display.setCursor(0,90);
    display.print( CCS811CO2 );
    display.println( " ppm" );
    // tVOC Concentration
    display.setCursor(0,100);
    display.println( "tVOC Concentration" );
    display.setCursor(0,110);
    display.print( CCS811TVOC );
    display.println( " ppb" );
    // Date
    display.setCursor(0,120);
    display.println( dateRTC );
    // Time
    display.setCursor(0,130);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,140);
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,150);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,160);
    display.println( TargetLon );
    // 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( dateRTC );
    // Time
    display.setCursor(0,30);
    display.println( timeRTC );
    // GPS Status
    display.setCursor(0,60);
    display.print( "GPS: " );
    display.println( GPSStatus );
    // Target Latitude
    display.setCursor(0,80);
    display.println( "Latitude" );
    display.setCursor(0,100);
    display.println( TargetLat );
    // Target Longitude
    display.setCursor(0,120);
    display.println( "Longitude" );
    display.setCursor(0,140);
    display.println( TargetLon );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display BME280
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 Gas Sensors MQ
void isDisplayMQ() {

    // Text Display MQ
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Gas Sensors MQ
    display.setCursor(0,5);
    display.println( "Gas H2 MQ8" );
    display.setCursor(0,25);
    display.print( iMQ8ppm );
    display.println( " ppm" );
    // 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() ))
    {
     displayInfo();
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    while(true);
  }

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

  // Location
  if (gps.location.isValid())
  {
    
    TargetLat = gps.location.lat();
    TargetLon = gps.location.lng();
    GPSStatus = 2;
    
  }
  else
  {

    GPSStatus = 0;
    
  }

}

getGasSensorMQ.ino

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

  // Read in analog value from each gas sensors
  
  // Hydrogen Gas Sensor - MQ-8
  iMQ8Raw = analogRead( iMQ8 );
  
  // Caclulate the PPM of each gas sensors

  // Hydrogen Gas Sensor - MQ-8
  iMQ8ppm = isMQ8( iMQ8Raw ); 
  
}
// Hydrogen Gas Sensor - MQ-8 - PPM
int isMQ8(double rawValue) {

  // RvRo
  double RvRo = rawValue * (3.3 / 1023);

  return (pow(4.7,( ((log(RvRo)-H2Curve[1])/H2Curve[2]) + H2Curve[0])));
  
}

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(2018, 9, 29, 12, 17, 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;
  
}

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 Environmental
      isDisplayEnvironmental();
      
      break;
    case 2:

      // Display Date
      isDisplayDate();
      
      break;
    case 3:

      // Display BME280
      isDisplayBME280();
      
      break;  
    case 4:

      // Display CCS811 - eCO2 & tVOC
      isDisplayCCS811();
      
      break;
    case 5:

      // Display Gas Sensors MQ
      isDisplayMQ();
      
      break;
    case 6:

      // Display UID
      isDisplayUID();
      
      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|Temperature Celsius|Humidity|Altitude Meters|Barometric Pressure|eCO2 Concentration|tVOC Concentration|H2 Gas Sensor MQ-8
  zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + GPSStatus + "|" + TargetLat + "|" + TargetLon + "|" + BMEtempC + "|" + BMEhumid + "|" + BMEaltitudeM + "|" + BMEpressure + "|" + CCS811CO2 + "|" + CCS811TVOC + "|" + iMQ8ppm + "|\r";

  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();
  
  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();
  
  // Display UID
  isDisplayUID();

  // Wire - Inialize I2C Hardware
  Wire.begin();

  // SparkFun BME280 - Humidity, Temperature, Altitude and Barometric Pressure
  myBME280.begin();
  
  // CCS811 - eCO2 & tVOC
  myCCS811.begin();

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

  // Date & Time RTC
  // PCF8523 Precision RTC 
  setupRTC();
  
  // Date & Time
  isRTC();
  
  // microSD Card
  setupSD();

  // Slide Switch
  pinMode(iSS1, INPUT);

  delay( 5000 );

}

Technology Experience

  • 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

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

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
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/

Don Luc

Categories
Archives