· 6 years ago · Oct 01, 2019, 04:08 PM
1// mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
2// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
3#include <GxEPD.h>
4
5// select the display class to use, only one
6#include <GxGDEW0154Z04/GxGDEW0154Z04.cpp> // 1.54" b/w/r 200x200
7#include GxEPD_BitmapExamples
8
9// FreeFonts from Adafruit_GFX
10#include <Fonts/FreeSansBold24pt7b.h>
11#include <Fonts/FreeSansBold18pt7b.h>
12#include <Fonts/FreeSans9pt7b.h>
13
14#include "youtubelogo.h"
15#include <ESP8266WiFi.h>
16#include <WiFiClientSecure.h>
17#include <YoutubeApi.h>
18#include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
19
20#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
21#include <GxIO/GxIO.cpp>
22
23GxIO_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
24GxEPD_Class display(io /*RST=D4*/ /*BUSY=D2*/); // default selection of D4(=2), D2(=4)
25
26
27long subs = 0;
28String subscribers,viewCount,videoCount;
29
30//------- Replace the following! ------
31char ssid[] = ""; // your network SSID (name)
32char password[] = ""; // your network key
33#define API_KEY "" // your google apps API Token
34#define CHANNEL_ID "UCqur3wdt2I-pVhckJb8n0bg" // makes up the url of channel
35
36WiFiClientSecure client;
37YoutubeApi api(API_KEY, client);
38
39unsigned long api_mtbs = 600000; //mean time between api requests
40unsigned long api_lasttime; //last time api request has been done
41
42void setup()
43{
44 // put your setup code here, to run once:
45
46 Serial.begin(115200);
47 Serial.println();
48 Serial.println("setup");
49 display.init();
50 display.setRotation(3);
51 Serial.println("setup done");
52
53 WiFi.mode(WIFI_STA);
54 WiFi.disconnect();
55 delay(100);
56
57 // Attempt to connect to Wifi network:
58 Serial.print("Connecting Wifi: ");
59 Serial.println(ssid);
60 WiFi.begin(ssid, password);
61 while (WiFi.status() != WL_CONNECTED) {
62 Serial.print(".");
63 delay(500);
64 }
65 Serial.println("");
66 Serial.println("WiFi connected");
67 Serial.println("IP address: ");
68 IPAddress ip = WiFi.localIP();
69 Serial.println(ip);
70}
71
72void loop()
73{
74 // put your main code here, to run repeatedly:
75 //if (millis() - api_lasttime > api_mtbs) {
76 if(api.getChannelStatistics(CHANNEL_ID))
77 {
78 Serial.println("Get YouTube Statistics");
79 subscribers=api.channelStats.subscriberCount;
80 viewCount=api.channelStats.viewCount;
81 videoCount=api.channelStats.videoCount;
82 display.drawPaged(showFontCallback_YouTube);
83 Serial.print("Subscriber Count: ");
84 Serial.println(subscribers);
85 Serial.print("View Count: ");
86 Serial.println(api.channelStats.viewCount);
87 Serial.print("Video Count: ");
88 Serial.println(api.channelStats.videoCount);
89 }
90 // api_lasttime = millis();
91 //}
92 delay(api_mtbs);
93}
94
95void showFontCallback_YouTube()
96{
97 const char* name = "FreeSansBold24pt7b";
98 const GFXfont* f = &FreeSansBold24pt7b;
99
100 const char* name18 = "FreeSansBold18pt7b";
101 const GFXfont* f18pt = &FreeSansBold18pt7b;
102
103 const char* name9 = "FreeSans9pt7b";
104 const GFXfont* f9pt = &FreeSans9pt7b;
105
106 display.fillScreen(GxEPD_WHITE);
107 display.setTextColor(GxEPD_BLACK);
108 display.setCursor(0, 130); //130
109 display.println();
110 //display.drawLine(0,60,264,60,GxEPD_BLACK);
111 display.drawLine(0,60,264,60,GxEPD_RED);
112 display.setFont(f);
113 int x=(subscribers.length()*20)/2; // make the text in the center of the display 30
114 //display.setTextWrap(true);
115 display.setCursor(100-x, 100);
116 display.println(subscribers);
117 display.setFont(f9pt);
118 display.setCursor(60, 120);
119 display.setTextColor(GxEPD_BLACK);
120 display.println("Subscribers");
121
122 display.drawBitmap(30, 10, gImage_ytlogo1, 46, 32, GxEPD_RED); //60
123 display.drawBitmap(80, 10, gImage_ytlogo2, 94, 29, GxEPD_BLACK); //110
124
125 display.drawLine(0,140,264,140,GxEPD_BLACK);
126 display.setTextColor(GxEPD_BLACK);
127 display.setCursor(0, 165);
128 display.println("Views:" +viewCount);
129 display.setCursor(112, 165);
130 display.println("Videos:" +videoCount);
131
132
133}