Skip to main content

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.

Select Board
Inkplate10_GIF_From_Web.ino
// 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 None

Creates 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

TypeNameDescription
uint8_tmodeDisplay mode, INKPLATE_1BIT here.
display.begin()returns void

Initializes the Inkplate library and its peripherals and clears the frame buffer. Call it once in `setup()`; later calls are ignored.

ReturnsNothing.

display.clearDisplay()returns void

Clears the frame buffer. The screen itself does not change until you call `display()` or `partialUpdate()`.

ReturnsNothing.

display.display(bool _leaveOn = 0)returns void

Sends the frame buffer to the e-paper panel and refreshes it.

ReturnsNothing.

Parameters

TypeNameDescription
bool_leaveOnOptional. If set to 1, the panel supply stays on after the refresh. Defaults to 0.
display.setTextSize(uint8_t s)returns void

Sets 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

TypeNameDescription
uint8_tsText scale factor.
display.print(value)returns size_t

Prints 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

TypeNameDescription
variousvalueA string, character or number to print.
display.partialUpdate(bool _forced = false, bool leaveOn = false)returns uint32_t

Refreshes 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

TypeNameDescription
bool_forcedFor advanced use with deep sleep. Defaults to false.
boolleaveOnIf true, the panel supply stays on after the update. Defaults to false.
WiFi.mode(wifi_mode_t mode)returns bool

Sets 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

TypeNameDescription
wifi_mode_tmodeThe Wi-Fi mode.
WiFi.begin(const char *ssid, const char *pass)returns wl_status_t

Starts 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

TypeNameDescription
const char *ssidName of the Wi-Fi network.
const char *passPassword of the Wi-Fi network.
WiFi.status()returns wl_status_t

Returns 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 void

Pauses the sketch for the given number of milliseconds. Arduino core function.

ReturnsNothing.

Parameters

TypeNameDescription
unsigned longmsTime to wait in milliseconds.
display.println(value)returns size_t

Same as `print()`, then moves the cursor to the start of the next line. Comes from the Arduino `Print` class.

ReturnsNumber of bytes written.

Parameters

TypeNameDescription
variousvalueOptional. 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 bool

Downloads 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

TypeNameDescription
const char *urlDirect link to a GIF file.
intxX position of the GIF top-left corner.
intyY position of the GIF top-left corner.
boolinvertIf true, swaps black and white. Defaults to false.
boolloopIf true, plays forever. Defaults to true.
uint16_tfullRefreshEveryFramesForces a full refresh every N partial updates to clear ghosting. 0 disables it. Defaults to 20.
boolleaveOnIf true, keeps the panel supply on between frames. Defaults to true.
display.setTextColor(uint16_t c)returns void

Sets the text color with a transparent background. Comes from the Adafruit GFX base class.

ReturnsNothing.

Parameters

TypeNameDescription
uint16_tcText 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.