My wife owns a tax office. So we are entering a time of year when all staff is putting in massive amounts of hours. To help a little bit with staff morale, I figured setting up a MagTag generating random inspirational quotes might be nice.
This post will walk through the steps of creating this device. Adafruit makes it easy to make projects like this quick and easy. Overall I think most of my time was spent printing the cover, and very little time was spent coding the device (it should go even quicker when I get better at using CircuitPython).
The quote generator uses the following hardware:
- Adafruit MagTag – This is a cool little ESP32-S2 wireless module and a 2.9″ grayscale E-Ink display in one package.
- 4 M3 magnetic feet – These screws hold on the rear cover and allow the MagTag to be mounted on a metal surface.
- 4 M3 screws – Four screws are used to hold the front cover on. Alternatively, 4 M3 screws could also hold the rear cover on if mounting on a metal surface is not necessary.
- 3.7V Lithium-Ion battery.
- 3D printed cover – more on that later in this post.
Plus, a USB-C cable is used to program and charge the battery.
I chose to use CircuitPython code to drive the device. I mostly did this to get more experience with the language. Since I am relatively new to CircuitPython, the code is mainly cobbled together and can probably be significantly improved.
Basically, the code will do the following once an hour:
- Wake up from sleep
- Connect to the wifi network (as set in Secrets.py)
- Download a random quote
- Display the quote and author on the screen
- Go back to sleep
The code is listed below. I used comments as much as possible, so my code can easily modify the code later.
The data source is https://type.fit/. This is an excellent little website that can be used to practice keyboard skills. The author of the site created an API so people could practice typing using random inspirational quotes. Type.fit’s author also allows others to grab quotes using that same API.
The two fonts used in this code are Arial-Bold-12.pcf and Arial-Italic-12.bdf. I got these fonts from Adafruit’s Shower Thoughts MagTag learn guide.
# TNT quote generator import time import random import alarm from adafruit_magtag.magtag import MagTag # Get data from this source DATA_SOURCE = "https://type.fit/api/quotes" # Get MagTag going, disable neopixels, set background, connect to network MAGTAG = MagTag() MAGTAG.peripherals.neopixel_disable = True MAGTAG.set_background("/bmps/background.bmp") MAGTAG.network.connect() # Set up text area for quote MAGTAG.add_text( text_font="/fonts/Arial-Bold-12.pcf", text_wrap=35, text_maxlen=210, text_position=( (MAGTAG.graphics.display.width // 2), (MAGTAG.graphics.display.height // 2) - 25, ), line_spacing=0.75, text_anchor_point=(0.5, 0.5), ) # Set up text area for author MAGTAG.add_text( text_font="/fonts/Arial-Italic-12.bdf", text_position=(MAGTAG.graphics.display.width // 2, 118), text_anchor_point=(0.5, 0.5), ) # Preload the fonts MAGTAG.preload_font() while True: try: # turn the response into json RESPONSE = MAGTAG.network.requests.get(DATA_SOURCE) VALUE = RESPONSE.json() # Choose a random quote QUOTE = VALUE[random.randint(0, len(VALUE) - 1)] # display the text MAGTAG.set_text(QUOTE["text"], 0) MAGTAG.set_text(QUOTE["author"], 1) # put the MagTag to sleep for an hour time.sleep(2) print("sleeping") PAUSE = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 60 * 60) alarm.exit_and_deep_sleep_until_alarms(PAUSE) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e)
I created a 296 128 pixels BMP file to use as the graphic. I resized and pasted a greyscale copy of our company logo into the BMP file. I think the logo graphic looks pretty sharp on the E-Ink display.
The 3D printed cover
I created a cover to protect the front and back of the MagTag. I wanted a simple design that allows access to the buttons (which I ended up not using for this project). On the back, I again wanted it to be simple and ensure the battery and other electronics are protected.
I broke out Fusion360 and created the covers. The front cover has built-in standoffs that place the cover just in front of the NeoPixels. At that depth, anyone can still use the four buttons.
I printed the case using Silk Yellow PLA from Mika3D. I chose yellow because it is a color that I’ve been told is emotionally happy.
I put this design up on Thingiverse as Thing 4722713 in case anyone wants to print it out.
I am happy with how the final product turned out. This device easily mounts onto the break room refrigerator with its magnetic feet. I also added the magnetic whiteboard and markers from Adabox 17. Hopefully, this fun little project will help a little with morale over the next few months.
Song of the day: Eye of the Tiger!
Since this device was created to hopefully inspire some happiness, I think this Survivor track is appropriate.
Bonus Song: Burning Heart
Speaking of cheesy inspirational Rocky songs…