I've been away from a little bit, but I'm back to discuss what I've been working on offline!
My super awesome wife purchased some super awesome little development boards for me for Christmas a couple of months ago! I tweeted this a few weeks ago:
The project currently displays random information about random Magic: The Gathering cards, but I'm eventually turning this into a little weather station for my desk. I figured I'd come over to my favorite little corner of the internet and show it off.
Let's start with the board and other tech I'm using. All of these components are from Adafruit, an electronics company that makes and sells all kinds of interesting little components for tinkering and making anything your heart desires!
Specifically, this project uses:
- A microcontroller packed with WiFi and Bluetooth capabilities, and a myriad of other things that make this board extremely versatile for IoT projects.
- Mine is the one that came with stacking headers.
- A breakout board with a 128x32 OLED screen attached.
- 3D-printed case designed for Adafruit Feathers (link to thingiverse)
One of the neatest things about the Adafruit Feather line is the Featherwings that you can optionally purchase for the board. In the tweet, what you're seeing is the OLED Featherwing that's attached to the ESP32 Feather using the stacking header pins.
The 3D printed case is just cool :D
Why did I choose the Feather for this project? For multiple reasons. First and foremost, the Feather line has many options for breakout boards that follow the same form factor as the boards themselves. All are stackable, and can change the capabilities of your board simply by switching them out!
Another reason is the size. I have a number of different boards: an Arduino Uno, Arduino Micro, Raspberry Pi Zero, and a couple Raspberry Pi 2s. Raspberry Pi is an excellent choice if you need the full capabilities of a Linux OS in a tiny space, and the newer boards even come with built-in wireless receivers. I didn't really need Linux though, and thought that the Feather offered a little more than my Arduinos did, for a smaller or comparable size.
The third main reason has to do with the software involved.
Feather boards can be programmed with the Arduino IDE, and you can utilize many popular Arduino libraries right out of the box. Writing Arduino code feels a lot like writing code for a Pebble watch: you can write a small C program that does a lot!
Here's a link to the code. (Please don't actually use
SSID as your actual SSID or
password123 as any password ever.)
Of the libraries I'm using, the most notable ones are:
- A magical library that allows you to parse JSON objects elegantly on the Arduino platform.
- Allows you to connect to the WiFi and make HTTPS calls.
- Adafruit OLED Driver
- Makes writing text to the OLED really easy.
- An online reference for Magic: The Gathering cards that has a REST API.
Honestly, the most difficult part of writing the code was just getting the board to connect to the WiFi and making an HTTPS call!
In a lot of programming languages, internet-related tasks are abstracted away to the point where you don't normally have to think about creating the connection to the internet and hand-writing an HTTP packet.
ArduinoJson makes it really easy to parse JSON bodies in Arduino though, so that part wasn't so bad.
The code is still pretty rough, and I haven't commented it, and it actually has a flaw in it that I need to fix:
After a while, the
client becomes unavailable and stops making HTTP calls. I think I might have to figure out how to reconnect the client if it becomes unavailable. At first I may have thought Scryfall was disconnecting me due to rate-limiting, but I don't think that's what it is since I'm only hitting it every 1/3 of a second. If you know what I'm doing wrong, lemme know!
The result is pretty cool I think: a small board that displays random information from the interwebs.
While this is just a small example of what this board is capable of, it's a good starting point for me, and it's going to be reminiscent of what my goal is for the board!
That's all I got for now guys. If you guys have any questions or if you know what I did wrong in my code, or if you liked the post, drop a comment and lemme know your thoughts!