“Building Your Own ‘Interactive’ Digital Pet with Adafruit’s Matrix Portal”
One late night, I had the idea of dressing up as a human tamagotchi for Mardi Gras parade. I thought it would be cool way to dive into hardware and costume making. Figuring out the execution of this project was a little tough. Initially there was that inclination (trap) people may have where they want to build it from scratch. However from a user’s perspective I realized most people won’t care about the underlying mechanics of how egg hatching works. As much as I’m doing it for me, I also wanted it to look cool, so I simplified it down to interactive buttons mapped to specific animations.
What You’ll Need
- Adafruit MatrixPortal M4
- Animated GIF Player for Matrix Portal Contains relevant supply information
- 1x4 Arcade buttons
- Your chosen sprites - The Spriters Resource is a great place to find these.
- An environment to run Python, like CircuitPython (though it seems like it can now be run in the browser according to adafruit)
Step 1: Setting up the Adafruit MatrixPortal M4
To begin, you’ll need to set up your Adafruit MatrixPortal M4. For a detailed walkthrough on the setup process, visit this guide.
Step 2: Creating the Animations
With your MatrixPortal M4 ready to go, it’s time to create some animations for your Tamagotchi. I used the Piskel app and the EZGif online sprite sheet cutter tool to create and edit my animations. Tip: You want to make sure the background of your background is black in color.
You can convert the gif to bmp using ImageMagick:
convert idle.gif -compress none -depth 16 idle.bmp
You might need to adjust gamma correction if the colors come out wonky. Adafruit has an article on how they do this :
python3 protomatter_dither.py 8 idle.gif
I found this solution from this github thread: Image Load Issues
Step 3: Coding with CircuitPython
We’ll use CircuitPython to program the tamagotchi. If you’re unfamiliar with CircuitPython, Adafruit has an excellent introductory guide to get you started.
You’ll want to create distinct functions for each interaction with your tamagotchi. The actions we’ve included are: feeding, kissing, praising and idling. Each action is tied to a different gif that will play when the action is performed.
You can use the Adafruit’s guide on Animating Sprites with CircuitPython as a good starting point.
The code I used is in this repository: https://github.com/imccorve/tamagotchi-led. You can copy and paste the contents of circuitpython-files/ into the CIRCUITPYTHON/ folder of the matrixportal.
Step 4: Connecting Buttons to Actions
To make the tamagotchi interactive, we will use arcade buttons. These buttons will trigger different actions such as feed, kiss, praise, etc. We connect the buttons to the Adafruit MatrixPortal M4 and assign each button an action (a specific animation).
You can follow this Adafruit guide on wiring arcade buttons for help.
Step 5: Assembling the Tamagotchi
Once all the components are prepared, you can put everything together. Connect your MatrixPortal M4 to your computer and upload the code. Now, your own Tamagotchi should be up and running! Watch it in action
@imonitroni Using the arcade 1x4 from adafruit I can now interact with Mametchi-chan ❤️😩 but there’s still more work to be done until it’s wearable for my Mardi Gras outfit#adafruit #creativecoding #ledlights #tamagotchi ♬ Boy's a Liar - PinkPantheress
I think next would actually be cool to put a tamagotchi emulator directly on the matrixportal to get the full tamagotchi experience. Though the purpose of a tamagotchi is to be pocket sized so having a 32x32 screen might be difficult to transport. (Unless you incorporate the screen into a backpack or workbag? https://learn.adafruit.com/matrix-portal-rgb-display-handbag)
Troubleshooting
If you encounter any issues during the process, refer to the following resources:
Questions?
Send me a DM!