Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save glyons/6438ed71aae2c6c2790256516881995f to your computer and use it in GitHub Desktop.

Select an option

Save glyons/6438ed71aae2c6c2790256516881995f to your computer and use it in GitHub Desktop.
// mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
#include <GxEPD.h>
// select the display class to use, only one
#include <GxGDEW0154Z04/GxGDEW0154Z04.cpp> // 1.54" b/w/r 200x200
#include GxEPD_BitmapExamples
// FreeFonts from Adafruit_GFX
#include <Fonts/FreeSansBold24pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>
// Wifi
#include <ESP8266WiFi.h>
// YouTUBE API
//#include "youtubelogo.h" // For logo only
#include <WiFiClientSecure.h>
#include <YoutubeApi.h>
#include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
GxIO_Class io(SPI, /*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
GxEPD_Class display(io /*RST=D4*/ /*BUSY=D2*/); // default selection of D4(=2), D2(=4)
// ms to update
long timeSinceLastRead = 9999999;
//DHT Temperature
#include "DHT.h"
#define DHTPIN D6 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
DHT dht(DHTPIN, DHTTYPE);
// YouTube
long subs = 0;
String subscribers,viewCount,videoCount;
//------- Replace the following! ------
char ssid[] = "-------------"; // your network SSID (name)
char password[] = "--------------"; // your network key
#define API_KEY "--------------------" // your google apps API Token
#define CHANNEL_ID "UCqur3wdt2I-pVhckJb8n0bg" // makes up the url of channel
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
unsigned long api_mtbs = 600000; //mean time between api requests
unsigned long api_lasttime; //last time api request has been done
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("setup");
display.init(115200); // enable diagnostic output on Serial
//display.setRotation(3);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
}
void loop() {
display.fillScreen(GxEPD_WHITE);
getTemperature();
}
void getYouTubestats()
{
if(api.getChannelStatistics(CHANNEL_ID))
{
Serial.println("Get YouTube Statistics");
subscribers=api.channelStats.subscriberCount;
viewCount=api.channelStats.viewCount;
videoCount=api.channelStats.videoCount;
Serial.print("Subscriber Count: ");
Serial.println(subscribers);
Serial.print("View Count: ");
Serial.println(api.channelStats.viewCount);
Serial.print("Video Count: ");
Serial.println(api.channelStats.videoCount);
}
showYouTube(api.channelStats.viewCount, api.channelStats.videoCount,api.channelStats.subscriberCount);
}
void getTemperature()
{
//https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor
// Report every 300 seconds. 5mins
if(timeSinceLastRead > 300000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
showTemperature(-1,-1);
timeSinceLastRead = 0;
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
showTemperature(t,h);
getYouTubestats();
display.update();
delay(5000);
timeSinceLastRead = 0;
}
delay(100);
timeSinceLastRead += 100;
}
void showTemperature(float tempValue, float humValue)
{
const GFXfont* f = &FreeSansBold24pt7b;
const char* name18 = "FreeSansBold18pt7b";
const GFXfont* f18pt = &FreeSansBold18pt7b;
const char* name9 = "FreeSans9pt7b";
const GFXfont* f9pt = &FreeSans9pt7b;
display.setTextColor(GxEPD_BLACK);
display.setFont(f18pt);
display.setCursor(10, 40);
display.print(tempValue,1);
display.setCursor(118, 40);
display.print(humValue,0);
display.print("%\t");
display.setFont(f9pt);
display.setCursor(80, 40);
display.setTextColor(GxEPD_BLACK);
display.println("*C");
display.drawLine(0,60,264,60,GxEPD_BLACK);
display.drawLine(105,0,105,60,GxEPD_BLACK);
}
void showYouTube(long viewCount, long videoCount, long subscribers)
{
const char* name = "FreeSansBold24pt7b";
const GFXfont* f = &FreeSansBold24pt7b;
const char* name18 = "FreeSansBold18pt7b";
const GFXfont* f18pt = &FreeSansBold18pt7b;
const char* name9 = "FreeSans9pt7b";
const GFXfont* f9pt = &FreeSans9pt7b;
display.setTextColor(GxEPD_BLACK);
display.setFont(f);
//int x=(subscribers.length()*20)/2; // make the text in the center of the display 30
//display.setTextWrap(true);
display.setCursor(50, 120);
display.println(subscribers);
display.setFont(f9pt);
display.setCursor(60, 140);
display.setTextColor(GxEPD_BLACK);
display.println("Subscribers");
// display.drawBitmap(30, 10, gImage_ytlogo1, 46, 32, GxEPD_RED); //60
// display.drawBitmap(80, 10, gImage_ytlogo2, 94, 29, GxEPD_BLACK); //110
display.drawLine(0,170,264,170,GxEPD_BLACK);
display.setCursor(0, 190);
display.print("Views:");
display.println(viewCount);
display.setCursor(112, 190);
display.print("Videos:");
display.println(videoCount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment