Seeed Studio Round Display for XIAO Christmas Ball
by feiticeir0 in Circuits > Electronics
379 Views, 2 Favorites, 0 Comments
Seeed Studio Round Display for XIAO Christmas Ball
Bring the festive spirit to life with a Christmas-themed interactive snow globe! This project uses the Seeed Studio Round Display and XIAO ESP32S3 to create a snow animation, complete with dynamic falling snow, wind effects, and touch interaction.
Supplies
Hardware Requirements:
Software Preparation
First Use
To use the Round Display, head to Getting Started with Round Display for XIAO to install the necessary libraries.
Try some of the examples to see if everything is working well.
Libraries
For this project, we're going to use the libraries that come bundled with the Seeed Studio Round Display For XIAO
Install all the libraries like specified in the tutorial Getting Started with Round Display for XIAO. After that, you need the following:
- PNGdec library .
- Update LVGL library (or not install the one from Seeed Studio github)
Images
Our images are PNG images stored in Flash Arrays. They are displayed using PNGdec library.
All images must be PNG
All the images used are AI generated .
Our background images need to be prepared for that TFT_eSPI can display them and they fit well on the Round Display for XIAO.
Prepare images
Resize Images
Our Round Display for XIAO has a 240x240 resolution. We need to resize the images. I'm going to show how to do it using GIMP
- Open the image
- Go to Image > Scale Image
- Set Width and Height to 240. Because the Keep Ratio is selected (the chain), once you change the width, the height should also change.
- Press the Scale button.
- Save the image (I'm going to override the old one)
Create the Flash Arrays
NOTE: This instructions are inside the TFT_eSPI Flash_PNG example.
To create the flash array, go to File to C style array converter
The steps are:
- Upload the image using Browse .
- After uploading the image, we need to set some options
- Treat as binary
- All the other options gray out.
- Let's change the Data type to char
- Press convert. This will convert the image to an array.
- You can now press the button Save as file to save your image and add it to your Arduino Sketch or press the button Copy to clipboard If you Copy to clipboard, you'll have to press the 3 dots on the right side of the Arduino editor and choose New Tab
- Give it a name (generally your image name with .h extension)
- You'll end up with all your images as .h files.
Code
Here's the code for the Christmas ball. A little explanation of the principal functions of the code. The code also includes some comments.
Headers and libraries
We start by including some libraries.
Remember that you need to have the Seeed Studio libraries installed.
Background images
Here are the functions to manage the background images
- Struct: Each background image is stored as a Background struct containing:
- data: Pointer to the PNG data.
- size: Size of the PNG file.
- Array: The backgrounds array stores all the background images. The currentBackground variable tracks the currently displayed background.
Snow particles Simulation
- Initialization of particles
- It initializes numParticles with random positions and speeds.
- Updates particle positions with:
- Falling Effect: Each particle moves down.
- Wind Effect: Adds a slight horizontal drift.
- Wrap Around: Particles reset to the top when they exit the bottom.
- Rendering particles:
- It renders each particle as a small white circle
PNG Decoding
- Loads and decodes the current background PNG using the png.openFLASH() function
Touch interaction
- Detects a touch event using the chsc6x_is_pressed() and changes the background image by incrementing currentBackground
Setup and loop
- Setup
- Initializes the display, touch input and snow particles
- Main loop
- Clears the sprite, renders the current frame (background + particles), and checks for user input.
The .ino file is attached here, as well the 3 background images that I've used as .h files.
Double Buffering
To reduce the flickering and improving animation smoothness of the snow flakes, we use double buffering.
This allows us to draw in an off-screen buffer before displaying it on the screen.
Double buffering here
In this project, the TFT_eSPI library's TFT_eSprite class implements double buffering.
- Sprite creation
- The sprite (off-screen buffer) is created in the setup() function:
- Drawing the buffer
- All drawing operations (background rendering and snow particle animation) are done on the sprite:
- Updating the display
- After the frame is fully drawn in the sprite, it is pushed to the display in one operation:
- This transfers the buffer's contents to the screen instantly.
- Reuse
- The sprite is reused for every frame by clearing it at the start of the loop():
Advantages of Using Double Buffering
- Smooth Snow Animation: The falling snow particles are updated seamlessly without flickering.
- Dynamic Background Switching: The touch-triggered background changes happen without visible delays or artifacts.
- Efficient Rendering: Drawing in memory (RAM) is faster than directly updating the display line by line
Future and Conclusion
I'm hoping that someone creates a 3D ball to place the Seeed Studio Round display for XIAO in it and then place it on the Christmas Tree.
I'm also hoping to change the code that the images are loaded from the SD Card instead of using FLASH arrays.
Hope you liked my project. Just add a bit of magic to your Christmas