Skip to content

Commit 80ad1e5

Browse files
authored
Merge pull request #222 from SolderedElectronics/dev
Dev to master merge
2 parents a23ced2 + e777f56 commit 80ad1e5

File tree

688 files changed

+32917
-4284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

688 files changed

+32917
-4284
lines changed

examples/Inkplate10/Projects/Inkplate10_Image_Frame_From_SD/Inkplate10_Image_Frame_From_SD.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void loop()
8686
lastImageIndex = file.dirIndex();
8787

8888
// Skip hidden files and subdirectories
89-
skipHiden();
89+
skipHidden();
9090

9191
// Get name of the pucture, create path and draw image on the screen
9292
if (!displayImage())
@@ -241,7 +241,7 @@ bool displayImage()
241241
/**
242242
* @brief Skip hidden files and subdirectories.
243243
*/
244-
void skipHiden()
244+
void skipHidden()
245245
{
246246
while (file.isHidden() || file.isSubDir())
247247
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
Inkplate10_Youtube_Subscriber_Counter example for Soldered Inkplate 10
3+
For this example you will need only USB cable and Inkplate 10.
4+
Select "e-radionica Inkplate10" or "Soldered Inkplate10" from Tools -> Board menu.
5+
Don't have "e-radionica Inkplate10" or "Soldered Inkplate10" option? Follow our tutorial and add it:
6+
https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
7+
8+
This example show how to use Google API to show info about some youtube chhannel.
9+
You need to register on https://developers.google.com/ and get API key of any kind so, you
10+
can use your API key in API call. That key you should copy in variable api_key.
11+
Second thing you need to get ID of any youtube channel and copy it in channel_id variable.
12+
You can get ID by going on any youtube channel profile and copy part of URL link after
13+
https://www.youtube.com/channel/ (so just some random text after last backslash).
14+
15+
IMPORTANT:
16+
Make sure to change wifi credentials below
17+
Also have ArduinoJSON installed in your Arduino libraries, download here: https://arduinojson.org/
18+
19+
Want to learn more about Inkplate? Visit www.inkplate.io
20+
Looking to get support? Write on our forums: https://forum.soldered.com/
21+
16 Aug 2023 by Soldered
22+
*/
23+
24+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
25+
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
26+
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
27+
#endif
28+
29+
// Include Inkplate library to the sketch
30+
#include "Inkplate.h"
31+
32+
// Include font used
33+
#include "Fonts/Inter30pt7b.h"
34+
#include "Fonts/Inter20pt7b.h"
35+
#include "Fonts/Roboto_Light_120.h"
36+
37+
// Our networking functions, declared in Network.cpp
38+
#include "Network.h"
39+
40+
// Include header files
41+
#include "youtube_icon.h"
42+
43+
// Delay between API calls in miliseconds (10 minutes)
44+
#define DELAY_MS 10 * 60 * 1000
45+
46+
// Create object with all networking functions
47+
Network network;
48+
49+
// Create display object in 3-bit mode
50+
Inkplate display(INKPLATE_3BIT);
51+
52+
// Write your SSID and password
53+
char ssid[] = "";
54+
char pass[] = "";
55+
56+
char channel_id[] = ""; // To get the channel ID of the public channel, go to the wanted Youtube
57+
// channel in Google Chrome, right click and 'view page source', then
58+
// CTRL+F search for "externalId".
59+
60+
char api_key[] = ""; // API key, you can get one on https://console.developers.google.com/
61+
// First create a project (name it whatever you like), then click on
62+
// "Enable APIs and Services" (it's at the top of the screen, it has a
63+
// plus sign). Next select "YouTube Data API v3" in Enabled APIs and
64+
// Serivces. Go back at the homepage, click on "Create Credentials" and
65+
// click "API Key". After the key has been created, edit API Key to
66+
// restrict it only on use for Youtube API. YouTube Data API v3 in
67+
// Credentials submenu.
68+
69+
// Used to simplify UI design
70+
struct textElement
71+
{
72+
int x;
73+
int y;
74+
const GFXfont *font;
75+
char *text;
76+
char align;
77+
uint8_t text_color;
78+
};
79+
80+
// Buffers for printing channel data
81+
char buf_subs[15];
82+
char buf_views[15];
83+
char buf_videos[15];
84+
85+
// Struct for storing channel data, defined in Network.h
86+
channelInfo channel;
87+
88+
// Varaible for remembering how many times we have woken up (to only show the splash screen once)
89+
RTC_DATA_ATTR int bootCount = 0;
90+
91+
// Our UI elements
92+
textElement elements[] = {
93+
{20, 132, &Roboto_Light_120, channel.name, 0, 3},
94+
{19, 130, &Roboto_Light_120, channel.name, 0, BLACK},
95+
{270, 355, &Roboto_Light_120, (char *)NULL, 0, BLACK},
96+
{260, 335, &Inter20pt7b, "Subscribers:", 1, BLACK},
97+
{270, 515, &Roboto_Light_120, (char *)NULL, 0, BLACK},
98+
{260, 495, &Inter20pt7b, "Views:", 1, BLACK},
99+
{270, 675, &Roboto_Light_120, (char *)NULL, 0, BLACK},
100+
{260, 655, &Inter20pt7b, "Videos:", 1, BLACK},
101+
};
102+
103+
void setup()
104+
{
105+
// Begin serial communitcation (send some useful information; WiFi status, HTTP status, etc)
106+
Serial.begin(115200);
107+
108+
// Initial display settings
109+
display.begin();
110+
display.setTextWrap(false);
111+
display.setTextColor(BLACK);
112+
113+
// Show splash screen if it's the first boot
114+
if (bootCount == 0)
115+
{
116+
// Welcome screen
117+
display.drawImage(youtube_icon, 326, 321, 549, 123); // Draw the YouTube logo
118+
display.setCursor(357, 475); // Set cursor, custom font uses different method for setting cursor
119+
display.setTextSize(3);
120+
display.print("Youtube subscribers tracker!");
121+
display.display();
122+
display.clearDisplay();
123+
bootCount++;
124+
delay(1000);
125+
}
126+
127+
// Our begin function
128+
network.begin(ssid, pass);
129+
130+
while (!network.getData(&channel, channel_id, api_key, &display))
131+
{
132+
Serial.println("Retrying retriving data!");
133+
delay(1000);
134+
}
135+
136+
// These functions convert a long (ultoa) or integer(itoa) into a number in string format.
137+
elements[2].text = ultoa(channel.subscribers, buf_subs, 10);
138+
elements[4].text = ultoa(channel.total_views, buf_views, 10);
139+
elements[6].text = itoa(channel.video_count, buf_videos, 10);
140+
141+
// Our main drawing function
142+
drawAll();
143+
// Refresh
144+
display.display();
145+
146+
// Go to sleep before checking again
147+
// rtc_gpio_isolate(GPIO_NUM_12); // Isolate/disable GPIO12 on ESP32 (only to reduce power consumption in sleep)
148+
esp_sleep_enable_timer_wakeup(1000ll * DELAY_MS); // Activate wake-up timer
149+
150+
esp_deep_sleep_start(); // Put ESP32 into deep sleep. Program stops here
151+
}
152+
153+
void loop()
154+
{
155+
// Never here! If you are using deep sleep, the whole program should be in setup() because the board restarts each
156+
// time. loop() must be empty!
157+
}
158+
159+
// Our main drawing function
160+
void drawAll()
161+
{
162+
// Draw our UI elements
163+
for (int i = 0; i < sizeof(elements) / sizeof(elements[0]); ++i)
164+
{
165+
// Text settings
166+
display.setTextColor(BLACK);
167+
// Use custom font. You can find more about that here
168+
// https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts
169+
display.setFont(elements[i].font);
170+
display.setTextSize(1);
171+
172+
// 0 is aligned by left bottom corner, 1 by right
173+
if (elements[i].align == 0)
174+
display.setCursor((int)(elements[i].x * 0.96), (int)(elements[i].y));
175+
else if (elements[i].align == 1)
176+
{
177+
int16_t x, y;
178+
uint16_t w, h;
179+
180+
// Get how much the textx offsets pointer and draw it that much more left
181+
display.getTextBounds(elements[i].text, 0, 0, &x, &y, &w, &h);
182+
183+
display.setCursor((int)(elements[i].x * 0.96) - w, (int)(elements[i].y));
184+
}
185+
186+
// Print out text to above set cursor location
187+
display.print(elements[i].text);
188+
}
189+
}

0 commit comments

Comments
 (0)