Skip to content

Instantly share code, notes, and snippets.

@glyons
Created May 13, 2018 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save glyons/dbdc476401390a21528d47d162a69280 to your computer and use it in GitHub Desktop.
Save glyons/dbdc476401390a21528d47d162a69280 to your computer and use it in GitHub Desktop.
Waveshare e-Paper Display 1.54" red/black YouTube Statistics
// 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 "youtubelogo.h"
#include <ESP8266WiFi.h>
#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.
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>
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)
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()
{
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.println("setup");
display.init();
display.setRotation(3);
Serial.println("setup done");
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()
{
// put your main code here, to run repeatedly:
//if (millis() - api_lasttime > api_mtbs) {
if(api.getChannelStatistics(CHANNEL_ID))
{
Serial.println("Get YouTube Statistics");
subscribers=api.channelStats.subscriberCount;
viewCount=api.channelStats.viewCount;
videoCount=api.channelStats.videoCount;
display.drawPaged(showFontCallback_YouTube);
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);
}
// api_lasttime = millis();
//}
delay(api_mtbs);
}
void showFontCallback_YouTube()
{
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.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setCursor(0, 130); //130
display.println();
//display.drawLine(0,60,264,60,GxEPD_BLACK);
display.drawLine(0,60,264,60,GxEPD_RED);
display.setFont(f);
int x=(subscribers.length()*20)/2; // make the text in the center of the display 30
//display.setTextWrap(true);
display.setCursor(100-x, 100);
display.println(subscribers);
display.setFont(f9pt);
display.setCursor(60, 120);
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,140,264,140,GxEPD_BLACK);
display.setTextColor(GxEPD_BLACK);
display.setCursor(0, 165);
display.println("Views:" +viewCount);
display.setCursor(112, 165);
display.println("Videos:" +videoCount);
}
const unsigned char gImage_ytlogo1[192] = { /* 0X00,0X01,0X2E,0X00,0X20,0X00, */
0X00,0X0F,0XFF,0XFF,0XC0,0X00,0X0F,0XFF,0XFF,0XFF,0XFF,0XC0,0X3F,0XFF,0XFF,0XFF,
0XFF,0XF0,0X3F,0XFF,0XFF,0XFF,0XFF,0XF0,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,
0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,
0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0XFF,0XFF,0XEF,0XFF,
0XFF,0XF8,0XFF,0XFF,0XE3,0XFF,0XFF,0XFC,0XFF,0XFF,0XE0,0XFF,0XFF,0XFC,0XFF,0XFF,
0XE0,0X7F,0XFF,0XFC,0XFF,0XFF,0XE0,0X1F,0XFF,0XFC,0XFF,0XFF,0XE0,0X07,0XFF,0XFC,
0XFF,0XFF,0XE0,0X03,0XFF,0XFC,0XFF,0XFF,0XE0,0X1F,0XFF,0XFC,0XFF,0XFF,0XE0,0X7F,
0XFF,0XFC,0XFF,0XFF,0XE0,0XFF,0XFF,0XFC,0XFF,0XFF,0XE3,0XFF,0XFF,0XFC,0XFF,0XFF,
0XEF,0XFF,0XFF,0XF8,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,
0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,
0XFF,0XF8,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X3F,0XFF,0XFF,0XFF,0XFF,0XF0,0X3F,0XFF,
0XFF,0XFF,0XFF,0XF0,0X0F,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X1F,0XFF,0XFF,0XE0,0X00,
};
const unsigned char gImage_ytlogo2[348] = { /* 0X00,0X01,0X5E,0X00,0X1D,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0X00,0X00,0X00,0XF8,0X3E,0X00,0X00,
0X00,0XFF,0XFC,0X00,0X1F,0X00,0X00,0X00,0X78,0X3C,0X00,0X00,0X00,0XFF,0XFC,0X00,
0X1F,0X00,0X00,0X00,0X78,0X3C,0X00,0X00,0X00,0XFF,0XFC,0X00,0X1F,0X00,0X00,0X00,
0X78,0X3C,0X00,0X00,0X00,0XFF,0XFC,0X00,0X1F,0X00,0X00,0X00,0X78,0X3C,0X00,0X00,
0X00,0X07,0X80,0X00,0X1F,0X00,0X00,0X00,0X7C,0X3C,0X00,0X00,0X00,0X07,0X80,0X00,
0X1F,0X00,0X00,0X00,0X3C,0X78,0X00,0X00,0X00,0X07,0X80,0X00,0X1F,0X00,0X00,0X00,
0X3E,0X78,0X7E,0X07,0X87,0X87,0X8F,0X8F,0X1F,0X3C,0X03,0XE0,0X3E,0XF8,0XFF,0X87,
0XC7,0X87,0X8F,0X8F,0X1F,0XFE,0X0F,0XF8,0X3E,0XF9,0XFF,0X87,0XC7,0X87,0X8F,0X8F,
0X1F,0XFE,0X1F,0XF8,0X1E,0XF3,0XE7,0XC7,0XC7,0X87,0X8F,0X8F,0X1F,0XBF,0X1E,0X78,
0X0E,0XF3,0XE3,0XC7,0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X1E,0X3C,0X0E,0XE3,0XE3,0XE7,
0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X3C,0X0F,0XE3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,
0X1F,0X1F,0X3E,0X3C,0X0F,0XE3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X3C,
0X0F,0XE3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X3C,0X07,0XC3,0XE3,0XE7,
0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3F,0XFC,0X07,0XC3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,
0X1F,0X1F,0X3F,0XFC,0X07,0XC3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3F,0XFC,
0X07,0XC3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X00,0X07,0XC3,0XE3,0XE7,
0XC7,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X00,0X07,0XC3,0XE3,0XE7,0XC7,0X87,0X8F,0X8F,
0X1F,0X1F,0X3E,0X3C,0X07,0XC3,0XE3,0XE7,0X87,0X87,0X8F,0X8F,0X1F,0X1F,0X3E,0X3C,
0X07,0XC3,0XE3,0XC7,0XCF,0X87,0X8F,0X8F,0X1F,0X1F,0X1E,0X3C,0X07,0XC3,0XFF,0XC7,
0XFF,0X87,0X8F,0XFF,0X1F,0XFF,0X1F,0XF8,0X07,0XC1,0XFF,0X87,0XFF,0X87,0X8F,0XFF,
0X1F,0XFE,0X1F,0XF8,0X07,0XC0,0XFF,0X83,0XF7,0X87,0X87,0XF7,0X1E,0XFC,0X0F,0XF0,
0X00,0X00,0X1C,0X01,0XC0,0X00,0X01,0X80,0X00,0X38,0X01,0XC0,};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment