二十一世纪电视之现实

1998年,我参加小学生作文竞赛时写下了一篇《二十一世纪电视畅想》。 20年过去了,让我们来看看,这些畅想变成现实了吗?

小朋友们,你们想过没有二十一世纪的电视是怎样的呢? 我学习之余,常在潜心研究、精心设计着它们呢。我告诉大家,到那时的电视机呀,小的只有手表这么小,大的足有三层楼高。

在二十一世纪,“手表这么小”的电视机称为“智能手表”。 它们不能直接接收电视信号,而是接入移动通讯网络,通过因特网可以观看电视。

“三层楼高”的电视机在广告业已经普及。 纽约时报广场就有多幅大型电视屏幕,每天24小时播放广告:

显示着广告的大型电视屏幕

Get Online in McDonald's with ESP8266

McDonald's used to be the largest chain of free restrooms in the world. Nowadays, they are the largest chain of free WiFi across the United States. Every McDonald's I've been to offers AT&T WiFi services. I can walk in, connect to "attwifi" on my phone, accept the license agreement, and I'm online.

attwifi captive portal in McDonald's

The license agreement page is called a captive portal, a web page displayed to newly connected users before they are granted broader access to network resource. While it's trivial to click through the captive portal on a smartphone, if you are wearing an ESP8266 as a connected jewelry, it would not connect successfully. When I encountered a captive portal in my apartment WiFi, I made an Arduino sketch to send the packets I found through Fiddler, but McDonald's WiFi is different:

  • Each McDonald's store hosts their captive portal on a different domain.
  • The form submission step needs several parameters from the HTML, but does not use cookies.

attwifi captive portal form HTML

How to Print uint64_t in Arduino

The Arduino programming language looks like C++, but it is weird in its own way: there's no C++ standard library. In C++, you can print a variable to the debug console with std::cerr << x;. In Arduino, you have to write a function call: Serial.print(x);. I love that the Streaming library brings back the familiar syntax Serial << x; through some template and macro magic. But when it comes to a uint64_t variable, nothing works!

error: call of overloaded 'print(uint64_t&)' is ambiguous
   Serial.print(x);
                 ^

note: candidates are:
note: size_t Print::print(const __FlashStringHelper*) <near match>
note:   no known conversion for argument 1 from 'uint64_t {aka long long unsigned int}' to 'const __FlashStringHelper*'
note: size_t Print::print(const String&) <near match>
note:   no known conversion for argument 1 from 'uint64_t {aka long long unsigned int}' to 'const String&'

The cause of this error is: Arduino does not know how to print a uint64_t!

How Arduino Prints Stuff

Arduino contains a subset of C++ standard library, plus some additional headers known as the "Arduino Core". Each microcontroller has its own Arduino Core: AVR, SAMD, ESP8266, ESP32. They follow roughly the same API, one of which is the Print class that knows how to print stuff.

Simple Temperature and Humidity Indicator with ESP8266 and HTU21D Sensor

I decide to mix up a few existing toys to make a simple temperature and humidity indicator. ESP8266 reads temperature and humidity from an HTU21D sensor, and displays the numbers on a 4-digit 7-segment LED display. Since a 4-digit display isn't wide enough for both temperature and humidity, the display cycles between temperature, humidity, and a blank state.

temperature and humidity on LED display

Hardware

Bill of materials

Listen to Podcasts

Apartment life involves a lot of chores: cooking, cleaning, folding laundry, etc. Many American housewives watch TV while doing chores, but I do not have a TV. The next closest thing is the radio, but I find it boring to listen to the same news over and over. In Dec 2016, as I scroll through my iPad Mini (paid link), I discovered the best activity to accompany chores: podcasts!

A podcast is a series of periodically published digital audio files that a user can download and listen to. iPad Mini comes with a Podcasts app that allows me to search for, subscribe to, download, and listen to podcasts.

My initial subscriptions include:

  • Radiolab, in-depth news stories. It's similar to a magazine, but in an audio format.

    My favorite episode is The Ceremony, a report about how Zcash generated their cryptocurrency parameters.

  • Stranglers, true crime stories about the Boston stranglers. They kept my eyes wide open at nights.

Listening to podcasts improves the quality of my housekeeping, because I do not rush through the chore so that I can switch to more "enjoyable" activities sooner. Instead, I can take my time cleaning the bedroom, while enjoying great audio content. I do have to keep it quiet, so that I can hear what's coming out of the small speaker on the iPad Mini.

Four-key Piano on Fipsy FPGA

The newest addition to yoursunny.com's toy vault is Fipsy FPGA Breakout Board, a tiny circuit board offering a piece of Lattice MachXO2-256 field-programmable gate array (FPGA). After porting an SPI programmer to ESP32, it's time to write some Verilog! Blinky is boring, but I did it anyway. Then, I'm moving on to better stuff: a piano.

The piano is an acoustic music instrument played using a keyboard. When a key is pressed, a hammer strikes a string, causing it to resonate and produce sound at a certain frequency. A normal piano has 88 keys, and each key has a well-defined sound frequency. My "piano", built on Fipsy, has four keys, and uses a passive buzzer to produce sound.

Fipsy FPGA connected to a buzzer and a keypad

Play Tone on Passive Buzzer with FPGA

A passive buzzer plays a tone controlled by an oscillating electronic signal at the desired frequency. In Arduino, the tone() function generates a square wave of a specified frequency, which can be used to control a passive buzzer.

Program Fipsy FPGA Breakout Board from ESP32

MocoMakers is creating Fipsy FPGA Breakout Board, a tiny circuit board offering a piece of Field-programmable gate array (FPGA). I worked with FPGA years ago in class projects, but didn't have access to a device after that. I backed the project, and received two Fipsy boards on Jul 20.

Fipsy is a very simple board: there is no power regulator or USB port. The official method to program the Fipsy is through the SPI port on a Raspberry Pi. It is easy to setup, and is a good use case for my Raspberry Pi Zero W (paid link), but there is one problem: It is good practice to power off the circuit when modifying hardware wiring. However, powering off a Raspberry Pi cleanly requires sending a shutdown command and waiting for a few seconds. If I just pull the power cord, I would risk corrupting the filesystem.

ESP32 microcontroller has SPI ports, and can be powered off and restarted very quickly. Can I program Fipsy from an ESP32?

Fipsy connected to Heltec WiFi\_Kit\_32

Hardware side is easy. ESP32 has two available SPI ports, HSPI and VSPI, and I connected Fipsy to the Heltec WiFi_Kit_32 (paid link)'s HSPI port. All that remains is deciphering the spaghetti code of the official programmer. After a day of hard work, I got it working:

How to Compile Just One Kernel Module

I received two C.H.I.P computers in 2016. They come with Linux kernel 4.4.13, but the kernel had limited features. When I needed to use the fuse kernel module, I had to re-compile the entire kernel, which took a whole day. Two years later, I upgraded to a newer 4.4.138 kernel, built by community member kaplan2539. The kernel comes with more modules including fuse, which is a better situation than the original kernel.

DM9601 USB Ethernet adapter plugged into a C.H.I.P computer

Recently I acquired a cheap USB Ethernet adapter. When I plugged it in, the kernel recognizes a USB device:

chip@chip-b:~$ lsusb | grep Ethernet
Bus 002 Device 002: ID 0fe6:9700 Kontron (Industrial Computer Source / ICS Advent) DM9601 Fast Ethernet Adapter

But there's no new NIC showing up in ip link command. A quick Google search of the USB ID 0fe6:9700 indicates that I need the dm9601 kernel module. But:

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 (paid link) 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