My First Brainfuck computer

main

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.

Description

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.

Watch in HD

Features

                                  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$

Development

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.

inspiration
programmable microcomputers (maybe not the last one…)

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.

8pinQuite 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:

  1. Ook.
  2. Ook!
  3. Ook?

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!

Future

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

my first brainfuck schematic

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).

my first brainfuck PCB

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.

It is a quick and easy board to solder since it has few components, no SMD parts and plenty of space.
IMG_6000B

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

Specification

86.4 x 53.3 [mm]

Version tracker

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)

Documents

See also

Licensing
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Related posts:

18 thoughts on “My First Brainfuck computer

  1. Pingback: Master My First Brainfuck | Johan von Konow

  2. Pingback: My First Brainf*ck

  3. Pingback: rndm(mod) » My First Brainf*ck

  4. Pingback: My First Brainf*ck - RaspberryPiBoards

  5. Pingback: My First Brainf*ck — Blog of MPRosa

    • Sweet!
      The debugger works great, since it shows the value in decimal it is a great tool for writing bf programs to My First Brainfuck. (I have tried other debuggers that show the ASCII character only – they are not so useful when working with 4 bits…)
      There is also an integrated debug function in My First Brainfuck that sends the program and memory content over the serial connection.

      /johan

  6. Pingback: My First Brainf*ck | Daily IT News on IT BlogIT Blog

  7. I love this idea. a couple of years ago I designed a similar fully programmable BF based disk operating system for a TI Launchpad but never got round to building it. Now I’m a teacher and I think that “My First Brainfuck” would be great in the class room, except for the name :)

  8. Amazing project! I’m pretty sure that I will build one for myself (and present it to my 16-years old students as I’m a high school teacher). What about substituting the Arduino with a FPGA? Would be fantastic!

    BTW: I don’t care about the name, as I’m living outside of the US/UK and I’m not known for beeing particularly PC :-)

    Yours friendly,

    Alex.

    • That’s a nice challenge. It can definitely be implemented in mfb if using 3 bcd values.
      I wrote this one, when playing with the mfb:
      ++>.+.< [>[>+>+< <-]>.[< +>>+< -]>.[< +<+>>-]<<.<-]
      Can you find out what it does?

  9. There are some problems in the source code. I am unable to compile and run it, due to multiple errors with Charlieplexing in the latest version of the Arduino software. I imported the charlieplexing library, though perhaps my configuration is different than yours. I like your design and would love to have the code work with the My First Brainfuck I just assembled. I stopped messing with the code after resolving 3 errors. As I am unfamiliar with brainfuck, I would rather not rewrite your Arduino code, so if you could help me resolve the issues, I would be very appreciative.

    • Hi
      it is a bug in the charlieplexing library.
      I have updated the Arduino project to contain a working library, but you can also fix it by editing the Charlieplex.h: Find the include row and replace “WProgram.h” with “Arduino.h”.
      (I tested the code in Arduino 1.0.5 and 1.0.3)

      God luck building mbf, let me know how it goes!
      /j

      • Thanks very much! After supplementing the recent Charlieplexing library with yours, the upload to the Arduino was successful. Unfortunately my mfb didn’t work, but that was most likely just a wiring mishap because I wired it on a breadboard so it’s a bit confusing. For me, building it with the Arduino code and the correct Charlieplexing library was a bit confusing, so you may want to include the necessary library’s link with the other pertinent links at the bottom of the post for simplicity. Thanks again, I can’t wait to get this up and running!

        • I’m glad that it works better. Thank you for the tip; I replaced the Arduino sketch with a package containing both mfb and the working charlieplex.

          If you still are having problem with the wiring, I suggest that you write a simple test program to debug the charlieplexed LEDs:
          Replace the loop in mfb with something like:

          void loop(){
          charlieplex.clear();
          charlieplex.charlieWrite(led6,HIGH);
          delay(1);

          charlieplex.clear();
          charlieplex.charlieWrite(out1,HIGH);
          delay(1);
          }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>