Program
Project #11: ESP32 Feather – Rocker Switches – Mk06
ESP32 Feather – Rocker Switches
——
——
——
——
——
——
Rocker Switch – Round
These panel-mounting rocker switches simple SPST on-off. They mount into a 20.2mm diameter hole and are rated up to 16A @ 12v.
DonLuc1909Mk03
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 Rocker Switches
1 x 100 Ohm
1 x 10K 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
RO1 – Digital 16
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
DL1909Mk03.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - Rocker Switches - Mk06 // 09-03 // DL1909Mk03p.ino 11-06 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // Adalogger FeatherWing - RTC + SD // EEPROM // RHT03 Humidity and Temperature Sensor // Rocker Switches // 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-3.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 = ""; // Rocker Switches int iRow1 = 16; // Rocker Switches int iRow1State = 0; // Variable for reading the pushbutton status void loop() { // Date and Time isRTC(); // RHT03 Humidity and Temperature Sensor isRHT03(); // SHARP Memory Display On isDisplayOn(); // Rocker Switched // Read the state of the iRow1 value iRow1State = digitalRead(iRow1); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (iRow1State == HIGH) { // iLEDGreen digitalWrite(iLEDGreen, HIGH ); // SD Card isSD(); } else { // iLEDGreen digitalWrite(iLEDGreen, LOW ); } // Delay delay( 1000 ); }
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(); // Rocker Switches pinMode(iRow1, INPUT); }
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
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
Project #11: ESP32 Feather – RHT03 – Mk04
Humidity and Temperature Sensor
——
——
——
——
——
——
RHT03 – Humidity and Temperature Sensor
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.
DonLuc1909Mk01
1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x Adafruit DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Lithium Battery
1 x RHT03 Humidity and Temperature Sensor
1 x LED Green
1 x 100 Ohm
14 x Jumper Wires 3″ M/M
2 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
GND – GND
VIN – +3.3V
DL1909Mk01.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - Mk04 // 09-01 // DonLuc1909Mk01p.ino 11-04 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // DS3231 Precision RTC // EEPROM // RHT03 Humidity and Temperature Sensor // include Library Code #include <Adafruit_SharpMem.h> #include <Adafruit_GFX.h> #include <RTClib.h> #include <Wire.h> #include "EEPROM.h" #include <SparkFun_RHT03.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 // DS3231 Precision RTC RTC_DS3231 RTC; String sDate; String sTime; // The current address in the EEPROM (i.e. which byte // we're going to read to next) #define EEPROM_SIZE 64 String sver = "9-1.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; void loop() { // iLEDGreen digitalWrite(iLEDGreen, HIGH ); // DS3231 Precision RTC timeRTC(); // RHT03 Humidity and Temperature Sensor isRHT03(); // SHARP Memory Display On isDisplayOn(); // iLEDGreen digitalWrite(iLEDGreen, LOW ); // Delay 1 delay( 1000 ); }
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( sDate ); display.setCursor(0,30); display.println( sTime ); 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(3); display.setTextColor(BLACK); display.setCursor(0,20); display.println( sver ); // display.setTextSize(); display.setTextColor(BLACK); display.setCursor(0,65); display.println( uid ); 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(); }
getRTCDS3231.ino
// DS3231 Precision 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__))); } } // timeRTC void timeRTC() { // DS3231 Precision RTC sDate = ""; sTime = ""; 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() { // 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); // DS3231 Precision RTC setupRTC(); // DS3231 Precision RTC timeRTC(); // RHT03 Humidity and Temperature Sensor // Call rht.begin() to initialize the sensor and our data pin rht.begin(RHT03_DATA_PIN); }
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
Project #11: ESP32 Feather – DS3231 Precision RTC – Mk03
Adafruit HUZZAH32 ESP32 Feather
——
——
——
——
——
——
Adafruit 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 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.
With a CR1220 12mm lithium battery plugged into the top of the FeatherWing, you can get years of precision timekeeping, even when main power is lost. Great for datalogging and clocks, or anything where you need to really know the time.
DonLuc1908Mk03
1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x Adafruit DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Lithium Battery
1 x LED Green
1 x Push Button
1 x 100 Ohm
1 x 10K Ohm
14 x Jumper Wires 3″ M/M
2 x Jumper Wires 6″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
Adafruit HUZZAH32 ESP32 Feather
LG1 – Digital 21
PB1 – Digital 17
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
SDA – Digital 23
SCL – Digital 22
GND – GND
VIN – +3.3V
DL1908Mk03p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - DS3231 Precision RTC - Mk03 // 08-03 // DonLuc1908Mk03p.ino 08-03 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // Push Button // DS3231 Precision RTC // include Library Code #include <Adafruit_SharpMem.h> #include <Adafruit_GFX.h> #include <RTClib.h> #include <Wire.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 int stateLEDGreen = LOW; // stateLEDGreen // Button int iBut1 = 17; // Button 1 int ButState1; // Variable for reading the button status int previous = LOW; // previous long lTime = 0; // lTime long debounce = 500; // debounce // DS3231 Precision RTC RTC_DS3231 RTC; String sDate; String sTime; void loop() { // Read the state of the button value ButState1 = digitalRead(iBut1); // Check if the button is pressed if (ButState1 == HIGH && previous == LOW && millis() - lTime > debounce) { if(stateLEDGreen == HIGH) { // stateLEDGreen = LOW stateLEDGreen = LOW; // DS3231 Precision RTC timeRTC(); // SHARP Memory Display Off isDisplayOff(); } else { // stateLEDGreen = HIGH stateLEDGreen = HIGH; // DS3231 Precision RTC timeRTC(); // SHARP Memory Display On isDisplayOn(); } lTime = millis(); } // iLEDGreen digitalWrite(iLEDGreen, stateLEDGreen); previous == ButState1; }
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(10,10); display.println( sDate ); display.setCursor(10,30); display.println( sTime ); display.setTextSize(3); display.setCursor(10,55); display.println("LED On"); display.refresh(); } // SHARP Memory Display Off void isDisplayOff() { // Clear Display display.clearDisplay(); // text display date, time, LED off display.setRotation(4); display.setTextSize(2); display.setTextColor(BLACK); display.setCursor(10,10); display.println( sDate ); display.setCursor(10,30); display.println( sTime ); display.setTextSize(3); display.setCursor(10,55); display.println("LED Off"); display.refresh(); }
getRTCDS3231.ino
// DS3231 Precision 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__))); } } // timeRTC void timeRTC() { // DS3231 Precision RTC sDate = ""; sTime = ""; 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() { // SHARP Display start & clear the display display.begin(); display.clearDisplay(); // Button 1 // Initialize the button as an input pinMode(iBut1, INPUT); // Initialize the LED Green pinMode(iLEDGreen, OUTPUT); // DS3231 Precision RTC setupRTC(); // stateLEDGreen = LOW stateLEDGreen = LOW; // DS3231 Precision RTC timeRTC(); // SHARP Memory Display Off isDisplayOff(); }
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
Project #11: ESP32 Feather – Push Button – Mk02
ESP32 Feather – Push Button – Mk02
——
——
——
——
——
——
Momentary Pushbutton Switch
This is a standard 12mm square momentary button. What we really like is the large button head and good tactile feel (it ‘clicks’ really well). This button is great for user input on a PCB or a good, big reset button on a breadboard. Breadboard friendly!
DonLuc1908Mk02
1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x LED Green
1 x Push Button
1 x 100 Ohm
1 x 10K Ohm
12 x Jumper Wires 3″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
Adafruit HUZZAH32 ESP32 Feather
LG1 – Digital 21
PB1 – Digital 17
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
GND – GND
VIN – +3.3V
Follow Us
Web: http://neosteamlabs.com/
Web: https://www.donluc.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
DL1908Mk02p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - Push Button - Mk02 // 08-02 // DonLuc1908Mk02p.ino 08-02 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // Push Button // include Library Code #include <Adafruit_SharpMem.h> #include <Adafruit_GFX.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 int stateLEDGreen = LOW; // stateLEDGreen // Button int iBut1 = 17; // Button 1 int ButState1; // Variable for reading the button status int previous = LOW; // previous long lTime = 0; // lTime long debounce = 500; // debounce void loop() { // Read the state of the button value ButState1 = digitalRead(iBut1); // Check if the button is pressed if (ButState1 == HIGH && previous == LOW && millis() - lTime > debounce) { if(stateLEDGreen == HIGH) { // stateLEDGreen = LOW stateLEDGreen = LOW; // SHARP Memory Display Off isDisplayOff(); } else { // stateLEDGreen = HIGH stateLEDGreen = HIGH; // SHARP Memory Display On isDisplayOn(); } lTime = millis(); } // iLEDGreen digitalWrite(iLEDGreen, stateLEDGreen); previous == ButState1; }
getDisplay.ino
// SHARP Memory Display On void isDisplayOn() { // Clear Display display.clearDisplay(); // text display tests display.setRotation(4); //display.clearDisplay(); display.setTextSize(5); display.setTextColor(BLACK); display.setCursor(10,25); display.println("LED"); display.setCursor(10,75); display.println("On"); display.refresh(); } // SHARP Memory Display Off void isDisplayOff() { // Clear Display display.clearDisplay(); // text display tests display.setRotation(4); //display.clearDisplay(); display.setTextSize(5); display.setTextColor(BLACK); display.setCursor(10,25); display.println("LED"); display.setCursor(10,75); display.println("Off"); display.refresh(); }
setup.ino
// Setup void setup() { // SHARP Display start & clear the display display.begin(); display.clearDisplay(); // Button 1 // Initialize the button as an input pinMode(iBut1, INPUT); // Initialize the LED Green pinMode(iLEDGreen, OUTPUT); }
Don Luc
Project #11: ESP32 Feather – SHARP Display – Mk01
ESP32 Feather – SHARP Display
——
——
——
——
——
——
Adafruit HUZZAH32 ESP32 Feather Board
The HUZZAH32 is our ESP32-based Feather, made with the official WROOM32 module. We packed everything you love about Feathers: built in USB-to-Serial converter, automatic bootloader reset, Lithium Ion/Polymer charger, and just about all of the GPIOs brought out so you can use it with any of our Feather Wings.
That module nestled in at the end of this Feather contains a dual-core ESP32 chip, 4 MB of SPI Flash, tuned antenna, and all the passives you need to take advantage of this powerful new processor. The ESP32 has both WiFi and Bluetooth Classic/LE support. That means it’s perfect for just about any wireless or Internet-connected project.
Adafruit SHARP Memory Display Breakout – 1.3″ 168×144 Monochrome
The 1.3″ 168×144 SHARP Memory LCD display is a cross between an eInk (e-paper) 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.
DonLuc1908Mk01
1 x Adafruit HUZZAH32 ESP32 Feather
1 x Adafruit SHARP Memory Display
1 x LED Green
1 x 100 Ohm
9 x Jumper Wires 3″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
Adafruit HUZZAH32 ESP32 Feather
LG1 – Digital 21
SCK – Digital 13
MOS – Digital 12
SSD – Digital 27
GND – GND
VIN – +3.3V
DL1908Mk01p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #11: HUZZAH32 ESP32 Feather - SHARP Display - Mk01 // 08-01 // DonLuc1908Mk01p.ino 08-01 // Adafruit HUZZAH32 ESP32 Feather Board // SHARP Display // LED Green // include Library Code #include <Adafruit_SharpMem.h> #include <Adafruit_GFX.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 void loop() { // iLEDGreen Off digitalWrite(iLEDGreen, LOW); // SHARP Memory Display Off isDisplayOff(); delay(2000); // iLEDGreen On digitalWrite(iLEDGreen, HIGH); // SHARP Memory Display On isDisplayOn(); delay(2000); }
getDisplay.ino
// SHARP Memory Display On void isDisplayOn() { // Clear Display display.clearDisplay(); // text display tests display.setRotation(4); //display.clearDisplay(); display.setTextSize(5); display.setTextColor(BLACK); display.setCursor(10,25); display.println("LED"); display.setCursor(10,75); display.println("On"); display.refresh(); } // SHARP Memory Display Off void isDisplayOff() { // Clear Display display.clearDisplay(); // text display tests display.setRotation(4); //display.clearDisplay(); display.setTextSize(5); display.setTextColor(BLACK); display.setCursor(10,25); display.println("LED"); display.setCursor(10,75); display.println("Off"); display.refresh(); }
setup.ino
// Setup void setup() { // SHARP Display start & clear the display display.begin(); display.clearDisplay(); // Initialize the LED Green pinMode(iLEDGreen, OUTPUT); }
Don Luc
Project #10: ESP8266 Thing – Precision RTC – Mk04
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 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.
With a CR1220 12mm lithium battery plugged into the top of the FeatherWing, you can get years of precision timekeeping, even when main power is lost. Great for datalogging and clocks, or anything where you need to really know the time.
DonLuc1901Mk03
1 x SparkFun ESP8266 Thing
1 x SparkFun FTDI Basic Breakout – 3.3V
1 x DS3231 Precision RTC FeatherWing
1 x RHT03 Humidity and Temperature Sensor
6 x Jumper Wires 3″ M/M
3 x Jumper Wires 6″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
SparkFun ESP8266 Thing
LG1 – Digital 5
RHT – Digital 4
SDA – Digital 2
SCL – Digital 14
GND – GND
VIN – +3.3V
DonLuc1901Mk03p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #10: SparkFun ESP8266 Thing – DS3231 Precision RTC - Mk04 // 01-03 // DonLuc1901Mk03p.ino 01-03 // SparkFun ESP8266 Thing // DS3231 Precision RTC // RHT03 Humidity and Temperature Sensor // Include Library Code // WiFi #include <ESP8266WiFi.h> // RHT Humidity and Temperature Sensor #include <SparkFun_RHT03.h> // DS3231 Precision RTC #include <RTClib.h> #include <Wire.h> // WiFi Definitions const char WiFiAPPSK[] = "donlucmk01"; // Pin Definitions const int LED_PIN = 5; // Thing's onboard, green LED const int ANALOG_PIN = A0; // The only analog pin on the Thing const int DIGITAL_PIN = 12; // Digital pin to be read // WiFi WiFiServer server(80); // RHT Humidity and Temperature Sensor const int RHT03_DATA_PIN = 4; // RHT03 data pin Digital 4 RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor float latestHumidity; float latestTempC; float latestTempF; // DS3231 Precision RTC RTC_DS3231 RTC; String sDate; String sTime; void loop() { // RHT03 Humidity and Temperature Sensor isRHT03(); // DS3231 Precision RTC timeRTC(); // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // Match the request int val = -1; // We'll use 'val' to keep track of both the request type (read/set) and value if set. if (req.indexOf("/led/0") != -1) val = 0; // Will write LED low else if (req.indexOf("/led/1") != -1) val = 1; // Will write LED high else if (req.indexOf("/read") != -1) val = -2; // Will print pin reads // Otherwise request will be invalid. We'll say as much in HTML // Set GPIO5 according to the request if (val >= 0) digitalWrite(LED_PIN, val); client.flush(); // Prepare the response. Start with the common header: String s = "HTTP/1.1 200 OK\r\n"; s += "Content-Type: text/html\r\n\r\n"; s += "<!DOCTYPE HTML>\r\n<html>\r\n"; // If we're setting the LED, print out a message saying we did if (val >= 0) { s += "LED is now "; s += (val)?"on":"off"; } else if (val == -2) { // If we're reading pins, print out those values: s += "Date = "; s += sDate; s += "<br>"; s += "Time = "; s += sTime; s += "<br>"; s += "Analog Pin = "; s += String(analogRead(ANALOG_PIN)); s += "<br>"; // Go to the next line. s += "Digital Pin 12 = "; s += String(digitalRead(DIGITAL_PIN)); s += "<br>"; // Go to the next line. s += "Humidity and Temperature"; s += "<br>"; // Go to the next line. s += "Humidity : "; s += String(latestHumidity); // Humidity s += "%"; s += "<br>"; // Go to the next line. s += "Celsius: "; s += String(latestTempC); // Temperature *C s += "*C"; s += "<br>"; // Go to the next line. s += "Fahrenheit: "; s += String(latestTempF); // Temperature *F s += "*F"; } else { s += "Invalid Request.<br> Try /led/1, /led/0, or /read."; } s += "</html>\n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected"); // The client will actually be disconnected when the function returns and 'client' object is detroyed }
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(); }
getRTCDS3231.ino
// DS3231 Precision 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__))); } } // timeRTC void timeRTC() { // DS3231 Precision RTC sDate = ""; sTime = ""; 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); }
setWiFi.ino
// WiFi void setupWiFi() { // WiFi mode WIFI_AP WiFi.mode(WIFI_AP); // Append the last two bytes of the MAC (HEX'd) to "Thing-": uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.softAPmacAddress(mac); String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); macID.toUpperCase(); String AP_NameString = "ESP8266 Thing " + macID; char AP_NameChar[AP_NameString.length() + 1]; memset(AP_NameChar, 0, AP_NameString.length() + 1); for (int i=0; i<AP_NameString.length(); i++) AP_NameChar[i] = AP_NameString.charAt(i); WiFi.softAP(AP_NameChar, WiFiAPPSK); } // init Hardware void initHardware() { // Serial Serial.begin(115200); // LED Green pinMode(DIGITAL_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // RHT03 Humidity and Temperature Sensor // Call rht.begin() to initialize the sensor and our data pin rht.begin(RHT03_DATA_PIN); // DS3231 Precision RTC setupRTC(); }
setup.ino
// Setup void setup() { // Hardware initHardware(); // WiFi setupWiFi(); server.begin(); }
Don Luc
Project #10: ESP8266 Thing – Web Server – Mk03
AP Web Server
Not only can the ESP8266 connect to a WiFi network and interact with the Internet, but it can also set up a network of its own, allowing other devices to connect directly to it. This example demonstrates how to turn the ESP8266 into an access point (AP), and serve up web pages to any connected client.
After uploading this sketch, find another device that you can connect to a WiFi network – phone, laptop, etc. Look for a network called “Thing-XXXX”, where XXXX is the last 2 bytes of the Thing’s MAC address.
WiFi => Yes
ESP8266 Thing XXXX
He sketch sets the network’s password to “donlucmk01”.
After connecting to your Thing’s AP network, load up a browser and point it to 192.168.4.1/read. The Thing should serve up a web page showing you its ADC and digital pin 12 readings:
Analog Pin = XXX
Digital Pin: XXX
Humidity and Temperature
Humidity: XX.XX%
Celsius: XX.XX*C
Fahrenheit: XX.XX*F
LED Green
After that, give 192.168.4.1/led/0 (No) and 192.168.4.1/led/1 (Yes) a try, and keep an eye on the Thing’s green LED while you do.
RHT03 Humidity and Temperature Sensor
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.
DonLuc1901Mk02
1 x SparkFun ESP8266 Thing
1 x SparkFun FTDI Basic Breakout – 3.3V
1 x RHT03 Humidity and Temperature Sensor
3 x Jumper Wires 6″ M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
SparkFun ESP8266 Thing
LG1 – Digital 5
RHT – Digital 4
GND – GND
VIN – +3.3V
DonLuc1901Mk02p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #10: SparkFun ESP8266 Thing – AP Web Server - Mk02 // 01-02 // DonLuc1901Mk01p.ino 01-02 // SparkFun ESP8266 Thing // AP Web Server // RHT03 Humidity and Temperature Sensor // Include Library Code #include <ESP8266WiFi.h> #include <SparkFun_RHT03.h> // WiFi Definitions const char WiFiAPPSK[] = "donlucmk01"; // Pin Definitions const int LED_PIN = 5; // Thing's onboard, green LED const int ANALOG_PIN = A0; // The only analog pin on the Thing const int DIGITAL_PIN = 12; // Digital pin to be read // WiFi WiFiServer server(80); // RHT Humidity and Temperature Sensor const int RHT03_DATA_PIN = 4; // RHT03 data pin Digital 4 RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor float latestHumidity; float latestTempC; float latestTempF; void loop() { // RHT03 Humidity and Temperature Sensor isRHT03(); // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // Match the request int val = -1; // We'll use 'val' to keep track of both the request type (read/set) and value if set. if (req.indexOf("/led/0") != -1) val = 0; // Will write LED low else if (req.indexOf("/led/1") != -1) val = 1; // Will write LED high else if (req.indexOf("/read") != -1) val = -2; // Will print pin reads // Otherwise request will be invalid. We'll say as much in HTML // Set GPIO5 according to the request if (val >= 0) digitalWrite(LED_PIN, val); client.flush(); // Prepare the response. Start with the common header: String s = "HTTP/1.1 200 OK\r\n"; s += "Content-Type: text/html\r\n\r\n"; s += "<!DOCTYPE HTML>\r\n<html>\r\n"; // If we're setting the LED, print out a message saying we did if (val >= 0) { s += "LED is now "; s += (val)?"on":"off"; } else if (val == -2) { // If we're reading pins, print out those values: s += "Analog Pin = "; s += String(analogRead(ANALOG_PIN)); s += "<br>"; // Go to the next line. s += "Digital Pin 12 = "; s += String(digitalRead(DIGITAL_PIN)); s += "<br>"; // Go to the next line. s += "Humidity and Temperature"; s += "<br>"; // Go to the next line. s += "Humidity : "; s += String(latestHumidity); // Humidity s += "%"; s += "<br>"; // Go to the next line. s += "Celsius: "; s += String(latestTempC); // Temperature *C s += "*C"; s += "<br>"; // Go to the next line. s += "Fahrenheit: "; s += String(latestTempF); // Temperature *F s += "*F"; } else { s += "Invalid Request.<br> Try /led/1, /led/0, or /read."; } s += "</html>\n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected"); // The client will actually be disconnected when the function returns and 'client' object is detroyed }
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(); }
setWiFi.ino
// WiFi void setupWiFi() { // WiFi mode WIFI_AP WiFi.mode(WIFI_AP); // Append the last two bytes of the MAC (HEX'd) to "Thing-": uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.softAPmacAddress(mac); String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); macID.toUpperCase(); String AP_NameString = "ESP8266 Thing " + macID; char AP_NameChar[AP_NameString.length() + 1]; memset(AP_NameChar, 0, AP_NameString.length() + 1); for (int i=0; i<AP_NameString.length(); i++) AP_NameChar[i] = AP_NameString.charAt(i); WiFi.softAP(AP_NameChar, WiFiAPPSK); } // init Hardware void initHardware() { // Serial Serial.begin(115200); // LED Green pinMode(DIGITAL_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // RHT03 Humidity and Temperature Sensor // Call rht.begin() to initialize the sensor and our data pin rht.begin(RHT03_DATA_PIN); }
setup.ino
// Setup void setup() { // Hardware initHardware(); // WiFi setupWiFi(); server.begin(); }
Don Luc
Project #10: ESP8266 Thing – Blink – Mk02
Soldering
Plated through-hole soldering (PTH), flux-core solder alloys commonly used for electrical soldering are 60/40 Sn-Pb used principally in electrical/electronic work and TENMA soldering station temperature controlled digital.
Hardware Assembly
We’re getting ahead of ourselves. To connect the FTDI programmer to your Thing you’ll need to solder something to the Thing. What, exactly, you solder to the board depends both on how you’ll use it in your project, and how you’ll interface it with the programmer. When it comes to selecting a header (or wire) to solder, there are a variety of options. We’ve tried a lot of them with the Thing:
Or you can mix and match headers to best fit your needs. Right-angle male headers may help to interface between the FTDI and the Thing. Straight male headers are a good choice for low-profile connections. Straight female headers may help with connecting to I2C sensors. And, of course, wire can be soldered to any of the pins that have a long way to connect to something.
10 pin – Break Away Headers – Straight
4 pin – Break Away Headers – Straight
6 pin – Break Away Male Headers – Right Angle
Once you’ve soldered up at least the programming port, you’re ready to load some code onto the Thing.
Programming the Thing
The ESP8266 has a built-in serial bootloader, which allows for easy programming and re-programming. You don’t need a specialized, expensive programmer – just a simple, USB-to-Serial converter. The FTDI Basic’s 6-pin header matches up exactly to the Thing’s 6-pin serial port header. To set up for programming, simply connect the FTDI directly to this port – take care to match up the DTR and GND pins.
Blink
Let’s blink some LEDs and IoT (Internet our Thing). To verify that everything works Blink: toggle pin 5, which is attached to the onboard LED Green, toggle pin 4 which is LED Green.
DonLuc1901Mk01
1 x SparkFun ESP8266 Thing
1 x SparkFun FTDI Basic Breakout – 3.3V
1 x LED Green
1 x 100 Ohm
4 x Jumper Wires 3″ M/M
1 x Full-Size Breadboard
1 x USB Cable A to Mini-B
SparkFun ESP8266 Thing
LG1 – Digital 5
LG2 – Digital 4
GND – GND
VIN – +3.3V
DonLuc1901Mk01p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #10: SparkFun ESP8266 Thing – Blink - Mk02 // 01-01 // DonLuc1901Mk01p.ino 01-01 // SparkFun ESP8266 Thing // Blink // Include Library Code #define ESP8266_LED 5 // LED Green int iLEDGreen = 4; // LED Green void loop() { // ESP8266_LED, iLEDGreen digitalWrite(ESP8266_LED, LOW); digitalWrite(iLEDGreen, LOW); delay(2000); digitalWrite(ESP8266_LED, HIGH); delay(2000); digitalWrite(ESP8266_LED, LOW); delay(2000); digitalWrite(iLEDGreen, HIGH); delay(2000); }
setup.ino
// Setup void setup() { // LED pinMode(ESP8266_LED, OUTPUT); // ESP8266_LED Green pinMode(iLEDGreen, OUTPUT); // LED Green }
Don Luc
Project #7: RGB LCD Shield – MCP4131 – Mk10
Microchip Technology Inc – MCP4131
Features:
-7-bit: 128 Resistors with 129 Taps to VSS and VDD
-SPI compatible interface
-Automatic Recall of Potentiometer Wiper Settings Resistance Values: 5k Ohm, 10k Ohm, 50k Ohm, 100k Ohm
-Absolute (Rheostat): <100 ppm (typ.)
-Ratiometric (Potentiometer): <10 ppm (typ.)
Device Overview – Summary
The MCP41/423X devices are volatile, 7-bit (129 wiper steps) digital potentiometers with an SPI compatible interface. The MCP41/42XX family is available with end-to-end resistor values of 5K Ohm, 10K Ohm, 50k Ohm and 100K Ohm. These devices offer a variety of configurations simplifying design while minimizing cost, package size and pin count.
Additional Features
-7-bit: 128 Resistors with 129 Taps to VSS and VDD
-SPI compatible interface
-Automatic Recall of Potentiometer Wiper Settings Resistance Values: 5k Ohm, 10k Ohm, 50k Ohm, 100k Ohm
-Low Tempco: Absolute (Rheostat): <100 ppm (typ.)
-Ratiometric (Potentiometer): <10 ppm (typ.)
-Low Wiper Resistance: 100 Ohm (typ.)
-Low-Power Operation: 1µA Max Static Current
-Wide Operating Voltage: 1.8V to 5.5V
-Extended Temperature Range: -40°C to +125°C
MCP4131 – Digital Potentiometer – 10K
Potentiometers are incredibly useful, whether you’re controlling the volume on your stereo or the ‘mood lighting’ in your room. The problem with traditional potentiometers is the fact that your microcontroller doesn’t have an easy way to interface with them. Digital potentiometers solve that problem by allowing you to control a voltage splitter with digital signals.
Wire it up just like a potentiometer and use serial signals to ‘turn the knob’. Another handy feature of digital potentiometers is that because they aren’t controlled mechanically, they don’t have a pre-determined sweep profile. In other words, depending on the way you write your code the potentiometer can ‘sweep’ in a linear fashion, a logarithmic fashion, or according to any other profile you like. Digital potentiometers can also be used in conjunction with rotary encoders to consolidate large banks of potentiometers into one ‘smart’ rotary control.
Digital Potentiometer MCP41131 and Arduino
We know the analog potentiometer, is a three-terminal resistor with a sliding contact that forms an adjustable voltage divider. Potentiometers many application such like:
1- Volume controls on audio equipment
2- Control the amplifier gain and offset
3- Transducer displacement transducers
Many other application, but did you want to control the resistance value by Arduino instead of using analog one. Analog potentiometers have some problem with Arduino doesn’t have an easy way to interface with them. The digital potentiometer, give you an ability to adjust the resistance, allowing you to control a voltage splitter with digital signals. This IC using SPI Protocol to communicate with Arduino.
DonLuc1808Mk03
1 x RGB LCD Shield 16×2 Character Display
1 x Arduino UNO – R3
1 x ProtoScrewShield
1 x MCP4131
1 x LED Green
1 x 270 Ohm Resistance
1 x NeoPixel Stick – 8 x 5050 RGB LED
1 x 100K Potentiometer
1 x Black Knob
7 x Jumper Wires 3″ M/M
12 x Jumper Wires 6″ M/M
1 x Full-Size Breadboard
1 x USB Cable A to B
Arduino UNO
MC1 – Digital 13
MC2 – Digital 11
MC3 – Digital 10
LR1 – Digital 3
POT – Analog 1
GND – GND
VIN – +5V
DonLuc1808Mk03p.ino
// ***** Don Luc Electronics ***** // Software Version Information // Project #7: RGB LCD Shield – MCP4131 – Mk10 // 8-03 // DonLuc1808Mk03p 8-03 // RGB LCD Shield // MCP4131 // Include Library Code #include <Adafruit_MCP23017.h> #include <Adafruit_RGBLCDShield.h> #include <Adafruit_NeoPixel.h> #include <SPI.h> // RGB LCD Shield Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield(); #define GREEN 0x2 // NeoPixels #define PIN 3 // On digital pin 3 #define NUMPIXELS 8 // NeoPixels NUMPIXELS = 8 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int red = 0; // Red int green = 0; // Green int blue = 0; // Blue int iNeo = 0; // Neopix const int iBriPin = A1; // Panel Mount 1K potentiometer Brightneed int iBri = 0; // Neopix Brightness int iBriMin = 1023; // Brightneed minimum sensor value int iBriMax = 0; // Brightneed maximun sensor value int z = 0; // Value // MCP4131 int pinCS = 10; // MCP4131 byte address = 0x00; // Address int i = 0; // Value void loop() { // MCP4131 isMCP4131(); delay(1000); // Clear RGBLCDShield.clear(); }
getMCP4131.ino
// MCP4131 void isMCP4131() { // NeoPixels isNUMPIXELSoff(); // isNUMPIXELSoff // Display // Set the cursor to column 0, line 0 RGBLCDShield.setCursor(0,0); RGBLCDShield.print("MCP4131"); // MCP4131 // MCP4131 // Move the potentiometer in one direction for ( i = 0; i <= 128; i++) { isNUMPIXELSoff(); // isNUMPIXELSoff MCP4131PotWrite(i); isNUMPIXELS(); // isNUMPIXELS delay(100); // Set the cursor to column 0, line 1 RGBLCDShield.setCursor(0, 1); RGBLCDShield.print("Level = "); // MCP4131 RGBLCDShield.print(i); // MCP4131 } delay(2000); // wait a couple seconds // Now mover potentiometer in other directions for ( i = 128; i >= 0; i--) { isNUMPIXELSoff(); // isNUMPIXELSoff MCP4131PotWrite(i); isNUMPIXELS(); // isNUMPIXELS delay(100); RGBLCDShield.setCursor(0, 1); RGBLCDShield.print(" "); RGBLCDShield.setCursor(0, 1); RGBLCDShield.print("Level = "); // MCP4131 RGBLCDShield.print(i); // MCP4131 } delay(2000); } // MCP4131PotWrite int MCP4131PotWrite(int value) { digitalWrite(pinCS, LOW); // pinCS Off SPI.transfer(address); // SPI Address SPI.transfer(value); // SPI Value digitalWrite(pinCS, HIGH); // pinCS On }
neopix.ino
// NeoPixels void neopix() { // Brightness iBri = analogRead(iBriPin); // iBri apply the calibration to the sensor reading iBri = map(iBri, iBriMin, iBriMax, 0, 255); // iBri in case the sensor value is outside the range seen during calibration iBri = constrain(iBri, 0, 255); pixels.setBrightness( iBri ); // Pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor( iNeo, pixels.Color(red,green,blue) ); // This sends the updated pixel color to the hardware pixels.show(); // Delay for a period of time (in milliseconds) delay(50); } // isNUMPIXELS void isNUMPIXELS() { // Neopix Value z = ( i / 16 ); // Value // Neopix Value switch ( z ) { case 0: // NeoPixels // Green for(int y=0; y<=0; y++) { red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 1: // Green // NeoPixels for(int y=0; y<=1; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 2: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 3: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=3; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 4: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=4; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 5: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=5; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 6: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=5; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Red for(int y=6; y<=6; y++){ red = 255; // Red green = 0; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 7: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=5; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Red for(int y=6; y<=7; y++){ red = 255; // Red green = 0; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; case 8: // NeoPixels // Green for(int y=0; y<=2; y++){ red = 0; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Yellow for(int y=3; y<=5; y++){ red = 255; // Red green = 255; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } // Red for(int y=6; y<=7; y++){ red = 255; // Red green = 0; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } break; } } // isNUMPIXELSoff void isNUMPIXELSoff() { // Black // NeoPixels for(int y=0; y < NUMPIXELS; y++) { red = 0; // Red green = 0; // Green blue = 0; // Blue iNeo = y; // Neopix neopix(); } }
setup.ino
// Setup void setup() { // set up the LCD's number of columns and rows: RGBLCDShield.begin(16, 2); RGBLCDShield.setBacklight(GREEN); // Display // Set the cursor to column 0, line 0 RGBLCDShield.setCursor(0,0); RGBLCDShield.print("Don Luc"); // Don luc // Set the cursor to column 0, line 1 RGBLCDShield.setCursor(0, 1); RGBLCDShield.print("MCP4131"); // MCP4131 delay(5000); // Clear RGBLCDShield.clear(); // NeoPixels pixels.begin(); // This initializes the NeoPixel library // NeoPixels isNUMPIXELSoff(); // isNUMPIXELSoff // MCP4131 pinMode(pinCS, OUTPUT); // MCP4131 OUTPUT SPI.begin(); // SPI }
Don Luc