First, I haven’t really blogged before, so this blog is also (hopefully) a work in progress. It will probably look really bad. For starters I have no idea why it is so narrow! Sorry about that!
Also, I absolutely wanted an offline editor on my Linux box for the blog. For the moment that is Bleezer (link at bottom). Doesn’t seem to be supported anymore, but that’s the one I got working-ish. The point about this is that every time I update this blog, the comments disappears… sorry about that too. And I will try not to update it via Bleezer if and when comments appear (Sorry to my brother who has supplied me with a couple of nice comments already!).
This is about an electronic Rubik’s cube like display thing I’ve made. Except it’s not completely finished yet, but for now I do have a working Rubik’s Revenge (as the Rubik’s cube 4 x 4 x 4 is called) on it. It is based on the Arduino platform using an Atmega 328 microcontroller, lots of RGB LEDs and shiftregisters. I have dabbled a little in electronics and programming from time to time throughout the years, but very periodically.
Ironically I also have come to realise that I don’t really use any of my regular Rubik’s cubes that much any longer, and also that I never was an expert on them. (I was “down” to around 5 minutes for the 3x3x3 Rubik’s cube, and some 21 minutes for the 4x4x4 Rubik’s Revenge at some point in time). I figure this will probably be more of a “mood light thingy” with (maybe) a Rubik’s cube functionality, rather than just a Rubik’s cube. Perhaps even instead of a Rubik’s cube.
Besides it’s a bit unpractical at 1.1 kg and about 15 cm cubed😛 It does contain 3 AA batteries, but I usually run it off external power.
I begun making it just before november 1th 2009, and was as finished as the picture above shows mid-december 2009. After that it has been all about software. Time flies, and it’s already soon half a year since I begun constructing this, and I figured I should post a little blog about this thing as I’ve kind of run into a sort of stand-still the last couple of months. It’s only sitting on my shelf for now. Besides, I figure blogging about this might get me a little input and inspiration.
For now I usually have the color tests running. But I have forked out a version for the Rubik’s Revenge (since the button pad is 4 by 4) too, but it is more of a beta version than a finished program. I haven’t came up with a good menu or mode-select solution method just yet. Ideally I’d want some sort of high-score list too. Maybe a self-solving cube even?😛
ERROR ERGO SUM
Now I did make some errors while designing it, and I think I need to address one of them in particular.
Since the PCB in question had limited space for components, I choose to not use any driver IC’s, and drive the LEDs directly between the shiftregister outputs. Hence I had to use a rather restrictive current through the LEDs. In bright daylight the cube wont be much to look at, but indoors and moderately lit, it works just fine.
Embarrasingly I managed to mis-calculate the current need for a row of 4 RGB LED”s (A matter of multiplying with 3 RGB LEDs instead of 4…or something like that), and even then I was designing it on the edge..well slightly above the rated max. A big no-no in designing as I’m sure most of you would like to tell me. So in fact the 4 row bits of the shiftregister will be driven even more above specs for all-white rows. Well.. almost 50-ish % above specs.. in theory at least.
In practice however, things look better! Although I have not yet had the chance of measuring the current out of an individual output from any shiftregisters. Measuring total current for the hole cube however indicates that things are not so bad after all. A white, fully lit cube consumes about 185mA. Disregarding the current to the other circuits, this suggest an output current for the row pins around 30.8 mA. In practice, again, even a bit less. How much less I don’t know. And each row pin is on for 1/4 of the time. Not too bad I hope!
In retrospect I might have had enough room for 4 small NPN small-signal transistors for the rows though. But I’m not about to redesign it and make 6 new PCBs and solder them again just yet! Well, I might in fact redesign it at some time, but I doubt I will make 6 new PCBs for myself.
When I selected series resistors for a white as possible colour in the RGB LEDs, I experimented with 5V as the supply voltage. Thinking that the output of the 74HC595 would’t differ much. However, luckily I now think they do differ a bit. The LEDs are all connected between 74HC595’s outputs for both source and sink
I found that with a 5V suppy, 1k ohm resistors for both the red and blue LED worked nice, and a 390 ohm for the green one. This will then mix to a rather white-ish light. A fully lit RGB LED will then use 11.19 mA, theoretically. A total of almost 45 mA for 4 LED’s, on an output capable of max 30 mA… But, as stated, this is teoretically speaking and in practice the numbers are lower. Which was a good thing concerning the current consumption, but not so concerning the color even-ness.
A measurement of the current consumption of the hole device is actually pretty optimistic:
- Red: 88mA
- Green: 116 mA
- Blue: 65mA
- Yellow: 163 mA
- Cyan:145 mA
- Purple: 123 mA
- White: 185 mA
As evident from this list, the RGB colors aren’t exactly additive (no pun intended) current-wise. As stated, probably due to the outputs between the shiftregister outputs are not exactly 5V, and even worse at higher loads (not surprisningly). Also, the colour even-ness is even more worse, of course, when I drive the cube from it’s internal three AA batteries at 4.5 V. When they are new or recharged that is.
I assume that when driving the LEDs at such a low current, the differences in their specifications are more noticeable.
I have simply accepted that the colors will not be very even amongst these “identical” RGB LED’s, I simply cannot be too picky here (not after making this thing anyway :P) I probably could swap the handfull of blue ones though, as those are the worst. But all things considered I think that the colors are pretty good imho!
The only little detail is that at 3 PWM levels, some orange buttons can be hard to distinguish from some yellow ones, because of the differences between LEDs. But usually it is fine. At 4 PWM levels and above, this improves.
ABOUT THE NAME
Well, since it is based on the Arduino platform, and it is a cube… Cubeduino. But I made the name before reading the Arduino FAQ,, which states:
“Note that while we don’t attempt to restrict uses of the “duino” suffix, its use causes the Italians on the team to cringe (apparently it sounds terrible); you might want to avoid it.”
So to any Italians (and others that feel the same way), sorry about that :PI’m actually a bit ambivalent about the name myself, but I’ve been using it for a while now (except I usually just call it The Cube).
Basically, it consists of this:
- A wooden “Core Cube” frame
- 1 one-sided PCB 6 cm by 6 cm, the “mainboard” in the center with the atmega 328 microcontroller on it.
- 3 AA Batteries😛 also inside the core cube.
- 6 one-sided PCB’s 8 cm by 8 cm, below the keypad PCB, the SIPOPISO’s interface boards.
- 6 double-sided keypad PCB’s 10 cm by 10 cm, with the RGB LED’s and the 4 by 4 button pads.
I should probably have a more detailed parts list, except I never really made one! If you want the details, they are in the Kicad files at the bottom. In essence the electronics consists of this:
- 1 atmega 328 microcontroller with an arduino compatible bootloader
- 7805, 5V voltage regulator
- HT7833, 3.3V voltage regulator
- 1 SparkFun MMA7260Q 3-axis accelerometer breakout PCB (with accelerometer)
- 12 74HC595 8-bit shiftregisters (the “SIPO” part, for display output), with sockets.
- 12 74HC165 8-bit shiftregisters (the “PISO” part for button inputs), with sockets.
- 6 SparkFun translucent silicon rubber button pads 4 x 4
- 96 RGB LEDs, common anode.
- 48 1 k ohm resistors
- 24 390 ohm resistors
- 110-ish 10 k ohm resistors.
- 6 BC548B. General-purpose NPN transistors, they are only used as inverters.
- 2 47uF capacitors
- 14-ish 100nF capacitors
- 6 female headers, 2×25-pin
- 42 male headers, 2×2-pin
- 6 male headers, 2×3-pin
- 1 female header, 1×8-pin
- 1 male header, 1×8-pin
- 6 female pin headers, 1×6-pin
- 6 male pin headers, 1×6-pin
- 3 male headers, 1×2-pin
- 2 diodes
In addition to some wires, 36 screws, 3mm by 20mm long for wood. And 20 M3 x 20 mm and 4 M3 x 50mm screws. And some nuts, some 2.5-ish meters of insulation tape, grill sticks and “meat sticks”🙂
In short it has a total of 96 RGB LEDs, and also 96 buttons. Weight is about 1.1 kg, and measuring about 15cm cubed.
Total cost? I’m not too sure😛 I guesstimate somewhat around nok 1500,- ($250-ish). And some countless hours.
Wooden core cube
The SparkFun 4×4 rubber button base is 10 by 10cm. I first figured I could make an additional 4 holes in it, placed in a the center of each “2×2” button corners. The holes would then be 5 cm apart in a square. Later I abandoned these 4 extra holes in the button pad (for now at least), but that square of 5 by 5 cm is my base for the center core cube, which holds it all together mechanically.I also designed the button pad PCB with these holes. In case I need them later. And also (of course) the SIPOPISO PCB.
I happened to have some (rather hard to translate to english, but I’ll try) wooden “meat sticks” that fit almost perfect. Original use is for cooking meat🙂 They were almost 1 cm by 1 cm by some length of about 17 cm. These were cut into 24 pieces, 12 with length 8 cm, and 12 with length 4 cm. Pretty nice round numbers there (for metric users at least:P). These sticks are assembled into 6 frames, which again is assembled into the Core Cube frame.
I have since made these schematic drawings of the core frame parts:
And this, of one assembled frame:
They were assebled with 3 x 20 mm screws for wood. The screw heads are recessed, as indicated by the Y-like blue lines, or blue dotted circles if viewed from above.
Unfortunately, the center screw on the short stick was not too well placed. It is neccesary to insulate them, or else they might short out some of the LEDs. I still get that error sometimes when I put the keypads back on.
And the finished core cube, with screws sticking out. Actually these are not the ones I ended up with, these are a bit too long. If memory serves, the ones I ended up with are also 3mm by 20mm long, M3 (metric) screws. I did not recess these screw’s heads, so it was a bit fiddly to get them in there.
The wooden core frame in all its ugly glory. My carpenting skills are not that good…
I have swapped some of the wooden sticks later, to make it a little better and more straight.
I decided to make 6 identical keypads, centered on the use of shiftregisters for both input and output (buttons and display). Since each keypad has 4 by 4 translucent buttons with RGB LEDs underneath, it fits nicely with 2 shiftregisters for output and 2 for input (16 bits each). That is, the display shiftregisters holds one row of RGB data, as well as row multiplexing, 4 bits each, 16 bits total. All keypads share the same clock and latch lines, with individual data in and out, plus power, requiring a 6-pin connection.
The Atmega 328 has 20 I/O pins total, and they are used like this:
- 12 pins for data I/O to all 6 sides (2 per side).
- 2 pins for common clock and latch to all sides.
- 3 pins for the triple-axis accelerometer.
- 2 pins for serial communication (firmware update).
This leaves one pin left, which is basically unused. Well almost, it can be used as an input to the randomizer if that needs arise. It’s an unconnected analogue input – as long as one do not use R3 on the Cubeduino Core PCB (the mainboard). I did not use R3, which btw also is the only SMD component. I have not taken the leap yet, and use all through-hole components (except R3).
While the display data is spit out row-wise with 74HC595 shiftregisters, the keypad buttons are read column-wise into the 74HC165 parallel-in serial-out shiftregisters, because of the keypad PCB layout.
(A little “Christmasee”, but it looks kinda naked without the button pads.)
The display colors are mixed using PWM, but since that is achieved via shiftregisters, the PWM is severly limited compared to the built-in hardware PWM of the Atmega. I usually have tested with 3 or 4 levels of PWM. 8 works nicely too, well, I believe it would look nice if I increased the ISR (Interrupt Service Routine) frequency for the display. I also believe I just might get it up to around 16 levels or so (untested), but not without a huge penalty in terms of processing power left. For a Rubik’s cube 4 or so should be enough.
FPS = ISR frequency / (PWM-1) / 4
At the moment I use an ISR frequency of 1 kHz.
At 3 PWM levels the framerate, as the software is now, should be 125 Hz. At 4 PWM levels it is 83.33 Hz.
In the beginning I just had the test code running from the outside, on the Arduino compatible BBB from Modern Device. Here it is somewhat hidden under the LCD on the breadboard.
Well time for some schematics. I made everything in Kicad (amazing software btw, though quirky). I basically learned Kicad while doing this project. Not that I have learned all there is to know about it.
I’m sorry these schematics pictured below are a bit low in resolution (I didn’t upload them so small!). Here are some links to images with a better resolution:
For a more detailed look, check the kicad link at the bottom (Of course then you will need to have Kicad installed).
Some quick notes about the three schematics/PCB’s of the cubeduino follows: While two of the PCBs are one-sided (Well, it’s relly seven, as six of them are of the same PCB design), I designed all as two-sided PCB’s. The component side tracks are then replaced by wires in reality. Hence I didn’t route those component-side tracks too elegantly.
This is the mainboard of the system. It contains the Atmega 328 with the excellent arduino compatible ADABOOT bootloader. For a future cool software addon, I also stuck a SparkFun breakout board for the MMQ7260 3-axis accelerometer in there🙂 It is only shown as an 8-pin connector here, since I didn’t make a part for it in Kicad.
Since I continously update the software, I also brought out a connector for a FTD232 USB-serial converter chip (USB-BUB). But it is not built-in.
R3 is not used (not important at this time, I’m not using the fact that I’m not using R3 for the time being either :P)
NOTE: I swapped the connector for the SIPOPISO interface nr.0 and 2 (the rightmost connectors in the schematics below). Rather than open the thing and correct it, I simply swapped this in software.Hence SIPOPISO 0 is not top-side of the cube, but at the right-hand side, and vice versa for SIPOPISO nr 2. The coordinate system is explained in the source code. The mainoard sits above the “bottom” SIPOPISO, that is interface 5.
Or “1/6th keypad (inter)face board”. There are 6 of these, and these PCBs are also one-sided. Measures 8 cm by 8 cm. Beware that the 6-pin connector to the Arduino, is located below the PCB, on the solder side. I forgot to mark the transistor, it is a BC548B. Basically general-purpose NPN.
There are also 6 of these of course. These are double-sided 10 cm by 10 cm. At the schematics below it might seem like a strange button/LED matrix, but the reason is that I made a kicad part for the button base 2 by 2. So there are 4 of those here (for the button pad 4 by 4).
I have not directly included layouts for the PCBs here. They are included in the Kicad files below.
For now some quick points about the PCB’s and assembling follows.
KEYPAD PCB AND RGB LEDs
The RGB LEDs that I got a hold on, had an ARBG pinout as opposed to the (I guess) more usual xAxx, where the common led is the second one. Or third, depending. A = common anode. This is very important if you want to make the keypad PCB, you must have the ARBG pinouts! Strange thing, my RGB LEDs still had the second pin as a longer pin, even the internal of the LED it looked like to be a common one, but it was not. I’m only glad I got the same one on every occation I ordered them!
Also, to get the LEDs at an even height on the PCB, I had a 2mm drill bit below it while soldering. This also made it possible to solder on the component side of the PCB, below the LED. And it fit nicely under the button pad too.
Another little tip is to keep the LED legs you snap off, to use on the keypad for connection between the solder side and component side for the button pad’s internal vias. I had to route those to the other side of the board, though I guess it’s always the possibility of designing the component side a bit different.
Note: I didn’t put arrows to every via.
I used 0.7 mm drill bits to drill the holes for the RGB LED’s. This was a tight fit and I struggled to get each and every one of them in place. But I think it was for the best in the end (Btw the drill bit broke early on, but I continued to use it for the hole project).
When done, I insulated the track from the LED’s common pin, that was routed out of the button pad rings, with a dash of some white lacquer.
Also, the male header pins should not stick too much above the surface of the solder side on the keypad PCB. But the button pad is about 2mm thick rubber, so it went pretty well. Well, almost that is, the pad can be a little “buckly” (that is a word, right?).
SIPOPISO (The “1/6th keypad (inter)face board”)
I really like the Kicad 3D viewer!
This is a one-sided PCB, but I didn’t manage to get all the tracks on one side, hence a few wires on the component side.
The female headers I found was cheaper to buy a 25 by 2 row type, instead of 7 pieces of 2 by 2 and one 3 by 2. I just used a hacksaw and sawed them off. One must saw through one column of headers, so you will loose one for eact header you saw off. Then I grinded them a bit so they looked a little nicer. I placed them in a ring-like manner because these are basically the ones holding the keypad in place mechanically (plus it needed to not disturb it too much), at least until I re-implement using a longer scew from the core, through the keypads. If I ever get to do it like that, that is.
Unfortunately two of the middle female headers, for connecting to the keypad, get in the way of the core screws, so those screws needs to be insulated. I simply used electrical tape, but that isn’t always enough. I have to be a bit careful when refitting the SIPOPISO PCB.
Note, as stated, the 6-pin connector is located on the solder side of the PCB.
As stated, a 25 by 2 female header row fitted nicely for one SIPOPISO PCB, there is only one column of pins left over (which you gotta loose by sawing through it and grind it away).
THE MAINBOARD / CUBEDUINO CORE PCB
This is a one-sided PCB, 6 cm by 6 cm placed inside the core cube. I had to saw off two corners to make it fit, as indicated by the yellow diagonal lines at two of the corners. Shown here from the Kicad 3D viewer.
The thing to keep in mind here is that it fits upside-down directly below (or above) a SIPOPISO board connector. One of the 6 connectors are located on the solder side of this PCB too. Hence there is no need for a wire between them. The other 5 SIPOPISO’s must be connected to it through one of the connectors above. The connecting wires are really just male / female pin headers soldered to flat cables, which are taken from old computers. Since that is what I had at hand.
I don’t remember the exact length I used, around 6-8 cm or so. And one is a bit longer, for the “battery lid”. Which is not really a lid at all, it’s just one of the sides that needs to be removed to access the batteries. Not the most elegant solution though😛
One of the connector are below the PCB for directly connecting one to one of the sides.
PUTTING IT ALL TOGETHER
Side view without the wooden core frame:
I haven’t connected the keypad in the above and below image, it’s just sitting loosely on top of it.
One side of the Cubeduino system. Looks like a Pyramid😛 Yes, that is a triple-axis accelerometer at the top. For now it is not utilised in software, but it will be.
The mainboard mounted inside the core cube, with the SIPOPISO plugged in directly below.I had to hacksaw off two corners on the mainboard to make it fit (indicated on the kicad PCB file). It was quite fiddly to get it inside there.
Starting to look like something. This with an early color test code running. I still didn’t quite know what to do with the ugly edges, but I figured they would come in handy for an on/off-button later on. They did🙂
Notice the long screws at the lower part of the image? Out of the 24 M3 screws that stick out of the core frame, 4 of them are 50mm long. This was a make-shift support for the battery holder. The battery holder holds three AA sized 1.5V batteries. Unfortunately I don’t have any pictures with the battery holder inside.The nuts are not below the SIPOPISO PCB in the end, thus I sometimes have the aforementioned trouble with the screw heads (under the tape) shorting out some LED connectors sometimes. Because the soldering points will sometimes stick trought the tape.
Assembly time #1, with ugly open edges.
Now for the ugly edges, I once again looked at the food industry😛 I had bought some wooden grill sticks, and these, together with some insulation tape, formed the basis for making nicer edges.
I simply glued the grill sticks with a glue gun, on all 4 sides below the keypad PCB. Then I kind of sewed the insulation tape in place with some white
wire. I wanted the sides to look as white as possible.
The first grill stick glued to a keypad PCB (lower side of the keypad PCB at the center of the image). This first one was a bit too long. If memory serves I eventually settled for cutting them into 9 cm pieces. This was simply to get a better support for the insulating tape.
I later divided the insulation tape into 4 pieces, one for each side, since the corners became too round for my liking. But I kept this first one, as I then can see which side I have to remove to change the batteries🙂 Btw I have no idea how long the batteries will last. I haven’t changed them yet, and I’m sure they have ran this thing at least 2 hours.
Starting to really look like someting.
ON / OFF BUTTON
Only thing left was an on/off-button, which I kind of didn’t plan too well. I resorted to make a thin slice of stripboard, which fitted nicely under an edge. The on/off button can be seen at the top-right corner of the cube, on the stripboard. I had to make two notches in the stripboard at the center, where there was a female header on the SIPOPISO’s. You can see it at the top center of the above and below image.
I also got a connector for the “USB BUB” board, the FT232R-based USB to serial converter board, used for uploading code or debugging. It is the black thing seen sticking out of the top-center of the cube in the upper image. Plus another connector for the power to the left. It didn’t work out too well, so I made two connectors for the power, an additional simple 2-pin male header. Later I added a diode in series with this male header, in case I should connect the polarity wrong.
I don’t really have any schematics or PCB layouts for the stripboard with the on/off-button, power connectors and the USB BUB connector. (It’s the undocumented part of the project😛 )
The on / off button only works with the batteries. Hence it can also be used as a “charge batteries” button when using external power. But that is a “use with caution” option. Also preferably rechargeable batteries.
And finally, done! Well…except for some programming, that is. Shown here on top of a mirror for dramatic effect.
(Just some test colors shown here, not the Rubik’s Revenge code)
But I have to admit it is somewhat lacking in the finish. Also, it feels kind of like a cube shaped rubber ball😛
Using a translucent DVD spindle as a base, it actually doesn’t look too bad🙂
This project could not have been done at all without these people:
Arduino, open-source electronics prototyping platform.
Arduino Interrups, by uC hobby. An excellent explanation, thanks!
mega-isp project, turn your Arduino into an ISP programmer! Brilliant project!
ADABOOT, a modified bootloader for the arduino. This is a really excellent bootloader! check it out!
Kicad, an electronics CAD program (link to sourceforge). Also really excellent, and multi-platform (Linux and Windows). But a little quirky to learn in the beginning. Fortunately, there are some good tutorials on the net. For instance here.
SparkFun– for the cool button base thing, and not least a really nice service!
The same can be said of Modern Device, from which I got my first BBBs – the Bare Bones Board. It is a really excellent Arduino compatible board (with a nice price too)!I also based my “mainboard” on this one, well a little bit at least.
And in general lurking a bit around the arduino forum🙂
The filenames for the Arduino sketches are not really tidied up, they are what I use on my own computer.
Cubeduino Kicad files – also includes custom libraries and “modules”. Extract to a suitable directory (folder).
Cubeduino Rubik’s Revenge source code – it’s just one file, from before I splitted it in several files.
Cubeduino Color test code – This is the “mood lamp” / color test fork of the code. Extract to an Arduino sketch folder
Fixed the kicad files. I’m a linux noob, and I managed to gzip each and every file, before tar’ing them and gzip’ing once more😛 Anyway this is fixed now.
However, to use the custom libraries and parts, you will probably have to edit the preferences in each Kicad program (EEschema, CVpcb and PCBnew) to reflect where they are (libs and dirs). Unfortunately I’m not that proficient in Kicad yet, so I don’t know how to make this more streamlined (and still have my custom-made libraries in my home folder – I’m using Ubuntu Linux).
COPYRIGHT 2009, 2010 Ragnar Aronsen
Open source hardware under the Creative Commons Attribution-Share Alike 3.0 licence.
Software under the GNU GPLv3 license.
If, for some unfathomable reason, you should want to get in touch with me. Beware this address is not really checked too often, at least not all the time.
(Sorry for the anti-spam method. Also, I’ve been playing with GIMP🙂 )
Until next time,