Andrew Huynh
Thoughts 
and ramblings.
Email me!
Follow me on Twitter!
Check me out on LinkedIn.

COVID-19 Stats Tracker

2020 July 15 - San Francisco | 882 words

#esp32 #hardware #iot

One of things I wanted to accomplish when I began learning more about electronics was to build a small device from the ground up. This would include sourcing all parts, writing the necessary code, and designing and 3D printing an enclosure for the device. Given the state the world at this time, as my first foray into electronics design, I decided to make a little device to keep track of US COVID-19 stats.

Bill of Materials

Starting off small, I used a micro-controller that came with everything and the kitchen sink. The Wemos LOLIN D32 is a fantastic little piece of electronics that cost around $5. It's a dev board based around the ESP32-WROOM-32 module and is compatible with the Arduino platform. and comes with WiFi and Bluetooth out of the box. Perhaps a little overkill for what I'm building, but it allowed me to get up and running very quickly.

The MSP2402 screen is an 2.4 inch TFT LCD Screen with a resolution of 320x240 pixels. I chose a larger screen so that I can could make something large enough for "at-a-glance" stats that I could put on a shelf somewhere.

All major pieces were connected together on a protoboard using JST connectors and pin headers so that future revisions can reuse the same components.

Writing the Code

The code for the project is available on GitHub.

The project utilizes a couple useful utilities to make development a lot easier. First and foremost is the PlatformIO IDE plugin for VS Code. This brings some modern niceties that aren't available with the standard Arduino IDE such as dependency version management, a command line based build system, and the ability to use the code editor of your choice.

For the implementation itself, I used:

The basic loop function would look like something below:

1bool updateScreen = false;
2
3void loop() {
4 if (wifi.run() == WL_CONNECTED) {
5 unsigned long currentTime = millis();
6 if (currentTime - LAST_UPDATED_TIME >= UPDATE_TIME_MS) {
7 LAST_UPDATED_TIME = currentTime;
8 update_tracker()
9 }
10 }
11
12 if (updateScreen) {
13 render_stats();
14 }
15}

We want to make sure we have an internet connection (wifi.run()) and if everything looks good, we can go ahead and make a request to the API. If anything has changed in the stats, we'll set a flag to update the screen. Once that request is done, if the screen update flag is set, we can run through the code to re-render the contents of the screen.

All in all, the code was very straightforward and pretty similar to how you would build a similar stats tracker in any other language/platform.

Wiring Schematic

Now for the hardware.

To keep track of all the different wires, I used kicad to build out a schematic based on the breadboard prototype I had built. As I get better at kicad, my hope is eventually turn some of these schematics into actual PCBs that can be printed, but for the time being, it's a handy way to visualize the connections.

covid

For this first build, I left out the button which allows you to jump to different screens, but the code and schematic still handles this.

Below are some photos of the final soldered result:

Designing & Printing an Enclosure

For the enclosure design, I settled on using Shapr3D for the iPad. It is a fantastic application that has everything I need as a hobbyist to get things done. Since the enclosure is nothing more than a simple rectangular box, diving into more complex tools like Fusion 360 or AutoCAD just didn't seem like a lot of fun.

This was my first enclosure that was designed from scratch, and is comprised of two large halves that are screwed together. The files are available here for download.

I used my MonoPrice Maker Select v2 to print out the enclosure and test prototypes before finally putting everything together.

Finished Result!

Here's a video fo the COVID tracker booting up and loading the data

Some things I would like to work on for v2 of this enclosure: