My First Brainfuck is an educational computer built to be as minimalistic as possible.
I’m sorry for the use of the offensive f-word, but it is the actual name of the program language the computer uses.
The My First Brainfuck has the same basic features as a normal computer, but at an extremely low level. The impressive part is that you can still run, write and edit programs on it. Programming My First Brainfuck is challenging, but rewarding, making it an ideal device to learn how computers work (both software and hardware).
It is easy to build, fun to play with and has an extremely low price. I hope that My First Brainfuck can increase understanding of how a computer fundamentally works.
[youtube type=object related=no annotation=no link=yes cc=no theme=light ]
A “normal” computer
(like a PC or a Raspberry Pi): My First Brainfuck:
Processor 32/64 bit CPU 4 bit CPU
Input USB keyboard 4 keys
Display Monitor or TV 10 LEDs
Audio Soundcard Play tones on a buzzer
Cost 50-500+ $ ~7$
Ever since I was a child, I have been fascinated by the idea that you can learn how a computer works by building one yourself. There are numerous models available, but they are all surprisingly complex; requiring a lot of components, soldering and special knowledge, making them interesting to only a few. If you don’t want to build a computer yourself, you can learn a lot by playing around with microcontroller kits like the Arduino (but you still need a computer to program them).
I wanted to create a minimalistic computer that you could build, program and understand. It should also be portable and at very low cost. How hard can it be…? ;)
During the past months I have been thinking about the minimalistic programmable computer a lot and I have studied all kinds of related areas; microprocessor architectures, program languages, old literature, low cost production and different electronic interfaces. However, I could not find anything that fulfilled my requirements… Instead I decided to try to develop the miniature computer myself. I was glad that I did my homework, because I could find a lot of inspiration from computers like ZX spectrum, Raspberry Pi, Altair 8800, Gakken GMC-4, Tandy Microcomputer Trainer, NEC TK80 and even Kenbak-1.
To cut the cost I simply used Occam’s razor and removed all unnecessary components: The screen was replaced by a few LEDs, the 64/32/16/8 bit bus was replaced with a nibble (half a byte / 4 bits) and the keyboard was reduced to a few switches.
Quite early I decided that the computer should be built around an 8-pin microcontroller, with only six pins for I/O. If I wanted to use LEDs, switches and basic audio – I had to make it work with no more than five keys and 12 LEDs.
Now it was only a matter of figuring out how you write and edit programs on a computer with 12 LEDs and five keys…
Instead of writing programs in BASIC, C, Java, assembler or microprocessor code, I studied all kinds of minimalistic program languages and eventually found a language with only eight instructions. An obscure esoteric language called Brainfuck (due to the fact that it is quite difficult to read the code). Still, writing eight instructions with five keys will not be intuitive. I therefore went further and found ook – a dialect of Brainfuck consisting of only three commands:
These three commands can be combined in groups of two, to form the eight different commands used by Brainfuck (let’s call it bf from this point on). Bf is perfect for the My First Brainfuck:
- It has only eight instructions – making it easy to remember (and it doesn’t require a large amount of keys).
- It is quite challenging – making it suitable for education. You basically have to think like a computer in order to write a program (which is good if you want to understand how computers work). Besides, if it was too easy – it wouldn’t be any fun.
- The language is Turing complete – basically meaning that other programs can be written in bf (in theory).
Even if only three keys is required to write ook, five keys is not enough if you want to view, edit, input data and run the code. Instead of adding more keys, I used some of the LEDs to build a menu system, where one key is used to select mode, and the other keys will have different functions depending on the selected mode. In the end, I could actually remove one switch and two LEDs, leaving me with a programmable computer with 4 keys and 10 LEDs! At least that was the theory.
To test if it actually worked I built a prototype Arduino shield with the keys, LEDs and a piezoelectric speaker. I programmed the menu system, Brainfuck interpreter and all the rest using the Arduino as development platform. And after some minor changes I realized that it actually worked! As far as I know, this is the simplest programmable computer in the world!
The My First Brainfuck shield was built as a proof of concept to evaluate the user interface, hardware and software.
The Arduino shield shows that the concept works and that the Arduino can be replaced by almost any low cost miniature 8 pin CPU. If the project gets enough attention and interest I will develop the ultra-low cost version and prepare files and programs, so everyone can build it, either getting the components themselves, or maybe provide it as a kit. In theory it should be possible to squeeze the price so that My First Brainfuck could be given away for free (funded by advertisement on the board/box).
Build the Shield
The shield can be built on a stripboard, an empty Arduino dev shield, a breadboard/protoboard or on a custom PCB. The Schematics is quite simple with 5 pins handling all the LEDs and switches, using Charlie-plexing. The remaining pin is connected to the buzzer.
I wanted to test the concept of using only six pins for interface (A0-A5). But it is quite easy to alter the program so that it uses individual I/O pins for each component if that is preferred. For instance the four switches could be on A0-A3, while the 10 LEDs and the buzzer could be on D2-D12). Just make sure you use current regulating resistors to the LEDs and weak pull-up for the switches (use internal).
I made a single sided custom PCB and used double sided adhesive to attach the laminated printed graphics to the board. After making new holes through the graphics, I mounted and soldered the components. I didn’t have an SMD version of the pinheader, so I soldered a normal header to the backside of the PCB.
Bill of Materials (BOM)
- 1x single sided PCB (etch, mill or order) or breadboard
- 2x 6×1 0.1” pin header
- 10x leds (red or green)
- 4x switches 6x6mm
- 5x 100R resistor (1/4W)
- 1x 10k resistor (1/4W)
- 1x piezo electric buzzer 12mm diameter
86.4 x 53.3 [mm]
0.1 First version 0.2 Separate pin for buzzer 0.3 Custom PCB 0.31 Code: Arduino sketch with charlieplexing 0.4 Code: BF interpreter 0.5 Code: Menu system 0.6 Code: PGM write + edit 0.7 Code: “.””,” working 0.75 Code: New command – “/” 0.8 Code: Bugfixes and cleanup 0.81 Code: Debug terminal 0.82 Added charlieplex library (current version)
- Rhino project file (2D lines)
- Artwork 2D Vector export (svg)
- Artwork 2D Bitmap export (png @ 600 dpi)
- PCB 2D Vector export (svg)
- PCB 2D Bitmap export (png @ 600 dpi)
- Arduino sketch
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.