Wi-Fi play a GIF from the web
What this example shows
Downloading a GIF over Wi-Fi and playing it on the display in a loop. GIF playback needs the display in 1-bit mode, so the sketch creates the display with INKPLATE_1BIT.
You need to supply three things: your Wi-Fi name (ssid), your Wi-Fi password (pass), and gifUrl, a direct link to a GIF file. The sketch comment says the link must point straight at the file, with no HTML redirect page. No API key is needed.
Example code
Trimmed from Inkplate10_GIF_From_Web.ino: the file header comment is removed, the sketch is otherwise unchanged. ssid, pass and gifUrl are empty on purpose, fill them in.
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
#endif
// Include needed libraries
#include "Inkplate.h" // Include Inkplate library to the sketch
#include "WiFi.h" // Include library for WiFi
// Enter your WiFi credentials
const char *ssid = "";
const char *pass = "";
// Direct link to a GIF file (no HTML redirect pages)
const char *gifUrl = "";
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library, GIF playback requires 1-bit mode
void setup()
{
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); // Clear frame buffer of display
display.display(); // Put clear image on display
display.setTextSize(2); // Use larger text for easier readability
display.print("Connecting to WiFi...");
display.partialUpdate();
// Connect to the WiFi network.
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
display.print(".");
display.partialUpdate();
}
display.println("\nWiFi OK! Downloading...");
display.partialUpdate();
display.clearDisplay();
// Download and play the GIF, looping forever, centered on the screen.
if (!display.gif.playGifFromWeb(gifUrl, E_INK_WIDTH / 2 - 125, E_INK_HEIGHT / 2 - 125, false, true, 20, true))
{
// If something failed (bad URL, download error, unsupported/corrupt GIF), write an error on the screen.
display.setTextColor(BLACK);
display.setTextSize(3);
display.println("GIF download/open error");
display.display();
}
WiFi.mode(WIFI_OFF);
}
void loop()
{
// Nothing...
}
Functions used
Inkplate(uint8_t mode)returns NoneCreates the display object. The mode picks how pixels are stored: `INKPLATE_1BIT` is black and white, which is what the sketches on this page use.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Display mode, INKPLATE_1BIT here. |
display.begin()returns voidInitializes the Inkplate library and its peripherals and clears the frame buffer. Call it once in `setup()`; later calls are ignored.
ReturnsNothing.
display.clearDisplay()returns voidClears the frame buffer. The screen itself does not change until you call `display()` or `partialUpdate()`.
ReturnsNothing.
display.display(bool _leaveOn = 0)returns voidSends the frame buffer to the e-paper panel and refreshes it.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | Optional. If set to 1, the panel supply stays on after the refresh. Defaults to 0. |
display.setTextSize(uint8_t s)returns voidSets the text scale. 1 is the base size, 2 is twice as big, and so on. The function comes from the Adafruit GFX base class the library builds on.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | s | Text scale factor. |
display.print(value)returns size_tPrints text or a number at the cursor, like `Serial.print()`. The display class inherits it from the Arduino `Print` class (through Adafruit GFX). The text appears after the next `display()` or `partialUpdate()`.
ReturnsNumber of bytes written.
Parameters
| Type | Name | Description |
|---|---|---|
various | value | A string, character or number to print. |
display.partialUpdate(bool _forced = false, bool leaveOn = false)returns uint32_tRefreshes only the parts of the screen that changed, without a full refresh. Works in black and white mode only.
ReturnsNumber of pixels that changed from black to white.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _forced | For advanced use with deep sleep. Defaults to false. |
bool | leaveOn | If true, the panel supply stays on after the update. Defaults to false. |
WiFi.mode(wifi_mode_t mode)returns boolSets the Wi-Fi mode. The sketch uses `WIFI_MODE_STA` (join a network), `WIFI_AP` (be an access point) and `WIFI_OFF` (radio off). Part of the ESP32 Arduino core.
Returns`true` if the mode was set.
Parameters
| Type | Name | Description |
|---|---|---|
wifi_mode_t | mode | The Wi-Fi mode. |
WiFi.begin(const char *ssid, const char *pass)returns wl_status_tStarts connecting to a Wi-Fi network. It returns right away; check `WiFi.status()` to see when the connection is up. Part of the ESP32 Arduino core.
ReturnsConnection status.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | ssid | Name of the Wi-Fi network. |
const char * | pass | Password of the Wi-Fi network. |
WiFi.status()returns wl_status_tReturns the current Wi-Fi connection state. `WL_CONNECTED` means the connection is up. Part of the ESP32 Arduino core.
ReturnsThe connection status.
delay(unsigned long ms)returns voidPauses the sketch for the given number of milliseconds. Arduino core function.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
unsigned long | ms | Time to wait in milliseconds. |
display.println(value)returns size_tSame as `print()`, then moves the cursor to the start of the next line. Comes from the Arduino `Print` class.
ReturnsNumber of bytes written.
Parameters
| Type | Name | Description |
|---|---|---|
various | value | Optional. A string, character or number to print. |
display.gif.playGifFromWeb(const char *url, int x, int y, bool invert = false, bool loop = true, uint16_t fullRefreshEveryFrames = 20, bool leaveOn = true)returns boolDownloads a whole GIF from an `http(s)` URL into memory and plays every frame on the 1-bit display. It blocks until playback ends, or forever when `loop` is `true`.
Returns`true` if playback ran or was stopped cleanly, `false` if the download or decoding failed.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | url | Direct link to a GIF file. |
int | x | X position of the GIF top-left corner. |
int | y | Y position of the GIF top-left corner. |
bool | invert | If true, swaps black and white. Defaults to false. |
bool | loop | If true, plays forever. Defaults to true. |
uint16_t | fullRefreshEveryFrames | Forces a full refresh every N partial updates to clear ghosting. 0 disables it. Defaults to 20. |
bool | leaveOn | If true, keeps the panel supply on between frames. Defaults to true. |
display.setTextColor(uint16_t c)returns voidSets the text color with a transparent background. Comes from the Adafruit GFX base class.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
uint16_t | c | Text color, for example BLACK. |
What to expect
The display prints "Connecting to WiFi...", adds a dot every half second, then "WiFi OK! Downloading...". The screen clears and the GIF plays in a loop. The position E_INK_WIDTH / 2 - 125, E_INK_HEIGHT / 2 - 125 centers a GIF that is 250 pixels square. If the download or decoding fails, the screen shows "GIF download/open error".
The library refreshes the whole screen every 20 frames to clear ghosting, which is the 20 in the call.