Monthly Archives: February 2015

As a simple project, I decided this morning to tackle the six sided die project. That is a simple random number generator that displays its result on a six-sided die.

This picture shows the LEDs lit up to represent 5, but the lights are so bright in the pic it’s hard to distinguish.

A six sided die has seven possible pip positions, and an LED can represent each. Lit, it represents a pip, unlit it represents a space.

One might think the simple solution would be to control 7 LEDs individually, so that when you roll a 1, you turn on the center pip. Roll a two, turn on one in a corner and one in the opposite corner, individually, and so on.

However, when you think about how dice are marked, you really only need four output controls:

Because:

1 =

2 =

3 = and

4 = and

5 = and and

6 = and and

So any combination from 1 to 6 can be represented with just four states.

That means you only need four output pins on the Arduino. One is hooked up to just one LED, but the other three turn on TWO LEDs at the same time.

The rest is all in how you place the LEDs in space. I will 3D print a plate that puts the LEDs in the right places, and then solder the wires to control them appropriately.

The sketch, as Arduino code is called, follows:

It’s fairly straightforward. I assign numbers to variables for PinA, PinB, PinC, PinD (in case I should want to change those output pins quickly without having to change a bunch of code). Then I need a random seed, which generates pseudo random numbers each time random(x) is called. That seed creates a fixed sequence of seemingly random numbers. But with a constant seed, it will always pick the same random numbers in sequence. So I use an analogRead on a pin that has nothing attached to create the seed. This creates a more random sequence because the seed is different each time.

Then I tell the four pins I’m using to be OUTPUT pins. Serial.* allows me to write standard text output to a monitor so I can see what’s going on in there.

Then I simply pick a random number between 1 and 6 and then use that number to tell which pins to turn on (HIGH) and which to turn off (LOW).

// HERE INSERT CODE TO LOOP 20 TIMES, with A*time delay (so each delay is longer) calling random, then DICE(Number)
// This gives the impression the die is rolling random values until it stops picking the last one.

Obviously it wasn’t enough to just have the Arduino choose a random number and then go into an infinite loop so that resetting the Arduino would be the only way to choose another random number (or roll the die). Resetting the Arduino can take a few seconds.

So I coded in a loop that checks for a switch. The goal was that while the switch was on, random numbers would just keep rolling until you let go the switch, then the die would roll 20 more times, slowing down each time until it finally landed on the final random number. That would be the completed roll of the die.

I spent a lot of time playing with various input devices including a SPST push-button switch pressed into the breadboard, connected to an analog input. Weirdly, as I went to push the button, the die began rolling even before my finger got to the button. I pulled it away and the die rolled down to the final number. Approach again, and it would roll.

It seemed I had invented a proximity switch from a simple push-botton on/off switch.

Turns out the Ardunio’s analog inputs can sense static charge in the immediate area, and as my finger approached the switch, the analog input began to jitter, and my code detected that as ON and went for it.

I then hooked that switch up to a variably-lit LED and saw that as my finger approached, the LED would begin to brighten. When I was touching the switch it was the brightest.

Weird.

Anyway, I played with potentiometers, pressure switches, slide switches but found that when I moved the simple push-botton to a second breadboard, it acted more like an actual on/off switch.

Then my die rolled while the switch was pressed, until I let go, then it rolled down, slowing, to the final number.

But I noticed that, naturally, sometimes the same roll would appear on the die when rolling down. I didn’t want that to show up twice, since it would look like the die was stuttering. So I added code to check the current roll against the previous roll, and if they were the same, to skip displaying it. So now it may CHOOSE two of the same random numbers while rolling, it will just give the illusion that it did not. And since it’s all for show except for the last number, this does not decrease the randomness of the roll.

Later I hooked up a small speaker to an PWM (Pulse Width Modulated) output, and output the randomly-rolled number multiplied by some factor, and as each number is displayed, it beeps during the display at a tone that corresponds to that number.

So it makes really cool beeping noise now while rolling, and the slowing roll-down sounds awesome, as the audio really sells the slowing of the die roll.

Man, now I have to move this all over to the Arduino Micro (because I want to make a housing for this die on my 3D printer).

This presents a few challenges: Powering the Micro means making a battery connect to a USB Micro jack (which is what powers the Arduino Micro) and I also need to get a light-detector working, because I’m going to be swapping out the push-button switch with a light detecting resistor on the bottom of the housing. That way, whenever you pick it up, it will roll, until you put it down, then it will roll down to the final number.

A few years ago, along about the time I was investigating 3D printing through, mainly, MAKE Magazine, I found that there was this rather fast-growing phenomenon surrounding a small electronic circuitboard called the Arduino.

I was interested, of course, and read a few articles which often showed some rather advanced projects, and I thought, “That looks cool, but that’s far too advanced for me.”

But I kept reading and watching what was happening, and when Radio Shack started selling Arduinos in cool kits with bunches of LEDs, sensors and other electronics, I figured I should investigate further – perhaps even get one.

But I didn’t really understand what was going on.

But like I was when I got my first computer, the Commodore 64, I was sure I could learn it and make some cool projects.

Recently I bought an Arduino, a Raspberry Pi (another circuitboard, but this one is a fully networked small computer, including USB ports, an HDMI port, and ran Linux) and an Arduino Micro, which is a smaller version of the Arduino.

But what exactly is an Arduino? Not much of what I read told me what I wanted to know. Most of the articles I read assume some knowledge of the Arduino.

One interesting fact: It was invented in Italy by two men and named after a bar they liked. That’s when I realized the name was familiar.

This poster has been hanging in my kitchen for nearly a decade. We bought it because it hangs in what used to be our favorite cafe in Norwood, MA. Here is that poster:

So maybe it was destiny that I get bitten by the Arduino bug…

It turns out my initial understanding of the Arduino wasn’t far off – it is basically a computer on a chip that controls various input and output channels, and understands computer code. So if, for example, I want to turn an LED on whenever I push a button, I could simply wire a circuit up to a battery (which is a heck of a lot cheaper) or I could use my Arduino to wire up a switch, and whenever that switch turns on, have my code (which is fed to the Arduino through your computer connected by USB cable) turn the LED on. By hooking the switch up to an input pin, I can detect it, then when it turns on, use an output pin to turn on an LED.

My Arduino is the Uno, but I also bought a Micro, which is a very small version with most of the same functions.

(Shown here larger than actual size)

What it is, essentially, is a series of ports directly controllable through computer code uploaded to the board’s internal memory and run like a portable computer. Each pin hole does something useful and you can mix and match those to make rather complex projects.

It is so much more than that, though. With a potentiometer (variable resister, like a volume knob on a radio) I can read an analog signal, which converts to a number, and then I can feed that number out to an LED on an analog output pin and voila – the LED gets brighter as I turn the knob. Again, something most people could do with simple circuitry.

But because the Arduino understands computer code, I can do so much more. I can, if I want, use that potentiometer, and have an LED readout give the NUMBER the potentiometer is reading, through an LED display, or a row of LEDs like a bar graph – whatever my computer code can tell the output pins to do.

Suddenly the possibilities become exciting!

Over the last few days I have played with my Arduino just a bit, and got some interesting first findings, including how to blink or fade an LED (or multiple LEDs at different rates) using the various analog output pins. I also found several sensors that worked, like a pressure sensor (that turns on when you touch it) and others. I have so much more to learn.

But I intend to document some of that learning here.

I’ll start with my first project idea: A simple dice rolling program that displays its number in a way similar to how a 6 sided die works, with 3 LEDs down either side and a single LED in the middle.

Last year it was announced that WETA, who made all of the awesome designs for the Lord of the Rings and Hobbit movies, among other accomplishments, would be reviving the iconic TV series Thunderbirds, created by Gerry and Sylvia Anderson in 1964. The new series is going to be named after the first of two feature films the couple also made back in the day: Thunderbirds Are Go.

The first big teaser image from the show is the CGI model of the updated Thunderbird 1, seen here:

It was soon followed by this image, almost the same, of Thunderbird 1 (TB1) flying inverted over the Hollywood sign:

So I set out to model this and 3D print it using my Afinia H479 printer. (And my Afinia H480.)

Luckily, WETA has been touring around the toy and merchandising conventions with a large 10 foot physical model of the ship too, and some photos gave me more information about shape and proportion, as well as detail.

And of further help, a friend of mine, Barry Kay, took some very nice high-rez close-up detail shots from various angles all around the model, which I used to work out a lot of the detail. (I may post those later.)

The Parts

Here is a photo of all of the parts that make up this model. Note that there are 98 individual parts, including a display stand.

The Main Body

The main body tube is made up of five separate parts. These parts comprise the main tube in silver, and two stripes in black mid-body.

Here, the top section has two underjets, and cutouts for the cockpit windows and body text which will inlay as white pieces.

Here the side text is inlaid, so that the TB1 reads upright from either side of the body (only one side shown here.)

Then the topside of the body, which has the word THUNDERBIRD going down its entire length, is inserted, or at least the first few letters that are printed on this top section.

Then I do the same for the bottom body tube section:

Next I attach the five main section pieces including the sandwiched black/silver/black rings, which leaves a hole for the letter D:

The Engine Section

The blue section of the body, if you look closely, is honeycombed with hexagons. This was the most difficult part of this model to make, but it was oh-so-satisfying when it printed so nicely. I cut the large number 1 from it and made that an inlaid piece, but with the honeycombing intact.

Here is an image someone posted of a texture used on this part of the body:

Here, I attach the large dark part, which looks like a heat sink, to the blue section. Note the detail on the bottom. This was not in any of the photos or CGI images I have seen.

I got the detail from a rough GIF file someone posted of a turntable rendering of the ship that was on display on monitors next to the physical models at the conventions:

I snapped two frames of this GIF as it rotated and used them side-by-side to create a 3D parallax image (like a ViewMaster slide) and while the video has serious GIF dithering, I was able to make out some detail in depth, so I modeled in what I could see.

Next come the thruster housings for the 8 jet engines. Each housing has TB or TB1 (depending on which one) inlaid in, and two jet engines attached:

Here are the four housings:

I had a conflict here. While the rotating turntable image (posted above) clearly shows the TB1 as upright on the upper and lower housings, so when the ship is landed flat it reads correctly, the physical model my friend photographed showed the TB1 as reading upright relative to the body, so I decided to go with the physical model for now.

(To make that a changeable thing, I opted not to glue the bottom thruster housing in place. It snaps in rather well, so it holds. Later, I will reprint that one with the TB1 facing the way it faces on the CGI model.)

Then I added the blue jet intakes to the tops of each thruster housing:

Then I added the housings to the heat sink section:

Next I added the fins

Then the flare section that connects the engine section with the body section, adding the silver pins to the tops of the thruster intakes. (Note the display stand, which is not canon. I just made it interesting.)

I then joined the two body sections together.

Next are the main engine intakes, each made from 3 pieces:

These get attached next to the slots where the wings would retract:

Last Bits

Then I prepared the wings, which have tabs that fit into slots in the body shoulders.

And here they are, slotted in place.

(In a future version of this model, these wings will actually scissor out on gears, so they can retract, like they do on the show. But for now this will do. The wings on this model are static. Making them do what I hope to do later will be quite a complicated job, but one I hope to take on later this year.)

Almost the last part is the nose-cone:

The very first image showing all of the parts has the window inlays printed in black. While I was assembling this model, I got a shipment with some glow-in-the-dark sky blue filament from Zen Toolworks, and I printed the windows again in that color to see if it worked better than black.

I also used a sample Zen sent me of translucent filament and tried that.

The winner was blue:

So there you have it. My version of WETA’s Thunderbird 1 from Thunderbirds Are Go.

Here it is on display:

Still missing: The Pitot tube which juts from the cockpit area, and some other body detailing, which I hope to add when I make the retractable-wing version later.