Googly eyes never fail to make people smile and laugh where ever they unexpectedly show up. I first ordered some circular displays for another project but while testing them out I thought it would be fun to hook up an accelerometer and create a googly eye.
After initial positive feedback, I decided to create googly eyes glasses so that I can wear googly eyes everywhere. This project teaches you how to build your own googly eye glasses.
Like many open source projects, this one owes many thanks to others people who built the foundation upon which I started. Tod Kurt for explaining how to have multiple displays in CircuitPython, the Ruiz brothers for the 3D printable LED glasses model that I modified and Phil Burgess who had done a googly eye Arduino project that I found in the middle of my own work, that helped me understand the math involved to make the edge collisions look so much better. Links to these projects are found later.
Parts InformationThe Things section lists all the parts used but there are a couple small notes about them:
- AdafruitFeather RP2040 - The microcontroller driving this project does not have to be RP2040 based. The microcontroller does need to support two SPI buses and one I2C bus (you can probably run off one SPI bus but speed may be slower. I never tested it).
- Adafruit LSM9DS1 - The reason I chose this accelerometer is simply because I had it already. Any accelerometer should work. Adafruit has a new STEMMA version of the LSM9DS1 if you wish to avoid some soldering.
- 1.28 inch TFT Round Display - These circular displays were purchased off AliExpress. They use a GC9A01 driver and have a 240x240 resolution. The code was written assuming 240x240 so if you try a different size display the size settings will need to be changed. The driver initialization is simple to swap out in CircuitPython if your display uses another driver chip. The code should run on square displays but contained in a circular shape.
The glasses print consist of three parts: the frame, the left arm that holds the Feather and the right arm that holds the accelerometer. All the parts will print flat, not needing support. The arms connect to the frame with two M2.5 screws and nuts.
Next step is to wire the electronics together and attach them to the glasses. It is easiest to do the soldering before you attach the electronics to the glasses.
Important: Be careful where you want the wires to go. In my build I had the TFT displays feed the wires through the frame to the Feather. This meant that once I soldered the wires to the TFTs I had to feed the wire through the hole in the frame before soldering the other wire ends to the Feather.
All the connections between electronic parts are shown on the wiring diagram.
- Both the TFTs and the LSM9DS1 wire VCC to the 3.3V on the Feather and GND to ground.
- The LSM9DS1 has SCL/SDA connect to the corresponding pins on the Feather that are I2C bus 1 on the RP2040.
- Each TFT has 5 pins to connect to the Feather that attach to the SPI0 and SPI1 bus on the RP2040. SCL relates to SPI SCK, SDA relates to SPI MOSI and CS to SPI CS. The DC and RST pins on the TFT do not require specific pins on the RP2040. The pins they connect to where chosen arbitrarily.
All the components connect to the glasses with M2 screws and nuts. The parts attach to the outer side of the glasses.
The last step is to load the code on the glasses and modify any configuration settings that you want to adjust. All the code is available on GitHub.
The glasses run on CircuitPython and were tested on version 7.3 and 8.0-alpha. To be able to display the eyes on two displays at once you will need to custom built version of CircuitPython that enables two displays. I have included a pre-built two display CircuitPython version for the Adafruit Feather RP2040 in the Googly Eye repository. Tod Kurt's blog post has more details on how to enable two displays if you want to build CircuitPython with two displays for another board.
Two external libraries are required for the code to run. The LSM9DS1 library is found in the main CircuitPython library bundle. The GC9A01 display driver is found in the CircuitPython community bundle. Both these libraries must be placed in the lib directory on your CircuitPython drive.
There are two python files in the Googly Eye repository needed to run the glasses. The primary file code.py and googlyeye.py that defines a class that runs a single eye.
The code displays two independently acting googly eyes with default settings that were chosen only for what I thought looked good.
At the start of code.py there are four settings that are may be modified to allow you to change the behavior of the eyes:
- G_SCALE : Can be used to increase the effect of acceleration to make the eyes more responsive. The higher the number the more responsive.
- DRAG : 1.0 represents no friction. Any value lower will have the eye slow down as it moves. The closer to 0 the greater the friction.
- ELASTIC : 1.0 represents no loss of energy when the eye bounces off the sides. The closer to 0 the more energy lost on a bounce.
- EYE_RADIUS : The size of the pupil itself. The larger this value is the larger the eye will appear. But be careful of too large a size, as more of the screen needs to refresh each update and the slower the framerate will be.
So you have amazed your friends with your fun and exciting googly eyes, and if you have not tried them on a Teams meeting for work yet what are you waiting for? But what's next.
Just like their plastic counterparts the electronic googly eyes have a million uses. Some ideas I've tossed about are:
- Attach one to any object, just like everyone does with plastic googly eyes.
- Change the pupil color or graphic. CircuitPython supports images and their are many tutorials that would allow you to change the vector circle to any image you want.
- Change the eye movement. Have the eye default to the center and bounce around a set point.
- Add sensors to track motion and have the eyes follow someone around the room. Extra points if you add this to a painting.
- Add blinking to the eyes, something plastic eyes could never do!
If you do build the glasses or any ideas based on them please let me know or tag me when you (hopefully) share your creation. I would love to see.
Comments