Lego PF Hacking – Wiring the Arduino

PowerFunctions_Logo

Lego Power Functions Hacking Guide –  Part 4 – Wiring the Arduino
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wire Hacking
Part 4 – Wiring the Arduino
Part 5 – Programming (coming soon)

The saga continues! Bust out the breadboard because its time to make use of those Power Functions wires we just defiled with our wire cutters.

Breadboard Schematic

Breadboard layout for connecting our lego motor and battery box

Breadboard layout for connecting our lego motor and Arduino to our motor driver

The above picture shows roughly what our breadboard will look like after we connect our Arduino and Lego parts to our DRV8833 motor driver. I included the reference schematic from Pololu in the upper right hand corner so you can see which pins we are connecting too. If you missed the link from the equipment post you can find the Pololu product page HERE

Layout Description and Explanation
I’ll provide a quick overview before I move on to a detailed list of our connections. The central focus of our circuit is the DRV8833 motor driver in the middle of the breadboard. It is what converts our low power signals from the Arduino to the high power outputs that a motor needs to run. Two lines are used from the Arduino to drive the motor (essentially one for each direction) and the Lego motor is tied to the corresponding motor output. The Arduino power is used for the logic side of the driver and the lego battery box is used to power the motor side.

Detailed Connection List:
1) Arduino Power
The 5V and Gnd from the Arduino are wired to the upper power rails of the bread board. This power rail is now the “Logic Power” for our circuit. Logic ground is tied in to the motor driver ground pin. (When two separate power supplies are used, as is often the case with motor applications, the grounds of the power supplies need to be tied together for them to interact. The motor driver does this for us)

2) Arduino Control Signals
To drive a motor you need two control signals. Each control signal ties to one of the motor wires (C1 and C2 in our case). For our control signal connections we need Arduino pins that are capable of PWM output so we can control motor speed. For this circuit I chose pins 6 and 9, both are PWM enabled. These lines will tie in to our AIN1 and AIN2 pins on the motor driver. (The motor driver can control two motors, we’re only using one so we will use the ‘A’ pins)

3) Motor Power
Motors require a higher amount of power than control circuits can handle so its good to use a separate motor power supply to drive them. In our case we are going to use the standard lego battery box and one of our hacked Power Functions wires we made in the previous PF Hacking post. Attach the Lego block end to the battery box. The hacked end we will connect to the breadboards lower power rail. Tie the 9V line to the red rail and the Gnd line to the black rail. The C1 and C2 wires are not used and can be taped off with electrical tape. BE CAREFUL THAT C1 and C2 DO NOT TOUCH. They will short out if power is turned on and they are touching. This is why either electrical tape or simply cutting them off is important. (PHOTO COMING SOON)

4) Lego Motor
Time to use that last hacked wire. Attach the lego block end of the wire to the lego block connector of your motor. At the other end, attach wire C1 to AOUT1 on the driver and wire C2 to AOUT2. Use electrical tape on the unwired 9V and Gnd lines from our hacked cable.
(PHOTO COMING SOON)

5) Capacitors (optional)
With motor applications its always helpful to add capacitors to the the power rails to help protect against spikes and dips that can occur when a motor is first started. Standard 10uF capacitors work great. These are optional but helpful and recommended.

Putting it all together

When you are done you should have something that looks a lot like the picture below. Once that is done its time to move on to the final steps of programming our Arduino! Stay tuned for the final post in the Lego Power Functions Hacking series where we get it all running and moving!

(Photo and Video of final circuit coming soon)

Advertisements

Lego PF Hacking – Wire Hacking

PowerFunctions_Logo

Lego Power Functions Hacking Guide –  Part 3 – Wire Hacking
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring Hacking
Part 4 – Wiring Arduino (coming soon)

Its time to hack! Break out the wire cutters and soldering irons cause its about to get real.

Step 1 – Grab your LEGO PF extension cables
The first thing we will need to do is prepare our extension cables so that one end can be hooked up to our legos and the other can go in to a breadboard for attachment to Arduino and motor controller.

LEGO PF Extension Wires

LEGO PF Extension Wires – Top wire is hacked, bottom is a normal wire before hacking

As you can see in the picture above the extension wires have two different colored heads on them, one light grey and one dark grey. We’re going to cut off the light grey end as close as possible to the plastic head to leave as much wire as we can. (Side note: the underside of the light grey end converts PF to old Mindstorms motors which is why we are cutting off that end). The goal is to achieve what you see with the top wire in the picture. A LEGO connector on one end and bare wires on the other.

Step 2 – Cut and Strip the wires
As mentioned above, take your extension cable and cut light grey end off as close to the plastic as possible. You should come out with the four wires that make up the cable all stuck together by their insulation. Now we need to prep the wires for use with a bread board

Separate then strip each wire

Separate then strip each wire

The first thing is to separate each of the four wires from each other using a razor or utility knife to cut the areas between each wire’s insulation. The insulation is thin so you have to be careful to stay straight and not bite in to a wire. I find this easiest by laying the blade edge flush with the area to be cut and then pushing straight down to do the cut all at once.

Next you need to strip the separated wires of their insulation. I used a wire stripper that can do 22 gauge stranded wire (20 gauge solid). I highly recommend a wire stripper as seen in the picture as the wire is very small and stranded which makes it easy to cut off strands when doing it with a razor blade.

Step 3 – Tin the wires and do it again for a second cable!
The final step is to tin the wire ends. This means to use a soldering iron to apply a small amount of solder to the end and bind the strands all together. This makes is much much easier to insert the wires in to a solder-less breadboard for use with the Arduino. You should end up with an end that looks something like the picture below. For help with Tinning do a search on youtube as there are many examples. We will need two of these cables so make sure you complete a wire in the exact same way.

Wires tinned and ready for use!

Wires tinned and ready for use!


Step 4 – Know your wires!

Congratulations! You have two wires hacked and ready to go (hopefully). Now we need to learn a little something about what each of the four wires does. In the picture below I have labeled each of the four wires from the top view of the cable (Lego nubs facing up on the connector)

Power Functions cable showing the use of each wire

Power Functions cable showing the use of each wire

Power Functions Wires:

  • GND – ground wire – Always connected (0V regardless of battery pack direction)
  • C1 – control wire 1 – 9V when battery pack is forward, 0V when in reverse
  • C2 – control wire 2 – 0V when battery pack is forward, 9V when in reverse
  • 9V – power wire – On when battery pack is on (9V regardless of pack direction)

The two outside wires are our power and ground. Anytime a LEGO battery pack is connected and turned on these wires will be the same and do not change polarity. The two inside wires are the motor control wires that power the motors themselves. When a battery pack has its direction switch changed it reverses the polarity of these two. When C1 is high and C2 is low the motors rotates forwards. When C1 is low and C2 is high the motor rotates backwards. If you have a PF infrared speed controller in your system the speed controller applies a PWM signal to C1 or C2 to regulate the speed.

Step 5 – Our design
What we are going to do is use one of our cables to draw power from the LEGO battery pack via the outside two wires and then use our second cable with the inside two wires to attach the PF motor to our motor controller. Stay tuned for how to wire this up with the Arduino!

Guide Table of Contents
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring Hacking
Part 4 – Wiring Arduino (coming soon)

Lego PF Hacking – Equipment

PowerFunctions_Logo

Lego Power Functions Hacking Guide –  Part 2 – Equipment
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring (Coming Soon)

Welcome to Part 1 of my Lego Power Functions hacking guide! For those who skipped the intro post I’m demonstrating how to hack Lego Power Functions  (part of Lego Technic) for control with your own microcontroller. In this guide I will be using the Arduino Uno to control our Legos.

To get started I’m going to go over the things we will need as a part of this guide:

Equipment


Equipment Shown:
1) Lego Power Functions Medium Motor
2) Lego Power Functions 9V Battery Box
3) Lego Power Functions Extension Cable (8″ or 20″)
4) Lego Technic Axel (optional)
5) Arduino Uno
6) Arduino CC3000 Wifi Shield (optional)
7) Breadboard jumper wires
8) Dual Motor Driver (DRV8833, can be others)
9) LED and 330 Ohm Resistor

1) Lego Power Function Motor

This is the standard Lego motor with four wire connection. It can be purchased as part of a kit (Link) or separately (Link). The Large and XL motor options also work.

2) Lego Power Functions 9V Battery Box

This is one of two Power Functions battery boxes. Both work just fine. This one comes in the Power Functions kit linked above with the motor or can also be had separately. (Link)

3) Lego PF Extension Cable

These cables are what we are going to hack to connect to the Arduino. This lets us keep the motor in tact for standard Lego builds. These cables were originally designed to convert from older Mindstorms connectors to the new PF connectors. We’ll be cutting of the Mindstorms end. You can find them here: 8″ (Link) and 20″ (Link)

4) Lego Technic Axel and Gear (optional)

Things are always more fun when they do stuff right? If you have some Lego Technic sets lying around go ahead and build something that moves in fun ways and connect it to the motor.

5) Arduino Uno and Solderless Breadboard

The brains of the operation. The Arduino Uno is one of the most common microcontroller boards for hobbyists worldwide. There are vasts amount of documentation and examples available all over the internet so you should have an easy time getting started if you haven’t used one before. The Arduino Uno and a solderless breadboard for wiring can be found at your local Radio Shack or also available online from Adafruit. Both have started kits available that include extra components to help you get started if you’re new to circuits.

6) Adafruit CC3000 Wifi Shield (optional)

Arduinos use add-on boards called “shields” to add functionality to them. As an optional addition to this guide series I’ll show how to add Wifi to your Arduino using this shield so your lego robots can be controlled from a computer! The shield can be found here (Link)

7) Wire Jumpers

To wire components together on a breadboard its always helpful to have jumper wires. A set of these is each included in the starter packs from Radio Shack or Adafruit. You can also cut and strip the ends of your own 22 gauge wire to make some cheaply.

8) Motor Driver – DRV8833

To control a motor you need large amounts of power, more than a microcontroller can handle. We use special motor driver chips to handle the motor current that can be controlled by a signal from the Arduino. There are numerous motor control shields available for the Arduino but I like using external drivers since they can connect to any microcontroller out there. This is a board from Pololu and can be found here (Link)

9) LED and 330 Ohm Resistor (optional)

I always add an LED to my projects just for status information. There is also an LED built in to the Arduino that can be used if it is not covered up by a shield.

10) Soldering Iron!

What hobby workspace wouldn’t be complete without a soldering iron? You’ll need one to tin some wires and attach the pins to many Arduino shields. I won’t be getting in to a soldering tutorial but youtube is your friend. My best advice is don’t completely cheap out on a soldering iron if you can help it. A variable temp iron from Weller or Hakko is a great choice. Both Adafruit and Radio Shack will have these.

Moving On!
Got it all? Ok, shopping list done! Time to move on to what most people are interested in and that is how to hack the Power Functions wires to connect them to our own circuits. Stay tuned as that’s coming up in the next part of the series!

Lego Power Functions Hacking Guide (Contents)
Part 1 – Introduction
Part 2 – Equipment
Part 3 – Wiring (Coming Soon)

Lego Power Functions Hacking – Intro

PowerFunctions_Logo

Hacking LEGOS! Seriously, who doesn’t like Legos?

One of my current problems is how to get more people interested in microcontroller programming and robotics. Microcontrollers are cheap through the likes of the Arduino but until you attach cool things to them they are quite boring left alone. But how do you start someone going when the things you attach are complicated and often expensive… LEGOS! Few are the households that don’t have access to standard Legos. Add to that a Lego Power Functions motor and gear kit which can be had for as cheap as $10 on ebay and you’re up and running!

I’ve started a project to hack Lego motors for easy attachment to an Arduino. The benefits of this are two fold:

  1. Ease and Low Cost of Lego robot platform building
  2. Massive Arduino code library and documentation availability from all over the internet

My goal is to create a project anyone with Legos and an Arduino could put together to use as a robotics platform. My plan is to start with simple motor control and move on to more advance control.

Here are a few of my possible plans:

  • Wire project with no destruction of Lego motors or attached cables. (Hacking extension cables for Arduino connection)
  • Basic Motor Speed Control using Arduino and cheap motor driver from Pololu.com
  • Remote control over Arduino serial terminal
  • Remote control over WiFi using CC3000 Wifi shield for Arduino from Adafruit
  • PC Interface for WiFi robot control using C#
  • Android Interface for Wifi Robot control (possibly using Basic4Android, we’ll see)
  • 3D Printed Lego Compatible mounting blocks for Arduino (entirely dependent on me getting a 3D Printer, hint: watch this blog)
  • Addition of webcam stream using Raspberry Pi or upcoming Arduino Tre

Some of these are stretch goals but you can never plan to big as long as you keep your priorities in order! So here we go! Hopefully I’ll have Part 1 up soon which deals with starting equipment and hacking the Lego Power Functions cables for connection to a motor driver.

Series Contents: