3DPCBoy – build your own handheld gaming platform

Description

The 3DPCBoy is a project I have been working on during my spare time for a couple of months. It originated as a test to see how a 3D printer can replace the need for a PCB and over tons of iterations, it has evolved to the 3DPCBoy – a cute handheld Arduboy compatible gaming device that cost around $10, is easy to build and fun to play with.

I think it is a great educational project since it involves several different areas:

  • 3D printing
  • Soldering
  • Electronics (microprocessor, display, switches)
  • Programming
  • Gaming

This project is standing on the shoulders of giants and I want to give credit to Arduino, Arduboy and its game development community. There are over 100 different games to download for free and you can modify them or even develop your own games.

rendering showing the 3DPCB with integrated diamond shaped wire channels.

3DPCBoy is using a rather unique approach – is not built around a glass fiber PCB like most electronics. Instead it uses a 3D Printed Circuit Board (3DPCB). This makes it easier to replicate, less expensive and you don’t need to wait for a PCB delivery. If you want to know more about 3DPCB, or use it in your own project, you can read about the development here .

The 3DPCBoy is not fully Arduboy compatible – to simplify the design I did some modifications:

  • Only PIN5 is connected to the beeper (the other side to GND)
  • I removed the RGB LED (might be added in the future)
  • CS pin of the OLED connected to GND (since the SPI is not shared)

Feel free to modify the design! With a CAD software, you can easily change the switches, layout, buzzer, add LEDs or build a snap on cover. I have included both .stl files for printing and .step files for tinkering (see documents section at the end of the post).

3DPCBoy has evolved over several iterations and is now easier to assemble.

Build it

This post describes the assembly process step by step and is suitable for most people. I have tried it on absolute beginners, kids and experienced developers. If you can identify the hot end of a soldering iron, you are good to go ;)

Equipment:

  • 3D printer (FFF/FDM with PLA filament)
  • Solder station and solder tin.
  • Basic tools: needle- and cutting pliers, knife, glue
  • Micro USB cable
  • Computer to run Arduino IDE and upload games to 3DPCBoy

Part list:

  • 1x 3D printed front 3DPCB (I used PLA)
  • 1x 3D printed battery holder (PLA)
  • 1x 0.96” monochrome 6-pin SPI OLED (not 4 pin I2C version, nor 7 pin spi)
  • 1x Arduino pro micro
  • 1x 1000mAh Li-ion battery (3.7V), or less capacity
  • 1x piezo electric disc (12mm in diameter)
  • 1x slide switch
  • 6x round push switches with low activation force.
  • 5x 20cm 0.3mm copper wires (strands from one RK-wire)
  • 1x Li-ion battery charger (USB-C)

The most expensive parts are OLED, Pro micro and battery – all can be bought and shipped from china for around $3 each. If you have trouble finding specific parts, let me know in the comments section – I can probably alter the design if needed.

Print the 3DPCB and battery holder

For the 3D printed parts, I sliced the stl model (see documents section further down) in Cura and printed on a BCN3D with a 0.4mm nozzle and the following settings:

  • 0.15mm layer thickness
  • 205deg C for the PLA
  • 100% infill
  • No support

When you have all the parts, you are ready to follow the assembly guide with some tips along the way.

­­Position, cut and bend switch wires.

Place the 6 switches in the 3DPCB.

Cut the switch pins about 3mm above the board.

Ensure the switches are in the bottom position and bend the cut wires to lock them in position.

Solder 6 signal wires to the switches and the CPU (Arduino pro micro)

Every switch has two connections, one is routed to the CPU and one is connected to ground and shared with the other switches and components. Let’s start with the ones that goes directly to the CPU.

Solder one end of a copper wire to the bent switch. This is done by placing the copper wire next to the switch wire and heating them briefly while adding solder tin. Yes, it would be easier if you had three hands, but you can either use “helping hands” to hold the copper wire in place, or if you are skilled, use your fingers to hold the wire and add solder at the same time. A tip is to first clean the soldering iron and add a tiny bit of tin directly to the tip to transfer the heat when soldering. Try to be quick and avoid heating up the components and 3D printed plastic. Use a ventilated area and avoid breathing the fumes from soldering or melted plastic (if any). Avoid excess amount of solder tin, no part should extend the flat surface.

Once the copper wire is soldered. Place the CPU board in its slot and thread the free end through the hole at the end of the guiding grove of the 3DPCB and then through the corresponding CPU hole.

Now tighten the wire while placing it in the grove.

Turn the board over and solder the wire to the CPU board while keeping the wire tight.

Cut the wire close to the PCB and reuse the loose section if it is long enough.

Repeat the process six times (solder, thread, solder, and cut)

Repeat for the remaining switches
All switches connected on one side

Add the ground wire

Now it is time to solder the ground wire connecting the other pin of the switches. Start by threading the wire through the battery hole and leave 3-4 cm wire on the other side. Then add the wire in the grove and solder the first two pins when the wire passes them.

Add the piezoelectric disc (speaker) and fold the copper wire until it forms a loop that passes over the copper side of the piezo electric disk. Then solder the wire to the disk (avoid contact with the white center of the disc). Since the disk has more surface area, you need to heat it up for a little bit longer, but try to avoid warming it too much since it will melt the plastic. Adding more tin to the soldering tip makes it easier to do a quick solder.

Solder the remaining switches and thread the ground wire through the hole to the CPU (not the OLED). This wire needs to connect both the CPU and the display, so fold the wire and thread it back through the hole. Now solder both wires to the CPU PCB and cut off the loop. Then thread the remaining wire to the display hole on top, again leave a few cm wire for later.

Solder a bit of copper wire to the center of the piezo electric speaker. Please note that the piezo electric crystal is quite fragile and should not be heated for a long period. Clean the soldering tip, add some extra tin, and solder the wire quickly to avoid damage. Then carefully thread the wire through its hole without adding stress to the solder joint. Flip the 3DPCB, solder and cut the speaker wire.

Verify that all keys work

This is a good time to upload a simple keytest program before soldering the display. Set up Arduino environment (Scroll down to Arduino IDE installation instructions) and create a new program with the following test code:

void setup() {
pinMode(17, OUTPUT);
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}

void loop() {
digitalWrite(17, HIGH);
if (digitalRead(A0) == LOW || digitalRead(A1) == LOW || digitalRead(A2) == LOW || digitalRead(A3) == LOW || digitalRead(7) == LOW || digitalRead(8) == LOW) {
digitalWrite(17, LOW);
tone(5, 262, 20);
}
delay(20);
}

The program above will play a beep for every key you press. If a key does not make a beep you probably have a bad solder connection.

Add the slide switch and fold the pins while holding the switch in bottom position. Solder a wire to the top pin and thread it to the battery hole.

Connect the display

Now it is time for the connection of the display. Since the OLED display covers the CPU board, all wires will be soldered only to the CPU and thread through the display holes. Leave a few cm for the display. The first wire in the picture above needs to cross another wire and is therefore threaded on the other side.

Tighten the threaded display wire, leave a few centimeters and repeat for the remaining display signals.

I almost forgot, solder a copper wire to the middle pin of the slide switch, thread through the hole to the CPU, solder, and cut from the other side.

don’t forget the second wire to the slide switch…

Before adding the display, double check that nothing is missing:

  • Check that all switches are connected
  • Check that all wires are inside their groves
  • Check that all wires are soldered to the CPU board an cut close to the solder (4,5,6,7,8,raw,gnd,vcc, a3, a2, a1,a0, 15,16 should be soldered.)
  • Check that no solder joint is protruding the flat back surface (might risk short-circuit against the battery)

Thread the wires to the display (without any crossings)

Place the display in position

Tighten, solder and cut the display wires

Add the rechargeable battery

Now it is time to connect the battery. Place the battery in the 3D printed case and remove the insulation of the red and black wire according to this picture, ***WITHOUT LETTING THE WIRES COME IN CONTACT WITH  EACH OTHER***. If the wires come in contact, they will weld together, short-circuit the battery, burn the fuse, catch fire or explode (maybe all at once ;)

It is now time to connect the battery to the front. Thread the wires through the same holes used to power the front, again ensure that the power wires don’t touch each other.

Fold the top over the battery backside; twin the battery and copper wires together. This ensures contact, and allows disassembly without soldering. Trim the wires  

Fold the twisted power wires into the neighboring empty holes.

These holes are also used for charging the battery and are compatible with a USB-C charging module.

Remove three pins from a pin header and solder them to the charging board (out+, B+, B-)

The charging module is attached to the 3DPCBoy by placing it in the battery holes in the top right corner. The spare upper hole is used to prevent switching polarity when an extra pin header pin is inserted next to the positive side on the charging board.

Installing Arduino and loading games.

Now it is time to install your preferred game on the 3DPCBoy.

  1. Download & install the Arduino IDE.
  2. Download the source code for the preferred game; unpack the folders to your Arduino sketch folder (Ctrl-K in Arduino IDE).
  3. Load the game in Arduino IDE
  • Use the Library manager (Ctrl+Shift+I or Sketch>Include Library> Manage Libraries.) to add Arduboy, Arduboy2 library.
  • Compile the game (Ctrl+R) with the tick box icon in the top left corner. Ensure that all requested libraries are installed (if not, use the Library manager)
  • Connect the 3DPCBoy to the PC with a micro USB cable. Select Arduino/Genuino Micro board from Tools->Board and select the corresponding com port from Tools>Port (the one that says COMx Arduino/Genuino Micro).
  • Upload the compiled code to the 3DPCBoy (Ctrl+U) with the RightArrow icon next to the tick box in the upper left corner.
  • Done!

Program the 3DPCBoy and test that everything is working (power switch, all six keys, speaker and display).

There are two guide holes where pin header pins can be inserted to align front and back before gluing them together with two drops of cyanoacrylate.

Documents


Appendix:

OLED Display:

Display Pin         Pro Micro Pin
GND                    GND
VCC                     VCC
SCL                      15
SDA                     16
RST                      6
D/C                     4

Buttons – Tie one pin of each button to GND and the other pin to:

Button  Pro Micro Pin
A                         7
B                         8
UP                       A0
RIGHT                 A1
LEFT                    A2
DOWN                A3

Piezo speaker: (Arduboy uses pin5 and pin13 for dual tone, pin 13 is not available on the Pro Micro, so it is simply skipped)

Speaker Wire     Pro Micro Pin
1                          5
2                          GND

Arduboy also have an RGB LED that is not included in 3DPCBoy

RGB LED – Tie the anode to VCC. The cathode of each LED should go to an appropriate dropping resistor and the other side of the resistor should go to:

Resistor for Color:          Pro Micro Pin
Blue                    9
Red                     10
Green                  3 (with custom library)   (11 in Arduboy)

Update – New version with standard components

The right version uses components that are easier to acquire.

I have created a new version with the following improvements:

  • More accessible 6×6 TACT switches (select low actuation force)
  • A buzzer with pins (9mm diameter – easier to acquire and to solder)
  • 2 channel audio for better gaming experience.
  • Added SPI CS to support 7pin OLED (still works with 6 pin)
  • Protective frame around OLED and 4 support pins (no need for hot glue)

To enable dual channel audio I recommend to use MrBlinky’s excellent arduino IDE package. Select ProMicro 5V (alternate wiring).

The 4 pin TACT switches made routing a bit more challenging. I rotated them 45deg to keep them close to each other (thumb size).

Licensing

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Developing 3DPCB – 3D Printed Circuit Board with lots of potential.

3DPCBoy illustrates the possibilities of integrating the circuit board in the structure of the product itself.

Description

Here I describe how I came up with the idea of replacing conventional FR4 circuit boards with 3D printed versions that also can integrate components, structure and cosmetic surface of the product. In the end I provide some tips for creating 3DPCBs. More posts will follow where I use this technology in different products and this post describes how to make a refined version of the 3DPCBoy gaming device, featured above.

Features

  • Rapid manufacturing, no need to wait for PCB production and shipping.
  • No special equipment or materials needed (just an FDM 3D printer, soldering station and wires.
  • Integrated wire guides show how connections are routed (beginner friendly).
  • Allows 3 dimensional circuits, opening up for new ways of integrating electronics, reducing size, part count and complexity.
  • Low cost

First of all, I would like to state that I’m sure that similar ideas have been developed before. I don’t claim that this is revolutionary and it certainly comes with pros and cons. The concept shares parts of perfboard designs, various 3D printed designs, wire warp and dead bug soldering. The combination of these techniques, its simplicity and possibility to integrate electronics and casing is quite promising, and by sharing this idea I hope that the method can evolve and be combined with new inventions to become even better.

Development – Day 1

I recently got a spare weekend (which is quite uncommon these days) and decided to use the time to play with different ways of making a PCB with a 3D printer. I wanted to see to what extent one can use standard technology, so I skipped printed metal, conductive filament and silver epoxy and similar solutions. Preferably I would rely on a single head FDM printer with PLA filament and reliable connections (solder or maybe even wire wrap). The plan was to test different ideas, iterate small steps and see what comes out. It’s a nerdy way to spend a weekend, but I really like the creative process of making something new.

My first idea was to use through hole components and bend the wires so they act like traces on a PCB. This is normally called fly-wire, point to point or sometimes dead bug circuits. However, the difference would be to use a 3D printed structure as support, simplifying the soldering process, guiding the user and making the final solution sturdier.

I needed to start somewhere, so I created a miniature Arduino breakout board (since they are simple and always handy). The process was similar to an ordinary PCB, with the only exception that the traces were replaced by the component legs.

2D sketch showing components, routing and board edge

When I was satisfied with the 2D sketch, I created a 3D model of the support board and printed it using standard PLA.

Top side of the first version – it’s just a printed piece of plastic with holes. The question was if it would melt when soldered?

The printed board was then used to test if the concept was working. The biggest risk was that the PLA would melt when soldering the wires, but luckily the soldering process is quite fast and even if the PLA get soft, it cools quickly and keeps its shape. For absolute beginners this might create a problem if you apply too much heat, but once you have soldered a few connections this should work fine.

Since this was a proof of concept, I replaced the CPU with a left-over logic circuit (no, you can’t run Arduino code on a 4017 ;).

The concept showed potential, but I realized that I needed to guide how the wires should be connected. If only there was a way of integrating guide channels to the model… This was easily solved by adding an extra layer on the circuit board that had channels for the connections. I even added a frame, allowing the circuit to lay stable on a flat surface and reducing the risk of short circuit the wires.

Bottom side of improved version with guide channels and a frame to prevent short-circuits. Everything is printed in one piece – colors are used to show the structure.

3D printing the board took 40 minutes with a BNC3D with 0.4mm nozzle and 0.15mm layer height using standard settings in Cura (without support & 205 deg C for the colored PLA).

Once the board was printed, soldering was straight forward, starting with the atmega328 and the low height components, bending the wires, soldering the connections and cutting away anything that protruded the frame. Since the component legs have limited length, I had to add two pieces of wire (0,5mm tinned copper wire). It’s actually fewer solder joints than a PCB, since two connections (component – PCB – component) are replaced by one.

The breakout board is obviously not Arduino shield compatible and you need to add a bootloader before programming it using a USB to serial adapter (this can be done using another Arduino – google it if you don’t know how).

After several iterations I had now reached the end of the first day and I felt that the concept had great potential. Just imagine when you don’t want to wait for a PCB order or the endless possibilities to add 3-dimensional shapes to the board. It doesn’t need to be flat anymore and it’s easy to integrate keycaps, attachment brackets or battery holders into the PCB itself…


Day 2 – game time!

After a good night’s sleep, I was eager to continue to experiment with the concept. Since the Arduino breakout board worked, I decided to build something with more complexity. An Arduboy clone seemed like the perfect next step. It has an OLED display, some pushbuttons, a beeper and most importantly you can play games on it! It would be awesome if you could print the PGB and solder a working handheld game without the need for perfboard or a custom-made PCB.

I started designing in 2D by creating models for the different components and positioned them in order to build a compact device. By placing the Arduino pro micro beneath the OLED display I could keep a small form factor. Compared to the original Arduboy I did some modifications:

  • Only PIN5 connected to the beeper (the other side to GND)
  • I removed the RGB LED (might be added in the future)
  • CS pin of the OLED connected to GND (since the SPI is not shared)

I then routed the connections with an iterative approach. After testing a couple of different tracks, I had a solution with good spacing between the traces and only a single bridge (where wires cross each other and needs to be separated to avoid short circuit).

Routed version of Arduboy game.

From the 2D routed drawing I created a 3D model similar to the Arduino breakout board. One layer with holes for the components, one layer with cut-outs for the traces and one layer for the frame. Everything was printed upside down. After one-hour printing time I could assemble the first version.

3D model with guide channels for 0.5mm wire.

To keep the shape of the traces I used a rather sturdy 0.5mm tinned copper wire. It was not a problem assembling the device, but I realized that the 2mm wide cut-out was too spacious, and the rather thick wire was a bit tricky to bend correctly. Since I wanted something that could be assembled quick and easy, I realized that I had to optimize the wire and channels and probably needed to test lots of different options. To save time I created a compact board (2x2cm) with three test traces. I then tested altering the sizes of the channels and could quickly test different wire diameters. I noticed that a thinner wire was easier to route, but needed better guiding since the wire is less stiff compared to the thicker. I realized that I could use the 3-dimensional freedom and created traces that was bigger inside the board with just a narrow opening on the top. In the cross section, the channel had a diamond, or rhombus shape, where only the top protruded the board. The diamond shape has several advantages compared to a circle, it is easier to print the constant angle undercut and the .STL file becomes much lighter. With this approach it was easy to insert the wire and by stretching it slightly it was kept in position. I tested different openings and different sizes of channels before I found the optimal setup.

Models to test different ways of routing wire.
Cross-section of test model with diamond channels inside.

The channels were created by placing the a diamond / rhombus curve at the end of the routed trace continued by a solid rail extrusion. The extrusions were then subtracted from the main board.

I also tested different wire options and found that the best result was using a 0.3mm diameter copper wire (0.07mm2 area) that I got from strands of RK-wire (the multi strained cable used for internal wiring in electrical 230V cabinets). It is easy to route yet still keeps its shape.

I like to kill my darlings, so I also tested a version where I used the soldering iron to melt the wire in dedicated pins along the trace. This method worked, but it was quite time-consuming and the melted plastic is probably not good for the health, nor the soldering iron. A more successful method was to create smaller straight channels that alternated between the two sides of the board. With this setup, I basically sewed the wire in position. It worked great, but was more time-consuming compared to the diamond trace.

I was worried that the diamond method was sensitive for printer calibration and tested if it worked printing upside down (with the trace opening against the glass of the 3D printer). It worked just as great as printing it with the opening on the top side.

With the new approach I remodeled the Arduboy 3DPCB and printed a second version. When I used the thinner wire, I noticed that the assembly process improved a lot.

3D model with diamond channels for 0.3mm wire
3D printed board with 0.3mm wires. Note how the wires are kept in place when the channels are bigger on the inside.

However, it also became apparent that using the traditional 45 deg routing method was not optimal for wire bending. I decided to take a shot at this too, and made a copy of the model and rerouted all the tracks, this time trying to keep each trace as straight and short as possible. This is called topological routing and creates a board that doesn’t look like an ordinary PCB, but I guess that this is not an ordinary PCB, so looks aside, this is a better approach where the sharp angles are replaced by circle segments. (note to self – try curvature-contingent routing one rainy day…).

Just by curiosity, I measured the length of the traditional 45 deg routing (509mm) with the topological routing (463mm) – it’s not a big difference, but still.

Improved routing without sharp corners – inserting the wire becomes easier and quicker.

Since the wires are embedded in the structure, I could now remove the frame. This allowed me to print with component side up and I could integrate support structure and protective cover on top of the board. This is where the advantages of the technology really become apparent, and the board and case become one. I added support pins for the OLED display and extruded a tube inside the block to create a hidden wire crossing. It’s almost overkill, but demonstrates that you can do lots of new things that are not possible with traditional stack ups. To improve assembly, I added extra cut-out where the soldering should be done, it’s now easy to see not only how the wires should be placed, but also where to solder the board.

3D model with support structures for OLED display, CPU, switches and buzzer

Cross section of final model showing diamond channels and wire crossing (bridge).

When the integrated board was printed and tested it was early Monday morning. I haven’t had this much fun in a long time, I missed some meals, hardly slept, but did lots of experimenting and testing new ideas, several bad ones, but a few good ones make it all worth the effort. I hope that this method will be used by others and I can’t wait to develop more projects with 3DPCBs to see how far the idea can be developed. It would be fun to create a synth or maybe a printed computer with blinkenlights…

Pros:

  • No need to wait for PCB delivery
  • Can be made with a standard 3D printer
  • Low cost (filament and some copper wire)
  • Large number of color options
  • Shape not limited to flat sheets, can easily integrate support, battery connectors and outer case.
  • Fewer solder joints when you use the component legs as wires.

Cons:

  • Large pitch compared to what can be done with SMD PCBs – mainly suitable for through hole components.
  • Soldering takes slightly more time compared to a regular PCB since you need to add the wires (but it’s a quite fast process anyway).
  • Heat sensitive compared to FR4. It’s not fire retardant and will melt if heated – NEVER EVER USE 3DPCBs for high voltage or large currents!
  • No available tools for routing, it has to be done manually in 3D CAD.
This is the result of several iterations; this version uses a rechargeable Li-ion battery and uses an ultra-low cost piezo electric disc as speaker. The routing is curvature contingent – making it easy to assemble and keeping all the wires in place.

Tips for designing a 3DPCB

After the initial weekend I have iterated the design of the 3DPCBoy and created other projects. Over time I have learned a few tricks that makes designing 3DPCBs easier:

  • Avoid hidden bridges – Its cool that they are feasible, but even with a fixed radius (subtracting a torus), there is a risk that the print isn’t perfect and threading the wire can be difficult. Use both sides of the board and simply switch side with one hole, cross the wires and go back with another hole.
  • Use a modular design in the CAD software, separate routing, 3D extruded tracks, board and 3D objects. Use Boolean subtraction to create the wire paths and save the extrusions if you want to edit something later.
  • Try to design without the need for 3D printed support structures. Add chamfered cut-outs where you need to solder, like connecting a wire to a switch.
  • Bending component legs; locks them in position, reduces height, avoids short circuit and is easier to solder.
  • I have now tried curvature contingent B-spline routing and it works great. It automatically avoids straight lines which keeps the wires in place. The downside is that it’s a bit more time consuming to route, and it also looks funny compared to normal routing. If you expect that the model will be used by many curvature routing is recommended. If it’s a one off, straight lines and radiuses works well.
Cross section with dimensions of board and diamond channel with a narrow opening for inserting the wire. (units in mm to the left and inches to the right)

Bill of Materials (BOM)

  • FDM 3D printer with PLA filament
  • Solder station & solder tin
  • Thin wires. I used 0.3mm copper wires (strands from 20cm of RK-wire)
  • Components for whatever you are building, see separate post for the 3DPCBoy.

Licensing

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Foldable 3D printed Arduino case

Description

This snug Arduino case is printed flat and then folded around the Arduino. The result is a fast print and yet a stable design from a single part.

Features

  • Easy to print
  • Single piece
  • Foldable
  • Lots of color options
  • Different versions for UNO, Leonardo and Chinese clones like visduino
  • Easy to adapt
  • Can even be lasered (in plastic or cardboard)

Background

I have quite a few of Arduinos and clones lying around and have missed an adequate casing. With bare PCB there is a risk of short circuit, and a temporary mockup looks more professional if the Arduino is encased. The cases I have tried were all too bulky, expensive or fiddly to assemble. Years ago, I designed a laser cut foldable raspberry pi case from a pizza box, and I got the idea that the same foldable technique could be used with a 3d printer. I quickly realized that by altering the material thickness, I could get both rigid and flexible parts from the same print. Since the sides interlock, the folded result is quite strong and sturdy, even though the material thickness is rather thin. The 3D print comes out with great result since there are no high walls or undercuts that need support, and the low material usage results in a fast print (if you are in a hurry ;)

Development

I designed the different parts in 2d, then separated them, added hinges and locking features. By extruding the sides and hinges, the first version was created in virtually no time. I first printed the flat case with the hinges at the bottom layer. The design folds with the glossy flat bottom surface as inner walls. This works great, but unfortunately prevents attachment details for the Arduino.

By rotating the part 180deg, the glossy surface becomes the outer surface and towers to lock position of the Arduino can be added on the inside of the case.  I was a bit worried for the folds – as they are printed in midair without support – but since the distance is small, this works great.

The design of the hooks was iterated a few times to find the balance between a secure fit and the possibility to open and reuse if needed.

I made two different versions:

  1. One for the official Arduino UNO with the bulky USB type B connector and socket mounted DIL ATMEGA328.
  2. One for Arduino Leonardo, and various Chinese UNO clones with micro USB connectors.

Assembly

Download the model and FDM print it with PLA, fold the case around your Arduino and snap it together. It’s as easy as that!

I used a BCN3D sigma and Cura slicer with the following settings:

  • 0.4mm hotend
  • 205deg temperature for the Colorfabb or Ultimaker PLA
  • 0.15mm step
  • 100% infill
  • No support

If you appreciate the work, or have ideas for improvements I would be happy if you shared your experience in the comments below.

Bill of Materials (BOM)

  • PLA filament – 22g or 2.8m@dia2.85mm

Documents

Licensing

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

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.

[youtube type=object related=no annotation=no link=yes cc=no theme=light ]

4hDFjNiHvQQ

[/youtube]

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.

Low cost microscope powered by USB

Description

How to add USB power to my 60$ microscope (Bresser junior 20x)

Features

  • Add current limiting resistor
  • Add USB cable
  • Add protective hardboard to the stage

Development

I recently bought a low cost (60$ or 50€) stereo microscope aimed for kids. I wanted to see how it compared to ten to twenty times more expensive versions. It actually performs very well and I am glad that I now have a small microscope at home that allows me to solder miniature components with ease. The only problem was that it used AA batteries for the built in LED. To solve this I simply did the following:

  1. Open the battery compartment.
  2. Add a 220 ohm current limiting resistor to the switch.
  3. Solder the power wires (red and black) from a USB cable to the resistor and the battery connector and close the battery lid.
  4. I added a replaceable piece of hardboard (Masonite) on top of the stage to prevent damage during soldering.
  5. Done, you now have a low cost stereo microscope ready for SMD work and there is no more need to change batteries.


Modified battery compartment beneath the microscope. It is easy to go back to battery operation is needed.

The microscope

Since the stereo microscope is quite small and doesn’t have angled oculars, the ergonomics isn’t comparable with a professional Leica version. It also only offers a fixed zoom of 20x (which is quite high). But except from that it really works perfect. Bresser is a German brand and the junior microscope actually comes with a five year warranty! I have soldered 0402 SMD components with ease and I definitely recommend it to others that want a compact and low cost stereo microscope for private use.


Image showing the 20x magnification (2x 0603 caps and SOT-23-5 3,3V LDO on the Arduino Lernardo). It looks even better IRL (due to stereo oculars and focus) !

You can find distributors all over the world. I live in Sweden and bought mine here.

Bill of Materials (BOM)

1x 220 ohm resistor
1x USB type A cable

Specification

5 volts 10mA

Licensing Creative Commons License

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

Nanino – the DIY friendly Arduino

Nanino v08 with prototype area (seen from component side)

Description

A minimalistic single sided Arduino compatible development board.

Features

  • Single sided PCB (easy to manufacture)
  • Arduino compatible form factor
  • LED’s for power and pin 13
  • Easy to access reset switch
  • Prototype area
  • FTDI Connector for serial communication
  • On board crystal with decoupling caps
  • Minimal cost (due to PCB and component count)

Development

I got a request from a college student in Brazil for a minimalistic Arduino PCB, very similar to a project I worked on a while ago. The requirements were to have a low cost single sided board that was easy to manufacture. It uses wide traces and a minimum of components. Instead of having a USB connection, a 5V FTDI cable is used. The board can be powered by either the FTDI cable or an external power supply (like a 5V USB charger or batteries). See it as what comes between a Veroduino and a Diavolino.
Milled PCB

Bootloader

In order to simplify the layout, the ICSP connector was removed. The bootloader can instead be programmed through the Arduino pin headers, or by removing the IC. An  AVR-ISP  (in-system programmer), USBtinyISP, a ParallelProgrammer, a Boot-Cloner or an Arduino can be used as a programmer.

Upload program to the Nanino

The Nanino has a serial interface (ttl level) that is compatible with a standard 5V FTDI cable. You can also build your own serial adapter or for example use a Sony Ericsson dock as adapter. Note that the FTDI auto reset is not implemented. You can either press reset after a program update, or add a 0,1uF capacitor between pin6 of the FTDI cable and the reset pin.

Bill of Materials (BOM)


component position (seen from component side)

  • 1x single sided PCB board (etch, mill or order)
  • 1x ATmega328P (28 pin DIL)
  • 1x IC socket 28 pin DIL (optional)
  • 2x 6×1 0.1” female pin header
  • 2x 8×1 0.1” female pin header
  • 1x 6×1 0.1” pin header (FTDI connector)
  • 1x 10k resistor (reset pull up – 1/4W)
  • 2x 1k resistor (power and pin 13 LED – 1/4W)
  • 1x Green 3mm LED (pin 13)
  • 1x Red 3mm LED (power)
  • 1x 16 MHz crystal (0.2” pitch)
  • 2x 18pF decoupling caps
  • 1x 6mm miniature switch (reset)
  • 2x 0.1uF decoupling cap 0.1/0.2”(aref and power)
  • 1x 1uF cap 0.1/0.2” (optional if power is good)

Removed features

To make a minimalistic single sided board the following things were discarded:

  • On board USB to serial converter
  • DC jack and power regulator (7-12V input)
  • Power regulator (3.3V output)
  • ICSP connector
  • Serial communication LEDs

Specification

  • 68.5×53.3 [mm] (standard version)
  • 4.5-5V DC


Assembled Nanino with ATmega328 

Version tracker

0.5                    Optimized routing
0.6                    Fine tuned PCB
0.7                    Added prototype area and component names
0.8                    Added toner transfer, compact and prototype version  – Current version
Future…           Maybe a Leonardo version (SMD ATmega32u4) with built in USB…

Documents

Project files:

Files for toner transfer (6 prototype and 6 compact, all mirrored):

See also

Licensing Creative Commons License

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

Bringing a 12 year old Roland MDX-20 up to date

Description

Adding USB connection, drivers and a new postprocessor to a low cost CNC mill (Roland MDX-15 / MDX-20).

Features

  • Adding USB interface to main PCB
  • Custom FTDI driver
  • HTML post processor
  • Batch files to control mill

Development

During my parental leave it is a somewhat bigger project for me to use the professional CNC mill at work. Since I have a miniature CNC router at home I don’t use anymore, I figured now would be a good time to improve it. The reason that I don’t use it is mainly due to the ultra crappy software that Roland provides. Each time I have to mill something, I have to spend a lot of time tricking the software to do things that it originally doesn’t support, which is time consuming, frustrating and usually results in several trials until it works. The fact that the mill doesn’t have support for G-code means that you most likely can’t use the CAM programs that you prefer (some third party options exist, but I haven’t found any worth the money). On top of that the mill needs a RS-232 serial connection and doesn’t work directly with an usb2serial cable (with default drivers)… These are the reasons that the mill has been collecting dust on my attic for the last six years. This is a pity, because the mechanical hardware is actually quite good.

Adding USB interface

I hate cables and connectors that fall apart almost as much as I hate running back and forth between the mill and the PC. Therefore I wasn’t so fond of adding an usb2serial adapter at the end of the long serial cable. Instead I added an FTDI usb2serial (TTL) chip inside the machine. Now I can just plug it in and it will work. Any FTDI chip that has Rx, Tx, RTS, CTS, DTR and DSR will work. I used a Sony Ericsson dss-20 syncstation which has all the necessary components, but a standard FTDI breakout board will work just as well. The mill has a very limited memory for storing commands and therefore uses hardware flow control for the serial communication. To support this I soldered a wire between RTS and dsr and one wire between CTS and DTR on the FT232BL chip. Then four cables were attached to Tx, Rx, GND and to the CTS/DTR wire.
I hoped that I could attach the cables to the secondary side of the DS14C238 chip on the main PCB in the mill, but it didn’t work. Instead I attached them directly to the primary side of the MAX238 clone.

  • Rx to pin5 (Din1)
  • Tx to pad under pin6 (Rout1) **
  • DTR/ CTS to pin 19 (Din3)
  • GND to pin 8 (GND)

** please observe that pin6 has to be lifted from the pad to release the signal to the main H8 CPU (solder the cable on the pad under the pin, make sure the pin isn’t attached). When all the cables were attached I used hot glue to mount the USB board above the main board inside the mill. I also secured all the cables between the boards (see photo). A small hole was cut in the cover of the mill to attach the bend protection on the USB cable.


The USB to serial adapter mounted inside the mill (the small board above the main board)

Adding custom FTDI drivers

If you search for mdx-20 and USB adaptor you will find that a lot of people have failed using a USB to RS232 adapter with the mill. They explain that the mill needs an old pc with a real serial port, since the USB protocol (package length) doesn’t work with the hardware flow control. – This is a myth! They are right that a USB serial cable doesn’t work with the default drivers. But you can find custom drivers on the Roland web site that works with a FTDI adaptor.

Reverse engineering a new postprocessor

With my USB connection for the mill, the hardware was up to date. The next thing to fix was the software. I really don’t like the Roland software package (modela, dr engrave, 3d engrave) that was already out of date when it was released 12 years ago. I didn’t want anything to do with the programs or the drivers, so I figured it was best to communicate directly to the mill itself. (It will then also work on all platforms, Linux, WindowsXP/7/8 etc). I created a fork of html-cam, which allows you to convert mill paths from a very simple neutral file format to g-code (also works on all platforms). See more details here. Instead of generating g-code the new versions now generates a Roland CNC mill file that can be sent directly to the serial port. I ran into quite a few problems during the development. To reverse engineer the protocol, I generated some simple curves and printed them with existing software. Instead of sending the file to the mill, I printed it to a file. Then it was a matter of understanding the generated code. The syntax is quite weird, but after a printout and some study with a highlight pen I got it to work. The only problem was that all the mill movements were too big. I guessed it was related to a mm to inch conversion, so I divided all the lengths with 2.54. Better, but when I measured some samples more precise, they were now slightly too small instead. I realized that a division of 2.5 gave a perfect result. Since the mill doesn’t handle decimal places the right coordinates of a position in mm has to be multiplied with 40 (100/2.5). I guess this is just the ratio of the stepper motors and have nothing to do with imperial/metrics conversion… Finally I got the 2D conversion to work and I quickly converted the drill operation as well. I can now export my mill paths from Rhino3d (using this script) to the neutral file format and then paste them in html cam (MDX version), set cutting parameters and generate mill code that can be directly sent to the com port.

Setting up the com port

Sending data from html-cam to the printer is really simple. First you need to make sure that the port is configured correctly (with the right custom drivers if you use a USB adapter, see above). Then the com port needs to be set up using the following command in a dos/command prompt:

“mode com3:9600,n,8,1,p”

Then all you need to do is copy the generated file to the port:

“copy /b mill.txt com3”

To make it even easier I have made some batch files to automate it for you. (download further down)

Manually moving the mill

When I set up the mill it is very useful to be able to move the router to an exact position. To do this I created another batch file with the following syntax:

movemill p,x,y,z
p:      com port (default=3)
x,y,z:  Coordinates * 10 "Example 2.55mm -> 25"

It moves the mill to the exact position that you specify. Please make sure that no obstacles are in the way of the spindle movement.

Example – make a PCB

Here is a step by step guide for how a PCB can be milled with the Roland MDX-20:

  1. Design the PCB (can be done in Rhino – see this guide for more details)
  2. Fixate FR3/4 substrate on mill (using double sided adhesive)
  3. Power on mill and leave “view mode”
  4. Mount engraving tool in mill
  5. Prepare and export mill paths for the PCB (in neutral file format)
  6. Move engraving tool 4,4 mm (x,y) over PCB using the batch file “movemill 3,40,40,0”
  7. Set Z=0 using the down key on the mill (press down repeatedly until you have contact – listen to the a change of sound)
  8. Paste engraving mill paths in html-cam and set cutting parameters: 1mm clearance 0mm cutting depth (-0.1 if the cut is too shallow) 2mm/s engage speed 4mm/s cut speed
  9. Press generate key and copy generated data to a text file named mill.txt
  10. Run mill.bat (configures com port and copies mill.txt to com port)
  11. Lean back and enjoy a PCB being made
  12. Repeat steps 4-11 if you need to drill the PCB and finally for cutting out the release path.

Caution

Use the files with care. I have tried them with good result, but I don’t take any responsibility if they generate any error. I recommend that you set z=0 above the workpiece first and mill in air to make sure everything goes as expected. When it works, reset zero and redo the operation. Make sure that the indata is correct and doesn’t contain any strange characters.

Documents

See also

Licensing Creative Commons License

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

Miniature USB to serial PCB

Description

A small FT232 USB to serial adapter built to fit directly in the USB port

Features

  • Integrated USB header
  • Standard FTDI cable pinout
  • Single sided PCB (easy to manufacture)
  • Rx,Tx led’s
  • Miniature size

Development

Lately I have been developing several projects that use a FTDI chip to provide USB interface to a computer. Instead of using a Sony Ericson dss-20 sync station all the time, I figured it was time to develop a dedicated solution that fits directly in the USB port. I have a bunch of FT232BL chips that I bought extremely cheap in Huaqiangbei last time I was there, so I based the layout around that chip. On the serial side I used the same pin-out as the de-facto standard FTDI cable (GND, CTS, VCC, TXD, RXD, RTS). It was a little challenging to manually route the traces (using this method), but I think it came out quite well. You can see the whole process here in 10 times the speed:

[youtube type=object related=no annotation=no link=no cc=no theme=light ]gKUJWfZuEMg[/youtube]
watch in full resolution

I could have avoided the single bridge wire by routing the 3,3v (pin6) signal under the 0603 1k5 resistor, but it would have increased the risk of short-circuit. After a bit of tuning I managed to fit everything within 35×18.5mm, which is smaller than most USB memories. I manufactured the PCB by milling it using the HTML CAM to generate the g-code, but toner transfer or UV mask should work just as great. I hope that this design can come to use for others as well!

Assembly

This is not a project for the very beginner since all components are SMD (surface mount) and the LQFT 32 package has a 0.8mm pitch. However if you have access to decent equipment they shouldn’t cause any problem (solder station with a narrow tip, tweezers and a microscope). Start with the 0603 components, then the chip and switch and solder the crystal, wire bridge and pin headers last.

Bill of Materials (BOM)

1x single sided USB2serial board 2mm thick (etch, mill or order)
1x FT232BL
1x 6×1 0.1” pin header (preferably angled)
2x 0603 0.1uF capacitor
1x 1206 10uF capacitor
1x 0603 33nF capacitor
1x 0603 green rx/tx led
1x 0603 220R resistor
1x 0603 470R resistor
1x 0603 1k5 resistor
1x SMD 6 MHz crystal
2x 0603 27pF decoupling caps

Specification

35.0 x 18.5 x 2.0 [mm]

Version tracker

0.1             First version
0.2             Added tx/rx led’s
0.3             FTDI cable compatible pin-out
0.4             Optimized size
0.5             Tweaked the USB header (current version)

Documents

Rhino project file (2D lines)
2D Vector export (svg)
2D Bitmap export (png @ 1200 dpi)

See also

Licensing
Creative Commons License

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

Ultimate PIC16F628/627 breakout board

Description

A miniature breakout board for rapid development of microprocessor projects

[youtube type=object controls=no info=no related=no annotation=no link=no cc=no theme=light ]ttUvpEUfh1Q[/youtube]

Features

  • ICSP connector for quick programming and power (PICkit compatible)
  • All pins available on standard .1” pin headers
  • Single sided PCB (easy to manufacture)
  • 4 debug led’s
  • 1 generic switch
  • Connector for serial communication
  • Power led
  • On board crystal with decoupling caps
  • Miniature size

Development

I needed a small PCB for a power meter project that I am working on. Instead of making a custom PCB I thought it was a good idea to build a generic version that can be used in several different projects. Since my microprocessor projects have many things in common, it made sense to make a breakout PCB that provides all the things that is needed: An ICSP connector to start with, access to all I/O, a power led and sometimes debug led’s, a switch, serial communication and a crystal. All the components are optional and you only mount the ones that you need. The PCB was manually routed and optimized using this method. I think it really shows the advantages of the manual routing and optimization. The PCB is very compact and doesn’t have a single bridge wire. It took less than one hour to design and fine tune. I milled the PCB using HTML cam to generate the g-code. Toner transfer or UV mask will of course also work, but then you need to manually drill the holes and cut out the board…

Other versions

It is quite easy to make different versions [for/of?] other processors. Let me know if there is anyone in particular that you miss, and I will see if I can find time to make a few other versions.

Assembly

This is not a project for the very beginner since all components are SMD (surface mount). However if you have access to decent equipment they shouldn’t cause any problem (solder station with a narrow tip, tweezers and preferably a microscope). Start with the 0805 components, then the chip and switch. Solder the pin headers and optional crystal last.

Bill of Materials (BOM)

1x single sided breakout board (etch, mill or order)
1x PIC 16F62X
1x 6×1 0.1” pin header (preferably angled)
1x 0805 0.1uF decoupling cap
2x 8×1 0.1” pin header (male or female) (optional)
1x 0805 green power led (optional)
1x 0805 1k resistor (if power led is used)
4x 0805 red debug led’s (optional)
4x 0805 1k resistors (if debug led’s are used)
1x SMD switch (5.1×5.1mm) (optional)
1x 0805 100k WPU resistor (if switch is used)
1x miniature 4/8 MHz crystal (4.86mm pitch) (optional)
2x 0805 1-68pF decoupling caps (if crystal is used)

Specification

25.4 x 31.75 [mm]

Version tracker

0.1             First version
0.2             Added led’s and switch
0.3             Added crystal and serial connector
0.4             Optimized size (current version)

Documents

Rhino project file (2D lines)
2D Vector export (svg)
2D Bitmap export (png @ 1200 dpi)
Demo code – LED chaser 

See also

Licensing
Creative Commons License

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

 

Web controlled home automation

Description

This post is the last of three and describes the software needed to build a web controlled home automation center. The previous two describes how to add a serial interface to a router and how to build a microprocessor lab board.

Features

  • Software for the router (OpenWrt)
  • Software for the web server (html and CGI)
  • Software for the lab board (PIC16F628 assembler)
  • Protocol for serial communication between router and lab board
  • Protocol for 433MHz radio (and html generation tools)

Development

My first project for the web access lab board is an Internet controlled home automation system. This allows me to control the lights in my apartment with my Smartphone or iPad (accessing a web page). I already have the infrastructure – custom built control panels and hacked low cost receivers (I will try to post them later).

In a way using a separate microprocessor for the radio communication is overkill. You could bit bang the radio data directly from the router using the power LED, but the microprocessor adds the ability to have more features (like IR communication) and for me it was a quicker hack since I had most of the code ready.

This is how it works:

  1. A mini router is running OpenWrt with a tiny web server
  2. The web server shows a plan of my apartment with icons for all controllable lights.
  3. The icons have links that starts CGI scripts
  4. The CGI scripts are sending control data to the serial port of the router
  5. A PIC microprocessor decodes the data and transmits it as 433MHz radio signal
  6. An RF switch or dimmer receives the data wirelessly and changes the attached light accordingly.

Installing the router


It was very easy to install and set up OpenWrt on the router (by following the steps in this link http://embeddedtimes.blogspot.com/2011/09/tp-link-tl-wr703n-tiny-linux-capable.html). The biggest problem was to change the baud rate on the serial port. This is done with stty, but the problem is that stty isn’t included in the busybox that comes with the default OpenWrt package (I tried picoterm, microcosm and setserial without success). You can either install this custom firmware or just replace busybox with this version. Try to avoid deleting all symbolic links to busybox, or you will be busy for a while (trust me, I know…).

Make sure the web server starts on boot and that the baud rate is set to 9600:
stty -F /dev/ttyATH0 raw speed 9600 -crtscts cs8 -parenb -cstopb
When everything is ready you should have web access to the web server on the router and a serial port running @ 9600 8n1

Setting up the web interface

The user interface showing three different mood buttons, a floor plan for the apartment (the magenta box turns off the complete room) and the individual controls for the lights.

I wanted to have a visual control over all the lights in my apartment. I did a graphic floor plan and added light control icons for all the controllable lights and saved it as a png. Then I created a webpage that displayed the image and used image map to link the icons to different CGI scripts. In the future I will encode the data in the html file to a generic CGI script, but as a quick fix I created different CGI scripts for each light, one for light on, one for light off and others for light intensity (see radio protocol further down for more details). I then uploaded the files to the router and set the right permissions to the CGI files. As a final step I connected my logic analyzer to the serial port of the router and verified that everything worked as it should.

Open Source serial protocol

Instead of inventing something new I thought it was a good idea to use a protocol that already exists. I found this open source protocol that is used in a product called tellstick, sold in Sweden. It does the job and it allows support for many different standards of radio recievers. Here is a brief description of the protocol:

The first byte defines type of command; if it is an “extended send command” the following four bytes declare four different timing lengths in 10us values. Then one byte with package length of the data followed by the real data and ending with a “+”. The data is encoded so that the length of each high or low flank is matched to one of the four different timing lengths (written as two bits).

The lab board

The microprocessor receives the serial protocol (using the USART), decodes it and sends it as radio, by bit banging the radio data, to a hacked radio module from a remote control. All the code is written in assembler (1075 lines); you can find the compiled .hex file and the source at the end of this post. I used a PICkit2 programmer attached to the ICSP port of the lab board to upload the microprocessor code. The lab board is designed to be used with a router for web control, but it also works great together with an ftdi cable for USB control from a PC.

Radio protocol

Since the serial protocol is generic and supports several radio protocol standards I could choose the one that I think is the best. For me it is important that each remote receiver can respond to several different transmissions and not just a single id. This allows me to arrange different lights into groups so that  a single command can  set the light on several devices at once. And by arranging all lights in a room to one command, I can turn off the complete room with one click. It is important that the devices have unique addresses so that my neighbors won’t control my lights by accident. All this is possible with the NEXA (learning code) protocol which allows 67 million different codes. To generate different codes for my devices I wrote this set of JavaScripts that generates the raw data that is transmitted to the lab board to control the lights.

Version tracker – microprocessor lab board files (PIC16F628 assembler)

0.1          Hard coded radio commands
0.2          Telstick protocol
0.3          Added serial interface
0.4          Adjusted timing
Future     IR transmission (to control stereo, TV etc)

IR reception (to control the lights from an IR remote control)

Version tracker – JavaScript (to generate nexa commands)

0.1         First version (only using hex code)
0.2         Hex code generation
0.3         Added light intensity support
0.4         Added different hex outputs
Future    No updates planned

Documents

Web server package (html and CGI files)
Lab board compiled file (.hex)
Lab board source code (PIC 16F628 assembler)
Radio protocol generator (html with JavaScript)

See also

Licensing
Creative Commons License

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