Open the Arduino IDE and go to the library manager. Download the Adafruit SSD1306 library. (A library is just code someone else made for you to use in your code.)
You might ask yourself, "What are SDL and SDA pins for?" They help you use the Inter-Integrated Circuit (I2C) protocol built into your board, which in turn lets you use 1 or 2 wires to get the job of multiple data wires done!
Now that we are wired up, let's go ahead and get our project started. We are going to make 2 files, one for our code and another for the animation. We don't really need to, but it keeps things cleaner in the long run.
We are going to make a new sketch in Arduino IDE and then save it with a name you will remember. Next you will want to make a file called "animation.h" (using notepad or VS code) in your arduino project folder that you just made.
Now we are going to use 2 websites to help us out. A GIF splitter, and an image to code generator.
The first one you want to use is: https://ezgif.com/split Upload the GIF you saved, click split frames, and download frames as zip. Extract the zip
Upload all the frames to: https://javl.github.io/image2cpp/ There are a few settings you will want to play with here, especially image size, scaling, brightness, and center image. Double check the preview screen to make sure you have your settings correct.
Now back to our main code for the ESP32 or Arduino. I have made a simple script that uses the animation.h file we made and goes through all the images in that file smoothly. Feel free to play with the delay to make it faster or slower. I will add comments to the code to explain more of it. Paste this code into your arduino sketch(The INO file, not the .h one)
//these are called libraries
#include <Wire.h>
//You get these libraries by using the library manager and hitting install
//It is used to interact with OLED
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
//This is the file you made for your GIF
#include "animation.h"
//This is to set the OLED size
#define WIDTH 128
#define HEIGHT 64
Adafruit_SSD1306 display(WIDTH, HEIGHT, &Wire, -1);
//this gets the amount of images from your animation.h file.
//In that file you have an array automatically made that holds all your images called : epd_bitmap_allArray
int frameCountFromGif = sizeof(epd_bitmap_allArray)/sizeof(epd_bitmap_allArray[0]);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
//inside this loop, we have a for loop that says
//"for each image in the gif, display it, wait 30 milliseconds, clear the display, then move on to the next image"
void loop() {
for (int i = 0; i < frameCountFromGif; i++) {
display.clearDisplay();
display.drawBitmap(0, 0, epd_bitmap_allArray[i], 128, 64, SSD1306_WHITE);
display.display();
delay(30);
}
}
Now plug in your Arduino/ESP32, upload the code, and watch the animation play! Try using different GIFs and increase or decrease the speed. Note the gif will have to be on the shorter side or it might take up too much space on your Arduino; when you verify or compile it will throw an error saying too large. If you REALLY cannot live without the GIF you want, you can always cut half the images out of your split GIF without it looking too choppy.