Project #11: ESP32 Feather – RTC + SD – Mk05
ESP32 Feather – RTC + SD – Mk05
——
——
——
——
——
Adafruit Adalogger FeatherWing – RTC + SD
A Feather board without ambition is a Feather board without FeatherWings! This is the Adalogger FeatherWing: it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board.
DonLuc1909Mk02
1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x Adafruit Adalogger FeatherWing – RTC + SD
1 x CR1220 12mm Lithium Battery
1 x 8Gb Micro SD Card
1 x RHT03 Humidity and Temperature Sensor
1 x LED Green
1 x 100 Ohm
14 x Jumper Wires 3″ M/M
6 x Jumper Wires 6″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
Adafruit HUZZAH32 ESP32 Feather
LG1 – Digital 21
RHT – Digital 17
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
GND – GND
VIN – +3.3V
DL1909Mk02.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - Mk05 // 09-02 // DL1909Mk02p.ino 11-05 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // Adalogger FeatherWing - RTC + SD // EEPROM // RHT03 Humidity and Temperature Sensor // include Library Code // SHARP Memory Display #include <Adafruit_SharpMem.h> #include <Adafruit_GFX.h> // Date and Time #include "RTClib.h" // EEPROM library to read EEPROM with unique ID for unit #include "EEPROM.h" // RHT Humidity and Temperature Sensor #include <SparkFun_RHT03.h> // SD Card #include "FS.h" #include "SD.h" #include "SPI.h" // 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, 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 int minorHalfSize; // 1/2 of lesser of display width or height // LED Green int iLEDGreen = 21; // LED Green // PCF8523 Precision RTC RTC_PCF8523 rtc; String dateRTC = ""; String timeRTC = ""; // The current address in the EEPROM (i.e. which byte // we're going to read to next) #define EEPROM_SIZE 64 String sver = "9-2.p"; // Unit ID information String uid = ""; // RHT Humidity and Temperature Sensor const int RHT03_DATA_PIN = 17; // RHT03 data pin Digital 17 RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor float latestHumidity; float latestTempC; float latestTempF; // SD Card const int chipSelect = 33; // SD Card String zzzzzz = ""; void loop() { // iLEDGreen digitalWrite(iLEDGreen, HIGH ); // Date and Time isRTC(); // RHT03 Humidity and Temperature Sensor isRHT03(); // SHARP Memory Display On isDisplayOn(); // SD Card isSD(); // iLEDGreen digitalWrite(iLEDGreen, LOW ); // Delay 1 delay( 10000 ); }
getDisplay.ino
// SHARP Memory Display On void isDisplayOn() { // Clear Display display.clearDisplay(); // text display date, time, LED on display.setRotation(4); display.setTextSize(2); display.setTextColor(BLACK); display.setCursor(0,10); display.println( dateRTC ); display.setCursor(0,30); display.println( timeRTC ); display.setTextSize(2); display.setCursor(0,55); display.print("Hum: "); display.print( latestHumidity ); display.println("%"); display.setCursor(0,75); display.print("Cel: "); display.print( latestTempC ); display.println("*C"); display.setCursor(0,95); display.print("Fah: "); display.print( latestTempF ); display.println("*F"); display.refresh(); } // SHARP Memory Display - UID void isDisplayUID() { // text display EEPROM display.setRotation(4); display.setTextSize(2); display.setTextColor(BLACK); display.setCursor(0,20); display.print( "UID: " ); display.println( uid ); // display.setTextSize(); display.setTextColor(BLACK); display.setCursor(0,45); display.print( "VER: "); display.println( sver ); display.refresh(); delay( 100 ); }
getEEPROM.ino
// EEPROM void GetUID() { // Get unit ID uid = ""; for (int x = 0; x < 5; x++) { uid = uid + char(EEPROM.read(x)); } }
getRHT.ino
// 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(); }
getRTCpcf8523.ino
// PCF8523 Precision RTC void setupRTC() { // 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 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; }
getSD.ino
// SD Card void setupSD() { // SD 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); } // SD Card void isSD() { zzzzzz = ""; zzzzzz = uid + "|" + sver + "|" + dateRTC + "|" + timeRTC + "|" + latestHumidity + "|" + latestTempC + "|" + latestTempF + "|\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){ //Serial.printf("Appending to file: %s\n", path); path; File file = fs.open(path, FILE_APPEND); if(!file){ return; } if(file.print(message)){ ; } else { ; } file.close(); }
setup.ino
// Setup void setup() { // EEPROM with unique ID EEPROM.begin(EEPROM_SIZE); // Get Unit ID GetUID(); // SHARP Display start & clear the display display.begin(); display.clearDisplay(); isDisplayUID(); delay( 5000 ); // Initialize the LED Green pinMode(iLEDGreen, OUTPUT); // PCF8523 Precision RTC setupRTC(); // Date and Time RTC isRTC(); // RHT03 Humidity and Temperature Sensor // Call rht.begin() to initialize the sensor and our data pin rht.begin(RHT03_DATA_PIN); // SD Card setupSD(); }
Follow Us
Web: https://www.donluc.com/
Web: http://neosteamlabs.com/
Web: http://www.jlpconsultants.com/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Facebook: https://www.facebook.com/neosteam.labs.9/
Instagram: https://www.instagram.com/neosteamlabs/
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Twitter: https://twitter.com/labs_steam
Etsy: https://www.etsy.com/shop/NeoSteamLabs
Don Luc
Leave a Reply