Watch @EmojiTetra Live on ESP32 OLED Display

@EmojiTetra is an online game resembling Tetris, hosted on Twitter platform. Every 20 minutes, the @EmojiTetra account posts a tweet that displays the current game board, along with a four-option poll that allows visitors to vote for the game's next move: left, right, down, rotate, or plummet.

a tweet by @EmojiTetra

I find this game interesting. To watch or participate in @EmojiTetra, I need to unlock my tablet, open Twitter app, search for "EmojiTetra", and scroll past the pinned tweet in order to see the current game move. In total, this process needs 17 taps. Looking at the 0.96 inch OLED display on my Heltec WiFi_Kit_32 board, I'm thinking: can I play @EmojiTetra on an ESP32?

Twitter API

Twitter offers an API that allows applications to retrieve and post tweets. GET statuses/user_timeline resource, for example, retrieves a collection of the most recent tweets posted by a specific user. To watch the game, "user timeline" is exactly what I need to retrieve the current game state.

Moving Dot: How Many Displays Can You Fit on an ESP8266?

In yoursunny.com's toy vault, there is an assortment of LED displays. I'm wondering, how many LED displays can I fit on an ESP8266? So I built this "moving dot" demonstration, with two LED displays and a buzzer.

moving dot demo

The LED matrix serves as the game board. A dot appears on the matrix. In each time step, the dot randomly moves by one pixel or stays in the same position. The 4-digit displays current time step number. Whenever the dot reach any of the four corners, the buzzer plays a piano note selected between C3 and B5.

Hardware

Bill of materials

Yuma Mega

Since my spontaneous visit of Pima Air & Space Museum on my 2015 birthday, I started a tradition of having a little road trip for every birthday. I rode a bike to Sweetwater Wetlands Park to see some birds with Tucson Audubon Society on my 2016 birthday. When my 2017 birthday came close, I planned something big: I wanted to attend the Yuma Mega, the biggest geocaching event in the Southwest region.

Finding the Event

I started geocaching as a hobby in 2013. Geocaching for me is mostly an individual sport: I rode bikes all over Tucson metro area, lift up lamp post covers and poke my hand into guardrails to find mint containers hidden within. Event Caches, on the other hand, are special geocaches that allow geocachers to gather and socialize. I browse Geocaching.com's event listing from time to time, and attend those events regularly. Normally, 15~30 people would show up in a local restaurant or city park. People would tell their stories, and plan out-of-state trips to search for large number of geocaches.

Yuma Mega is not just any event, but a "Mega-Event Cache". Geocaching HQ awards Mega status to events attracting more than 500 geocachers. I heard about Yuma Mega in 2015, but the date was adjacent to a conference trip so I wasn't able to arrange it. 2017's Yuma Mega event falls on Sunday Feb 12, which happens to be my birthday. 2017 is also my last year living in Arizona. It was "now or never", so I have to attend Yuma Mega!

I made up my mind on Nov 24, 2016, and booked a rental car and a motel room for the trip. Both reservations were cancelable in case there's a paper deadline on that weekend, but thankfully there wasn't one, so I'm greenlighted for the trip.

Install OpenCV 3.2.0 on Raspberry Pi Zero W in 15 Minutes

OpenCV, or Open Source Computer Vision Library, is an open source computer vision and machine learning software. It works on Raspberry Pi computers, and can process photos captured by the Raspberry Pi Camera Module.

OpenCV has two supported versions: 2.4.x and 3.x. New features are being added to 3.x branch, while 2.4.x only receives bug fixes and efficiency fixes. It is recommended that new developments should use OpenCV 3.x, to take advantage of new features. However, the official operating system for the Raspberry Pi, Raspbian Stretch, comes with OpenCV 2.4.9. While I am not yet familiar with OpenCV algorithms, one thing notably missing from OpenCV 2.4.9 is a Python 3 binding.

I wanted to have OpenCV 3 running in Raspbian Stretch on a Raspberry Pi Zero W. Unable to find existing packages for Pi Zero and Stretch, I had no choice but to compile my own OpenCV 3. I decided to do it the proper way: build a backported Debian package. This method is superior to installing from the source code, because the packages can easily be deployed to other Raspberry Pi Zero W computers. I followed the Simple Backport Creation instruction, and spent a week building the packages. Now I'm sharing my compiled packages, so that you can use them if you dare.

What You Need

The Quest of Building OpenCV 3.2.0 Debian Packages on Raspberry Pi Zero W

The newest members in my toy collection are a Raspberry Pi Zero W and a NoIR Camera Module, purchased in Dec 2017. Recently, I witnessed an impressive Contour Detection demo at MoCoMakers meetup. I read their source code, and it has a dependency on cv2 Python package. Therefore, the first step to get it working on my RPi Zero would be installing OpenCV that provides cv2 package.

While Raspbian Stretch offers a python-opencv package, it is version 2.4.9 released in 2014, and it only works with Python 2 but not Python 3. Since I'm starting from scratch, I wanted to develop on newer platforms: OpenCV 3.x and Python 3.

Many online tutorials suggest compiling OpenCV from source code. There are also a few sites offering pre-compiled tarballs, but these are either compiled for the Raspberry Pi 3, or built for Raspbian Jessie; neither would be compatible with my Raspberry Pi Zero W running Raspbian Stretch. Therefore, I started my quest to build OpenCV 3 for Pi Zero.

Debian Package > Source Code

When I first learned Linux, the standard process of installing software is wget, tar xzvf, ./configure, make, make install. Today, this is no longer recommended because software installed this way is difficult to remove and could cause conflicts. Instead, it is recommended to install everything from Debian packages.

PO Box 3943

PO Box, or post-office box, is a uniquely addressable lockable box located on the premises of a post office station. There is a wall of PO Boxes in the University of Arizona's Student Union Memorial Center, where it costs $25 to rent one for a semester. I found them interesting, although I didn't use one because I could receive mail in my apartment, and the Tucson heat did a good job to keep the grounds dry so I didn't have to worry about packages.

When I first came to Maryland, I rented a room in Orchard Place neighborhood. It rains often, and the house does not have a porch. Seeing the post office right outside the neighborhood, I thought it would be the perfect chance to try a PO Box.

Opening My PO Box

Rental fee for a small PO Box at Diamond Farms post office is $54 for six months, or $30 for three month. I would live at Orchard Place for two or three months, so the 3-month option seems more reasonable. However, it is cheaper to choose the 6-month option, because the post office offers a ½ refund if I close the PO Box within three months, so the final price is only $27.

PO Boxes at this location include "premium service": every PO Box comes with a street address, and can accept deliveries from non-postal carriers. This is an important factor for me, because most items I buy online are not shipped via USPS, and having a street address allows me to receive them at the PO Box.

NFD on Windows 10 WSL

The NDN Forwarding Daemon (NFD) connects every Ubuntu and Mac OS machine to the Named Data Networking (NDN) testbed network. While it's awesome to get your NFD connected from a Linux server or a Macbook, 82.56% of the desktop users running Windows are out of luck. Compiling NFD for Windows is possible, but the amount of patches needed is astonishing.

Then the good news came: Microsoft announced Windows Subsystem for Linux (WSL), which lets developers run Linux environments directly on Windows, unmodified, without the overhead of a virtual machine. Ubuntu is the first Linux distribution supported by WSL. This means, we can now run NFD natively on Windows!

How to Install NFD on WSL

This section outlines how to install NDN Forwarding Daemon (NFD) on Windows Subsystem for Linux (WSL). As of this writing, I have Windows 10 version 1709 (Fall Creators Update), and the latest NFD release is version 0.6.1.

The steps to install NFD on Windows are:

How to Flash C.H.I.P Offline

Next Thing Co (NTC), the company that made the $9 C.H.I.P computer, is not doing well: orders are not shipping on time, and support is not answering emails. While the little CHIPs would still work even if NTC no longer exists, same cannot be said for firmware flashing: the recommended method for flashing firmware is through Chrome App developed by NTC, which in turn downloads from NTC's file servers. If Next Thing Co evaporates and their file servers go offline, the Chrome App would not be able to download the firmware, and therefore I cannot re-flash my CHIPs if I ever mess up their operating system.

To keep my C.H.I.Ps working for as long as possible, I have to plan for the inevitable and find out how to flash a CHIP without relying on the Internet, or at least, without relying on the opensource.nextthing.co file server. NTC has published some scripts, known as CHIP-tools, to work with CHIP computers. The chip-update-firmware.sh script is a command line tool to flash the device. While the content of this script is complicated, to make it work offline, I just need to figure out what it needs from NTC file servers, and download these files in advance.

A brief read and tests indicate that chip-update-firmware.sh has the following workflow:

  1. Verify all necessary programs are available.
  2. Select a flavor according to command line arguments. It is one of server, gui, pocketchip, and buildroot.
  3. Download a latest file that contains the latest firmware version number.
  4. Download SPL, sunxi, and U-Boot images.
  5. Connect to CHIP in FEL mode, and determine whether the CHIP has a Hynix or Toshiba NAND chip.
  6. Download CHIP operating system image that suitable for the NAND chip.
  7. Connect to CHIP in Fastboot mode, and send the operating system image to CHIP.

Files for each flavor is hosted in a different directory on the file server. For server flavor, the files are: