Interactive Snow Globe Touch: a Festive DIY Raspberry Pi Project
by feiticeir0 in Circuits > Raspberry Pi
27 Views, 0 Favorites, 0 Comments
Interactive Snow Globe Touch: a Festive DIY Raspberry Pi Project
Imagine bringing a winter wonderland to life with falling snow, interactive backgrounds, and a touchscreen experience—all powered by a Raspberry Pi! This project is perfect for the holiday season or for learning how to create an engaging, interactive display. Whether you're a maker, coder, or holiday enthusiast, this project combines creativity, coding, and technology to spread some festive joy!
Supplies
Hardware
- Raspberry Pi (e.g., Raspberry Pi Zero 2 W - older version should also work)
- Touchscreen display (e.g., Pimoroni HyperPixel or any HDMI touchscreen)
- Power supply for Raspberry Pi
- MicroSD card (16GB or larger)
- USB keyboard/mouse (for initial setup)
- Optional: Case for Raspberry Pi
Software
- Raspberry Pi OS
- Required libraries: libsdl2-dev, libsdl2-image-dev, libevdev-dev
- Git for cloning the repository
Set Up Your Raspberry Pi
Before anything, we need to install the Raspberry PI
Install Raspberry Pi OS:
- Download and flash Raspberry Pi OS to your microSD card.
- We don't need the full version with desktop. The Lite version is enough.
- Insert the card into the Raspberry Pi and boot it up.
Update the System
Install Dependencies
Clone the Project
After having the Raspberry PI ready, use Git to clone the project to your Raspberry Pi.
Enter the directory
Add Background Images
Our project slides through images, so we may add more images to the project.
Add your .jpg background images to the images directory in the project folder. For example:
Build and Run
Let's now build the program.
Inside the ChristmasSnowGlobe directory:
After making it, let's run it and see if it works
- Replace 720 with your display's resolution.
- Replace /dev/input/event0 with your touchscreen's input device.
Switch Backgrounds:
- Tap the screen to change backgrounds dynamically.
To view the help message:
Touch
You probably need to add your user (or the user running this program) to the input group. Check with your distro for the correct group.
Autostart
To autostart the program when the Raspberry PI starts or reboots, we can use our.basrc file.
Just configure the Raspberry PI OS to auto login to cli:
1. System Options > S5 Boot / Auto Login > B2 Console Autologin
Next, edit your .basrc to execute the program once you login.
And place the following line at the end of the file:
Save and exit.
NOTE: We need to execute it inside the directory because of the images path. Something to change in a next release.
Reboot your RPi and see if it works.
If using Pimoroni's Hyperpixel Touch 4.0 screen
Using Pimoroni's Hyperpixel Square 4.0, sometimes the touch device changes between reboots. So, it may not always be event0.
I've created a script to find the correct touch device for the Pimoroni's Hyperpixel Touch 4.0. This way, when invoking the Christmas Snow Globe, I always have the right device.
To use the script to find the device, the correct invocation is:
The script findPimoronisTouchDevice.sh returns the correct event device for the touch screen.
Customization
Adding Your Own Backgrounds
- Replace or add .jpeg images in the images directory.
- The program automatically detects all .jpg files in the folder.
Adjusting Snowflake Properties
You can modify the following aspects in the code:
- Number of Snowflakes:
- Wind Speed and Acceleration:
- Snowflake Speed and Size:
Scaling for Larger Displays
Modify the screen resolution via the command-line arguments or adjust the default values in the code:
Code Explanation
1. Initialization
- The program initializes SDL2, SDL2_image, and libevdev for rendering graphics and handling touch input.
- Command-line arguments allow setting screen width, height, and the touchscreen device path.
- If you're using the Pimoroni's Hyperpixel touch 4.0 screen, every time the Raspberry PI boots, the touch device can change. This invalidates an automatic execution.
- I developed a script that will detect the touch device. This way, I can always pass the correct device to the program.
2. Snowflake Simulation
- Each snowflake is represented by a struct containing its position, size, and speed.
- Snowflakes are updated dynamically to simulate falling with wind effects.
3. Dynamic Backgrounds
- Background images are loaded from the images directory using SDL2_image.
- Touch events cycle through the loaded backgrounds.
4. Touchscreen Integration
- The program uses libevdev to read raw input events from the touchscreen device.
- The EV_ABS and EV_SYN events detect touch positions and release states.
Touch Device
To find out your touch device, you can install evtest and use it to find the device:
Run the software
It should list some devices and one of the them is your touch device.Here's an example using Pimoroni's HyperPixel 4.0 Square
Select one, touch it and see if outputs text.
If you see text, that's the one you should use.
Conclusion
Exit the application
To exit the program, we have to kill it.
In a terminal, execute the following script to kill the snow wonderland:
Future Improvements
Here are some improvements that I'm hoping to make:
- Dynamic Background Scaling: Automatically scale backgrounds to fit the screen resolution.
- Audio Integration: Add festive music or sound effects.
- Enhanced Visual Effects: Introduce twinkling lights or a dynamic weather system.
- Exit Cleanly: Find a way to exit the software without having to kill it.
Conclusion
I hope you enjoy creating and customizing your own Interactive Winter Wonderland!
Add your family photos or favorite holiday scenes to make it uniquely yours and create a cozy, festive atmosphere for everyone to enjoy.
Have fun, and let your creativity snowball into the perfect holiday project! ❄️