It became more and more clear to me that the only reasonable way forward was to drop the Famicom. I haven’t had any emotional attachment to it in the beginning, but it had grown on me. Not to mention that little of the software I had developed would translate easily to any other machine.

It was painful, but it had to be done. But what was to take its place?

A personal computer programmable in BASIC that hooks up to a TV and a keyboard and costs virtually nothing. Now I knew what I was aiming for.

Using a BASIC interpreter written by Tetsuya Suzuki for the Arduino Uno, he (or she) came up with a system based around the so-called " Blue Pill " board. These boards, built around the STM32F103C8T6 MCU, are sold for small change on AliExpress, and Tamakichi-san’s design limits itself to adding a bunch of resistors and connectors to provide what is arguably a full-fledged personal computer, with all the peripherals you would expect: keyboard, video output, sound, storage, serial port.

I looked through the depths of the Internet for a solution. Maybe somebody had already figured it out? In doing so, I came across an unnamed system designed by a Japanese going by the name Tamakichi-san.

An STM32F411 might be capable of handling all the I/O and computing on a single buttcheek, but it lacks the visuals and the sound. It lacks what gives a computer its personality, what makes a Famicom, a PC Engine, a ZX Spectrum and a Commodore 64 instantly recognizable.

It became more and more clear that it would not be possible to get good graphics without extra hardware.

Showing graphics, on the other hand, gobbles up memory quickly, and showing color graphics even more so. Three times as much, in this case. The STM only comes with 20 kB of RAM, and when you subtract the memory required by the BASIC interpreter and the color graphics, you basically end up with nothing left for your program. Even if I got that to work, it would at best be a neat trick, but nothing anybody would actually be able to use for anything.

The bigger problem, however, was memory. While modern MCUs are more capable than the Famicom by orders of magnitude in many areas, they do not tend to come with a lot of RAM. It’s simply not necessary for the tasks they are typically used for. Pull the brakes. Open the valve. Blink the LED. Not much to remember there.

For one, using my technique would give me a maximum of eight colors, and no control over saturation. Basically, it would look like a ZX Spectrum . Meh.

I came very close to implementing a system that uses two more of the STM32F103’s very capable timer circuits and only an external oscillator and some passive components to produce a color video signal. When I was almost done, I realized that it will not actually be that great.

I find black-and-white endlessly depressing, and I knew I would not be happy with a system that doesn’t have color. So I felt my only chance would be to be more clever than the rest of the world, and I went ahead to develop a system that produces color video without requiring expensive components or intricately timed code.

There are various similar projects (although none as ingeniously minimalistic as the Toyoshiki system) that implement video output in clever ways, but almost none of them produce a color video signal. The few that do heavily rely on carefully timed software (and are thus not usable as general-purpose computers) or add additional hardware video encoders, which typically cost several times more than a Blue Pill board.

The Toyoshiki system uses the STM32F103’s timers and SPI controller to produce a video signal, containing the synchronization pulses and the luminance. It is not, however, capable of producing a color burst signal, which is required for a TV to display any sort of color in an analog video signal.

The Toyoshiki Tiny BASIC system contains a number of very clever hacks required to achieve its amazing price-performance ratio, but the reliance on what the low-end STM32F103 controller has to offer limits its capabilities, especially in one area: the video output is black-and-white.

But even with the VS23S010D-L taking a lot of memory load off the shoulders of the MCU, the 20 kB RAM of the STM32F103 weren’t going to do it. Something with more punch was needed. But it couldn’t cost anything.

Besides producing a color video signal, the VS23S010D-L solved another problem I ran into all the time: the lack of RAM. It comes with 128 kB, some or all of which can be used as a frame buffer. That frees up a ton of memory on the MCU that can be used for user programs instead. Perfect!

Figure 7. Panu-Kristian Poiksalo, presumably using a lull in the conversation to think up a texture mapping unit using fewer than five NAND gates.

Let that sink in for a moment: When they needed a gimmick to soup up their somewhat bland memory chip, they threw in a graphics controller. Because, you know, that doesn’t cost anything. It’s just a couple of gates. Did it on the weekend, no testing required. The VS23S010D-L video controller has a price-performance ratio of zero.

The VS23S010D-L by Finnish manufacturer VLSI is a static RAM chip with an SPI interface. Nothing special about that, there are literally hundreds of these. Except that this one comes with a video controller. That is a rather unusual feature for an SRAM, and when I read how it came about, it was immediately clear to me that this is what I’ve been looking for all along:

When you search for dedicated hardware to produce a video signal that you can hook up to an MCU without tying up most of its resources, you will find mostly nothing. Some devices are mere encoders, requiring a timed input signal that you have to create yourself, some are super-expensive (two figures), some are long obsolete, and the best are all of the above. HDMI, you say? Fewer obsolete components, but twice the price.

Meanwhile, Russian developer pvvx has conjured up an SDK culling all the network support and thus freeing virtually all of the ESP8266’s memory for application use. I went to graft the ESP8266 Arduino core onto it and started porting.

Relieve it of the weight of WPA2/PSK, TLS, IPv4 and all that other network nonsense, though, and the awkward little controller roars. Charles Lohr, noted ESP8266 hacker with at best a shaky grasp on the meaning of the word "impossible", has run it at 378 MHz .

When you program the ESP8266 using the Arduino platform, as most people do, it feels somewhat bloated and sluggish. For a "Hello, World!" program you have to upload more than 200 kB of code. There are extra hoops you have to jump through so it won’t crash after a few seconds. Power use, latency and performance are hard to predict. All in all, it’s quite awkward to use, but it’s cheap and has networking, and for many applications that makes up for its shortcomings.

By the standards of your typical MCU, that is a formidable task. It requires giant protocol stacks, cryptography, radio, and all sorts of expensive things. Espressif made the ESP8266 just powerful enough to handle these things, no more.

The ESP8266 was developed by a company called Espressif as a low-cost WiFi-capable MCU, and was first used as a WiFi dongle connecting embedded systems to the Internet.

The search for an MCU with more memory and a cheap price point led me straight to the ESP8266.

Does it sound good? Hell, no. Calling it LoFi is being charitable. But it’s there, and it’s loud, and at the end of the day, that’s what counts.

Espressif provides a demo program for the ESP8266 SDK that streams MP3 audio from the network and sends it to an audio codec connected to the MCU’s I2S output, effectively resulting in something like a web radio. Knowing their customers, and never outdone when it comes to cheap, they included an option to replace the codec with a low-pass filter and use the I2S output for pulse-width modulation. Boom, two capacitors and a resistor later we have sound! Total cost: three cents.

So I had video and computing and an input device, but there was no sound yet. I already used two whole chips by now, and there was definitely no budget for a fancy audio codec. What to do?

I had wired up a prototype on breadboards by now, and a quick port of Toyoshiki Tiny BASIC to the ESP8266 and a hacked-up video demo from VLSI later, it started to look like this could actually work!

Besides the moral aspects, I also thought about how to connect game controllers, Atari-style joysticks in particular. The problem was the same in the end, and the canonical solution to it is commonly called an "I/O expander". Such devices connect to a narrow bus on the MCU (like SPI or I2C) and have a lot of pins that can be controlled over that bus. They can also be really expensive.

I thought about it. So what if I’ll present the BASIC Engine to the public, and some kid comes along and says, "WTF, one GPIO? My dad’s Arduino Uno has more than that!" And instead of joining the peaceful forces of the BASIC Salvation Army, she walks by, straight into the arms of a recruiter for a military equipment manufacturer, spending her life developing drones that kill innocent people in Central Asia. Would I be able to live with myself after that?

Nobody needs that much I/O, I certainly didn’t. But the minimalistic approach of the ESP8266 still turned out to be an issue. Having put all the pieces of the BASIC Engine together, a single general-purpose I/O pin remained unused and could be made available to the user.

Contrast that with MCUs more geared towards industrial applications: The STM32F411, comparable in CPU power and memory size, has five SPI controllers, three "USARTs", three I2C controllers, USB OTG, five times I2S, and eleven(!) timers.

When Espressif designed the ESP8266, they clearly had some applications in mind: web radio, home automation, turning the lights on and off and the AC up and down over the Internet. Besides WiFi, you don’t need a lot of interfaces for those purposes: maybe an SPI port, a little I2C, an I2S, a few GPIOs, and an analog input to measure the humidity of your plants. No need to go overboard.

Expansion

I/O expanders come in all sorts of specifications, and generally speaking, the faster they are, they more expensive they get. Sinking a lot of money into an I/O expander was not an option, so I looked at the low end of the performance range and tried to find the cheapest option.

Finding the "right" price for electronic components is not very easy if you don’t know where to look. Large Western electronics distributors, such as Digikey, Mouser or Farnell, charge you as much as they can get away with. If you buy a rarely-used component, you will be ripped off. If you buy a generic part, you will be ripped off. They wrap your tiny chip in about one cubic meter of packaging and then charge you insane amounts for shipping. The only thing you can learn from them is how much is too much. The only reason to buy from them is that somebody else foots the bill. If you consider buying from them because you need something immediately, check first if a plane ticket to Shenzhen is cheaper.

Yet another catch with major distributors is that while they offer a seemingly impressive variety of components, they do not stock products by some manufacturers at all. Among them are more often than not VLSI and Espressif…​

Major Asian distributors usually do not give you any price to begin with, you need to request a quote, and I doubt that any first offer for a small number of components will be very good. Smaller local distributors, such as Reichelt in Germany or TME in Poland, occasionally have decent prices on some items, but they also have wildly overpriced ones, and usually a more limited selection than the larger companies.

eBay is completely useless. While it has decent offers when it comes to tools, it is with very few exceptions by far the most expensive place to buy electronic components from. Amazon does not have any offers worth speaking of.

No, my friend, the real price of electronics is on AliExpress.

AliExpress is the business-to-consumer retail web site of the Alibaba Group, a large Chinese business-to-business trading platform. Vendors on AE sell everything from glass beads and teddy bears to pick-and-place machines directly to consumers worldwide. On lighter items, such as electronics components, shipping is usually free. I get virtually all my parts and consumables from AE, and of course I looked there first.

A popular choice for an I/O expander is the PCF8574T. It connects to an I2C bus, provides eight I/O pins and costs about 22 cents per piece on AliExpress. For comparison, here are the prices from other places:

Mouser 1.18 EUR Digikey 1.23 EUR Farnell 0.88 EUR TME 0.89 EUR Reichelt 0.94 EUR eBay 0.33 - 7.23 EUR Amazon 1.35 - 5.29 EUR

While it seemed to be a decent choice, there was an even better one: the PCF8574T has a bigger brother called PCF8575TS, which is actually physically smaller, but provides 16 I/O pins, enough even to hook up a Neo Geo controller.