Sunday, September 22, 2013

Remote Controlled EV3 Lego Excavator 42006

Remote Controlled Excavator

I got the LEGO Excavator a few months ago but the controls on it were way too difficult for my kids to use.  Heck I had a hard time remembering what combination the three switches had to be in to make it open/close the claw or raise/lower the arm.  I found some videos on youtube where people used a lot of power functions gear to make their excavators remote controllable.  The way they did it was cool but I don't own tons of power functions parts so I decided to make mine remote controllable by combining it with my EV3.

The hardest part was figuring out how to control six movements with only four motors. I built a motor multiplexer that uses two motors to control four movements.  This is used to control the claw, arm, rotating the platform,etc.   I used the other two motors to control the tracks.

It is a big hit with my kids :)


  • LDD Instructions - I didn't include instructions for the arm/boom since they are the exact same as the standard 42006.  When you build it turn the mux so that it is engaging the gear at the top.
  • EV3 Software - There is a program called RunFirst that you need to run one time when you first build the excavator.  This program creates a text file that is used to remember where the multiplexer is located.  This way if you turn the EV3 off and turn it back on, we know which gear is currently engaged by the mux.

Tuesday, September 10, 2013

Lego Technic Two Input, Four Output Motor Multiplexers

Motor Multiplexers

I bought the Lego Excavator 42006 a few months ago (for the kids of course) along with the power functions add-on so you could motorize moving the boom up & down along with opening and closing the claw.  The controls are pretty bad though, there are three switches that you have to toggle in just the right combination to get the movement that you want.  It takes me several tries to find the combo I'm looking for, for my 4-year old it is really frustrating.

I also got an EV3 kit recently so I've been working on combining the two so that I end up with a remote-controlled excavator.  I figure that will be much more enjoyable for the kiddos.  The challenge is the EV3 brick only supports 4 motors but I need to be able to control six movements on the excavator.

  • Opening and closing the claw
  • Moving the boom up and down
  • Moving the boom in  and out
  • Rotating the entire platform clockwise and counter clockwise
  • Moving the left track forward and backwards
  • Moving the right track forward and backwards
I need to run both tracks at once in order to move forwards, backwards and steer so that leaves me two motors to control the claw, boom up/down, boom in/out and platform rotation.  I started working on a hardware based motor multiplexer that would let me control four functions from two motors.  

It took me a few iterations to get something compact enough to fit in the excavator.  The turntable mux at the beginning of this video is the one I'm using for the Excavator.  The other two work, they were just too bulky.  The two at the end are a little different in that they will let you enable two outputs at once unlike the turntable mux which only enables one output at a time. Someone else may find them useful though so I included them in the video.

I'm still working on the Excavator but it shouldn't be much longer now that I have the mux figured out.

Build Instructions

Here are the LDD (LEGO Digital Designer) files:

Friday, August 23, 2013

LED Photo Drawing Robot

LED Photo Drawing Robot

A few years ago on a camping trip my friends and I started playing around with drawing shapes with our headlamp while someone else took a 30-second exposure with the camera.  I drew Pac-Man chasing a ghost and it came out fairly well for blindly waving a flashlight around in the dark.

I thought it might be cool to build a robot that could draw a picture like this.  I built a robot that moves a LED around a grid and then turns on the LED to the desired color at each location on the grid.  I used my DLSR to take a very long exposure while the robot is moving the LED around the grid.   The end result is a photo of the LED at all of the various points in the grid which (hopefully) looks like the image the robot is trying to reproduce.

LED Photos


Given the photo that gave me the idea for the robot I had to try a Pac-Man image first.  This was a nice photo to start out with because there was a lot of black in it so it only took the robot about 10 minutes to draw it.  That made it nice for troubleshooting because I only had to wait 10 minutes to see if it worked.

The Starry Night

Next on the list was The Starry Night.  This was a big jump in complexity over the pac-man photo.  It took me a few attempts to get all of the kinks worked out.  There aren't many all black pixels in this one so it took about 30 minutes to complete.   It is a long shot from a perfect replica but at least you can tell what it is :)

Lego Mona Lisa

I stumbled across this image and it seemed too fitting for this project :)

In Action

How It Works


The color sensor from lego can also produce light of various colors but it is pretty limited.  You can only tell it basic colors like "red", "green", "yellow", etc.  I needed a way to produce a larger range of colors so I bought a dLight from Dexter Industries.  It comes with four LEDs but I only ended up using one of them.  Most of the time you see these used in robot cars so people can add turn signals and/or headlights.

The LED was a little bright though so I punched a small hole in a piece of black construction paper and taped that over the LED.  That gave me a smaller light source which meant that I could squeeze in more pixels.

Robot Hardware

I needed the position of the LED to be very accurate so that I could draw the right color pixel in the exact spot where I needed it.  I've tried doing super accurate movements like this before with a robot that drives around on rubber wheels but at some point the wheels always slip a little and that throws everything off.  To get the accuracy I needed I built a platform with two rows of gear-racks on top.  The LED sits on top of a motor which has gears for wheels, these gear wheels drive along the gear racks.  This is how the LED moves up and down.

Getting the left to right movement was a little trickier.  I put wheels at the ends of my "up/down" platform and attached a long arm of beams to the platform.  I put gear-racks on top of the really long arm and used a 2nd motor to turn a gear that joined with those gear racks.  This gave me a way to slide the "up/down" platform left and right.

Robot Software

I wrote small program in PERL reads an image file and gets the color for each pixel in the image.  This ends up being information like "Pixel 10x50 has Red=57, Green=140, Blue=200".  I just printed all the information about what color each pixel should be into a simple text file.   I then copied that text file over to the robot where the robot would read the text file to learn how much Red, Green, and Blue for the LED to output at each location.  Then you just have it move to every location listed in the text file and tune the LED to the correct color.

Tuesday, August 20, 2013

Lego Technic iPhone Tripod

The Motivation

I downloaded the LEGO Movie Maker app for my iPhone a few days ago so my daughter could try her hand at making stop motion videos.  It is really easy to use, it only took a few minutes and my 6-year old was reenacting Luke rescuing Leia from the Death Star.  My daughter couldn't hold the phone in the same spot though so the movie ended up being a mix of Star Wars and The Blair Witch Project.  I didn't get green watching it but that is only because it was about 4 seconds long.  It was still really cool to see her make a movie on her own though :)

The Tripod

Anyway, we didn't have a tripod for an iPhone so I started building one out of technic parts.  The only parts I used that were not from my Mindstorms kit were the three technic turntables.  These cost about $1.50 each on ebay so the entire thing is probably $7 or $8 in parts.

There are two turntables on the sides so that you can tilt the phone forwards and backwards.  There is another turntable underneath that lets the phone twist left and right.

And yes I know that this isn't technically a tripod but I figure "iphone tripod" is probably googled about a billion times more often than "iphone bipod" :)

Parts List

QTY: 1

QTY: 8

QTY: 2

QTY: 4

QTY: 2

QTY: 4

QTY: 4

QTY: 46

QTY: 2

QTY: 2

QTY: 4

QTY: 2

QTY: 8

QTY: 1

QTY: 4

QTY: 4

QTY: 3


I used LEGO Digital Designer to create the build instructions that are in the video.  If you don't feel like pausing the video every 5 seconds you can download the LDD file for the tripod here

Saturday, March 9, 2013

Build Instructions for Drop7 Robot


I tried out the Lego Digital Designer software to create some build instructions for the Drop7 robot. It was very easy to use and works really well.  If only the NXT-G software were as solid as the LDD software :)

Here is a zip file with the .lxf file that you view in Lego Digital Designer.  LDD wouldn't let me attach the gear racks and it wouldn't let me attach the sliding platform to the track.  Other than that the instructions should be accurate.


Here is the BricxCC code that tells the robot which way to move and how long to pause after touching the iPad.

task main() {
   // This sequence will get you to the x29 chain at the end of Level 2.
   unsigned char column_drop[] = {1,3,3,2,3,5,5,6,3,7,6,5,4,2,3,1,7,4,1,6,5,2,7,1,2,3,2,3,2,4,6,6,3,2,4,3,1,4,3,7,4,5,5,6,6,3,1,5,2,3,2,7,2,7,5,3,7,5,6};
   unsigned int column_delay[] = {1600,1600,1600,0,0,1000,0,0,0,0,0,0,17600,0,0,0,0,0,0,0,3200,0,18500,4100,0,0,0,0,0,2500,1000,0,0,0,0,1600,1600,0,0,0,0,1000,1600,1000,0,1600,1600,0,0,0,1600,0,0,1600,0,0,0,1600};

   unsigned int i;
   unsigned char prev_column = 4;
   unsigned char curr_column = 0;
   unsigned int degrees = 0;

   for (int i = 0; i < ArrayLen(column_drop); i++) {
     curr_column = column_drop[i];
     degrees = 0;

     TextOut(0, LCD_LINE1, "DROP: ", true);
     NumOut(50, LCD_LINE1, curr_column);

     if (prev_column) {
        if (curr_column > prev_column) {
           degrees = (curr_column - prev_column) * 120;
           TextOut(0, LCD_LINE2, "RIGHT: ");
           NumOut(50, LCD_LINE2, curr_column - prev_column);
           TextOut(0, LCD_LINE3, "DELAY: ");
           NumOut(50, LCD_LINE3, column_delay[i]);
           RotateMotor(OUT_B, -50, degrees);

        } else if (curr_column < prev_column) {
           degrees = (prev_column - curr_column) * 120;
           TextOut(0, LCD_LINE2, "LEFT: ");
           NumOut(50, LCD_LINE2, prev_column - curr_column);
           TextOut(0, LCD_LINE3, "DELAY: ");
           NumOut(50, LCD_LINE3, column_delay[i]);
           RotateMotor(OUT_B, 50, degrees);
        } else {
           // Same nothing

      // Touch the iPad, (motor, power, degrees)
      RotateMotorEx(OUT_C, 40, 25, 0, 0, 1);
      RotateMotorEx(OUT_C, 20, -25, 0, 0, 1);

      if (column_delay[i]) {
      prev_column = curr_column;

Friday, March 8, 2013

Drop7 with Lego Mindstorms NXT

I posted a video on youtube of a Lego Mindstorms NXT robot of mine, playing Drop7 in sequence mode to a score of 5,205,955.  Some of my friends told me I should blog about it to explain how I did it, so here is a rather lengthy explanation of everything that went into the video.  The robot plays to the end of Level 71, it clears the board 23 times, the longest chain is x29 and is worth 367,087 points. There are also chains of x26, x25, x24, two x23s, two x22s, etc, etc.

The Inspiration

I started playing Drop7 on my phone a few months ago and eventually stumbled across a video of someone who scored 5,000,000 points on Drop7 in sequence mode.  For those of you that have never played Drop7 is it sort of like a math based version of Tetris.  You have a 7x7 grid where you select which column to drop a disc in.  You earn points by making discs explode, preferably in a long chain which earns more points. Making a disc explode is easy, if you place a disc with a 4 in a column with 4 discs, all of the 4s in that column explode.  The same rule apples to having 4 discs in a row, when that happens all of the 4s in the row explode.

Anyway, I started thinking about how the person that made the video figured out what sequence to play the discs in to get such a high score.  They were playing in sequence mode which means that the same discs are played every time you play the game.  I was sure they wrote a program to figure out how to get such a high score and I like to do geeky little projects so I wrote my own program that simulates Drop7.   I figured I would have it run through a few million permutations that one could play the discs in and see which permutation produced the highest score.


Just how many permutations can the discs be played in? Let's say you only know what the first four discs will be in sequence mode. There are 7 different columns you can drop each disc in so the permutations will be as follows (the numbers represent which column to place a disc in):
#11 1 1 1
#21 1 1 2
#31 1 1 3
. . . .
#23997 7 7 5
#24007 7 7 6
#24017 7 7 7

This comes out to 7^4 or 2401 permutations. OK 2401 isn't such a huge number for a computer but let's expand this and assume you know what the first 100 discs are in sequence mode.  7^100 is  a GIGANTIC number of permutations,  3.2344765096247579913446477691002e+84 to be exact.  That number is so huge it is hard to wrap your head around it. To put it in perspective if you stacked up 3.2344765096247579913446477691002e+84 sheets of printer paper the stack of paper would be about 3.29 light years tall! Needless to say I don't have access to enough computing power to crunch through that many permutations of Drop7 within the next few billion years.

I decided to break the first 100 discs down into groups of 8. I could run through every permutation that one could play the first 8 discs in, find the permutation that resulted in the best score and then move on to the next batch of 8 discs, etc. This wouldn't give the absolute best possible score one could get out of the first 100 discs but it would spit out a sequence to play the discs in that would produce a very high score.

Drop7 Simulator

At this point the little simulator program I wrote was in a language called PERL which is an easy language to program with but is slow compared to a complied language like C. It took my PERL program quite a while (days) to crunch through the first 100 discs in groups of 8 so I rewrote my simulator in C which is much much faster, in this case the C version was 74x faster than the PERL version!!  I then moved from analyzing the discs in groups of 8 to groups of 12.

I was doing all of this on my home PC which has four 2.8Ghz cores.  Crunching through the discs in groups of 12 took a long time, each group of 12 was 13.8 billion permutations (7^12) to simulate.  I knew I wouldn't be able to do move up to groups of 13 on my home machine, not unless I was willing to let it run for months.  The larger the groups of discs you analyze the higher scoring sequences the program is able to find so I wanted to move from 12 to 13 if not higher.  I was chatting about this little project with a co-worker and he gave me access to one of his machines at work that has 32 cores.  It is a Linux machine running on a Cisco UCS B200-M3 to be exact.  It isn't often that one maxes out 32 cores for days on is a screen capture that shows them all pegged at 100% :)

In the end I was able to crunch through the discs in groups of 14, each group of 14 has 678 billion permutations.  I knew what the first 680 discs were in sequence mode which means there were ~49 groups of 14 discs to analyze.  So 678 billion permutations per group x 49 groups x 14 discs per group = 465 TRILLION discs were "dropped" in my Drop7 simulator.  Even with 32 cores running 24 hours a day it took weeks for it to produce the sequence I used for the video.

I posted all of my code for the Drop7 simulator on github.  If anyone wants to tweak it to find a better Drop7 algorithm you have my permission to use my code.

Sequence Mode Discs

I found a post on a forum somewhere that listed all of the discs that would come in sequence mode for the first 10 levels.  To figure out the future disc beyond level 10 I would play to level 10, then record a video of myself playing, then watch the video to figure out what the new discs were.  The only problem with this approach was that I had to keep playing from the beginning of the game up to Level 10, or 11, or whatever level I was stuck on at the time, in order to figure out what the next discs were.  This was taking a while and either my wife or I jokingly said that we should build a Lego robot to play it for us.  I'll go into the robot more in second but here is a table of all discs (a disc with a "?" means it is a solid disc) for the first 71 levels of sequence mode.  Should someone else ever decide to do a project like this they shouldn't have to analyze game film of themselves playing Drop7....that part was pretty boring.

LvlLevel Up DiscsOne-By-One Discs


You get 7,000 points for each level and 70,000 points every time you clear the grid. You also get points when discs explode but the number of points depends on the "chain" length of your explosions.  The formula for determining the value of a chain explosion is 7*n^2.5 where 'n' is the chain length.

Here is a table that shows the value of a disc for a given chain length along with the total score for that chain...assuming only one disc exploded at each level of the chain. The longest chain I have been able to find is x29.

Disc ScoreTotal Score

The Robot

I should be clear here that the robot I built doesn't make any decisions on its own about where to play the disc, the robot can't see the screen and therefore can't play the game by itself.  My Drop7 simulator figured out what sequence to play the discs in to achieve a high score, I just programmed the robot to touch the screen in a specific pattern so that the discs would be played in that sequence.

The Stylus

One tricky part of this project was figuring out how to get the robot to touch the screen in a way that would register with the iPad.  iPad screens aren't pressure sensitive, they are capacitive screens so you can't just stick a stylus in a robot's hand and have it work.  I tried grounding a stylus but that didn't work either.  After a bit of googling I found where some people had used frozen sausages as a stylus and that made me wonder if that would work for a robot since it is made of flesh like your finger.  I was all out of those little breakfast sausages but I did have some hot dogs in the fridge so I gave one of those a try and BINGO!

Now there are a few downsides here
  • Hot dogs touch a large part of the screen at once compared to a normal stylus
  • Hot dogs dry out and the touch doesn't always register
  • Your iPad smells like a hot dog at the end of the day
  • If you think little kid fingers can make your iPad screen disgusting, try touching it with a hot dog a few hundred times.
I eventually figured out that when I had tried grounding a regular stylus I wasn't grounding it properly and that is why it didn't work.  You have to take the little rubber tip off the end of the stylus, wrap some wire around the metal there, then put the rubber tip back on.  Ground the wire and that should do the trick.


I went through a few different styles of robots before settling on the one used in the video.  My original robot is the one you see in the hot dog photo.  It had problems consistently dropping discs in column 1 and column 7 though because the angle was so narrow by the time the motor moved the stylus that far to one side.

Next I tried building a little rover that would drive forward and backwards to the appropriate column.  This wasn't accurate enough though because if the wheels slipped at all it would end up dropping the disc on the wrong column.

I decided I needed a platform that moved on a track so I could get the stylus exactly over the middle of a Drop7 column.  I'll post some instructions later on how to build the robot.  The only parts I used that did not come with the Lego Mindstorms kit were the gear racks.  These were used to move the platform from side to side.

Here you can see the gear racks underneath the platform.  A motor turns a gear which moves the gear rack which in turn slides the platform to the left or right on the track depending on which way I tell the motor to turn.  Once the platform is centered over the right column, the motor on top of the platform turns a few degrees to touch the screen with the stylus then reverses direction to pick the stylus up.


I am completely new to the world of Lego Mindstorms but I have to say it is amazing they are as popular as they are given how horrific the NXT-G software is that Lego provides.  It is slow as Christmas, it locks up, it crashes, things that once worked randomly stop working, etc.  Needless to say I didn't use it for very long until I started googling for an alternative.  I settled on BricxCC which allows you to program Lego Mindstorm in NXC "Not eXactly C".  If you have any programming experience at all I would say go with BricxCC over NXT-G, it will save you a lot of frustration.

My BricxCC code for this project is also on github.

The End

This was a lot of fun. I hadn't written a line of C in 6 years and had never used Lego Mindstorms so I learned a lot via this little project :)

Tuesday, February 26, 2013

I like to do random tech projects and some friends convinced me that I should blog about a lego mindstorms project that I've been working on lately.  I'm still working on the mindstorms project but wanted to go ahead and start a blog as a placeholder.  More to come later...