BrickEngineer: LEGO Design

LEGO Engineering for LEGO NXT and Robot Enthusiasts

DIY Arduino Circuit


Jameco.com has an interesting article on how to build your own Arduino microcontroller circuit.

Image of a circuit board

The circuit relies on an ATMega328 microcontroller, and since it requires only component parts it is cheaper and has a potentially smaller footprint than the popular Arduino Boards.

We have started using Arduino microcontrollers to directly control the LEGO Motors (9842), and expect to post on this sometime in the near future. In the meantime check out posts on LEGO NXT motor control:

LEGO NXT Motor Wiring

Hacking the LEGO Mindstorms NXT Standard Motor

Interface a Potentiometer to the NXT

NOTE: WE ARE NOT RESPONSIBLE FOR ANY DAMAGE YOU MAY DO TO YOUR NXT BRICK.
THIS EXERCISE PRESUMES SOME WORKING KNOWLEDGE OF ELECTRONICS.

In this exercise, I will walk you through interfacing a potentiometer (variable resistor) to the NXT brick.
You will need:
– A stripped NXT cable
– A potentiometer with a maximum resistance no more than $10 k\Omega$
– A small piece of wire
– An NXT Brick

This exercise is derived and expanded from a chapter in Extreme NXT by Gasperi, Hurbain and Hurbain.

THEORY

The NXT monitors the potential difference between the black and white wires with an Analog-to-Digital (A/D) converter. The A/D converter converts this potential difference to a RAW value between 0 and 1023 (10 bits accuracy). This RAW value is given by the ratio

(1) $RAW = \frac{RAW_{max}}{V_{max}} V_{R} = \frac{1023}{5} V_{R}$

where $RAW_{max}$ is the maximum RAW value of 1023, $V_{max} = 5V$ is the voltage used by the NXT A/D Converter, and $V_{R}$ is the voltage drop between the black and white wires.

The circuit diagram looks like this:

NXT A/D Converter Schematic

I have a little $1k\Omega$ potentiometer that can turn over a range of about $0^{\circ}$ to $270^{\circ}$. Below is a diagram. The resistance between the leftmost and rightmost pins is the maximum resistance of $1k\Omega$. We will focus on the resistance between the leftmost and center pins, which varies based on the angle through which the potentiometer has been rotated. To keep things safe, we wire the center pin and rightmost pin together. This doesn’t affect the potential difference between the leftmost and center pins.

Potentiometer Wiring

I will assume that it is a linear potentiometer (a pretty good assumption), which means that the resistance at any given angle $A$ is given by

(2) $R = \frac{A}{A_{max}} R_{max} = \frac{A}{270} \times 1 k\Omega}$

where $A_{max}$ is the maximum angle of the potentiometer and $R_{max}$ is the $1k\Omega$ maximum resistance.

Equation (2) says that if the angle $A = 0^{\circ}$ then the resistance of the potentiometer $R_{max} = 0 \Omega$, and if the angle $A = 270^{\circ}$ then the resistance of the potentiometer is maximum $R_{max} = 1 k\Omega$.

Looking at the circuit diagram for the A/D converter, the potential drop across our potentiometer (represented by resistor $R$) is given by the typical voltage divider relation

(3) $V_R = \frac{R}{R+R_{int}} V_{max} = \frac{R}{R+10k\Omega} \times 5V$

We can now substitute (2) into (3) so that the voltage between the black and white wires is determined by the angle of the potentiometer rather than its resistance. Then we can substitute the result into (1) to get an equation for the RAW value

(4) $RAW = RAW_{max} \frac{A R_{max}}{A R_{max} + A_{max} R_{int}}$

with my particular values, this is

$RAW  = 1023 \frac{A \times 1 k\Omega}{(A \times 1 k\Omega) + (270 \times 10 k\Omega)}$

This formula will let us predict the NXT RAW value based on the angle of the potentiometer.

For my potentiometer, I find that a maximum angle of $270^{\circ}$ gives me a maximum value of 93. This is less than 7 bits of information, and each RAW value corresponds to $2.9^{\circ}$. If you want a nice angle detector, you will probably need a $10 k\Omega$ potentiometer!

TRY IT

1. Before beginning, you need to cut and strip one of the NXT cables so that you can interface with the wires directly. I have placed a layer of solder on mine, so they can be inserted into a breadboard for easy connecting.

2. Next connect the center and right pins of the potentiometer together with a wire

3. Plug the other end of the NXT cable into the NXT brick.

I wrote a simple NXT-G program to read the sensor and display the RAW value. Notice that the Touch Sensor actually reads the resistance between the wires. So we are just replacing the Touch Sensor with a potentiometer. We will use the raw number output of the Touch Sensor Block, which is represented by the 1010 0101 symbol. We then need to convert it to text so it can be displayed on the NXT LCD panel.

potentio-01.rbt Screenshot

You may download it here,
Potentio-01.rbt
or write your own.

When I try my potentiometer, I find that the RAW value goes from 0 to 95, pretty close to my predicted range of 0 to 93. So it works! Not bad considering I guessed that the potentiometer sweeps through and angle of $270^{\circ}$.


Determining the Angle of the Potentiometer

Now, let’s convert this RAW value to an angle.
In Extreme NXT, the authors worry about the fact that the resulting relationship is nonlinear with respect to the RAW value. As far as I can see, this isn’t a problem. We simply solve (4) above for the angle $A$ in terms of RAW. We can output the angle if we wish, but here I’ll take it a step further and demonstrate the resulting equation by controlling a motor so that it maintains an angle equal to the angle through which I have rotated the potentiometer.

I will leave out the algebra. Try it yourself. Solve (4) for angle A:

(5) $A = \frac{RAW A_{max} R_{int}}{R_{max} (RAW_{max} – RAW)}$

for my potentiometer, this is simply

$A = \frac{2700 RAW}{(1023 – RAW)}$

which is easy to code in NXT-G.
You can download my code here:
Potentio-03.rbt

The motor control is a bit crude, but it works well enough for the demonstration.
Check out the YouTube video to see it in action!

Enjoy!

LEGO NXT Motor Wiring

After posting Hacking the LEGO Mindstorms NXT Standard Motor, I received several requests for more information regarding the wiring of the motor.

The NXT cable has six wires. Below I list a table with the wires and their colors:

Color Name
White Motor 1
Black Motor 2
Red GND
Green 4.3 Volts
Yellow Tach01
Blue Tach02

The WHITE and BLACK wires (Motor 1 and Motor 2) deliver power to the motor.
If standard batteries are used, the potential difference will be 9 volts, otherwise the NiMH rechargeable batteries provide 7.2 volts. If the white wire is positive and black is negative, the motor will turn one way. If you reverse the polarity, the motor will turn the other way.

The RED wire is connected to the ground (GND). Note that in the sensors, RED and BLACK are connected to one another. This is not the case in the motors.

The GREEN wire is connected to the +4.3 NXT power supply.

The YELLOW and BLUE wires are connected to the quadrature encoder, also called an incremental rotary encoder.

Basic Rotary Encoder

Square waves from quadrature encoder

As shown in the figure from Wikipedia above, (http://en.wikipedia.org/wiki/Quadrature_encoder) the wires return square wave pulses that are 90 degrees out of phase. If the rising pulse on TACH00 leads the rising pulse of TACH01 by 90 degrees, then the motor is going forward. If it instead lags by 90 degrees, the motor is rotating backwards. One complete square wave cycle corresponds to 2 degrees of rotation. In the diagram above, if TACH00 refers to A and TACH01 refers to B, we can see that the motor is going backwards as TACH00 is lagging TACH 01.

By measuring the frequency of the square wave oscillation, one can compute the rotational velocity. Since one cycle corresponds to 2 degrees of rotation, one cycle per second (1 Hz) corresponds to 2 degrees/sec. If you record a frequency of X Hz, then the rotation rate is 2X cycles/sec.

Note also that by tracking both square waves, you can identify quarter cycles, which gives you a resolution of 1/4 of 2 degrees, which is 0.5 degrees.

The motor speed is controlled by pulse-width modulation (pwm), which works by driving the motor with a variable duty cycle square wave. This effectively turns the motor on and off, fast. The longer it is on, the more torque it will generate and the faster it will go.

These details and more can be found in the excellent book: Extreme: NXT with a sneak peak here.

Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.

Philo uploaded a comment, and reminded me that “Note that there are some internal photos of the NXT motor here: http://philohome.com/nxtmotor/nxtmotor.htm and schematics here: http://www.brickshelf.com/cgi-bin/gallery.cgi?i=1846577

Happy Hacking!

Basic Electronics Supplies for Beginners

I am getting interested in more general robotics projects, but will still be relying on LEGOs for their construction.  The LEGO brick is a bit too limited with its specialized programming languages and limited sensor and motor ports.

So for those interested in some LEGO electronics hacking, here is a list of supplies that will get you up and running fast for about $275… just a but more than the cost of a single Mindstorms kit.  Plus you’ll now get to learn electronics!

First, check out the book:
Making Things Talk: Practical Methods for Connecting Physical Objects

This book explains how to wire, program and interconnect various microcontrollers, some of which are very closely related to those used by the NXT Brick.

Supply List

Item Number Description Quantity Unit Price Total
Amazon.com
  Making Things Talk 1  $19.79 $19.79
Jameco.com
19166 Desoldering Pump 1 $4.95 $4.95
159291 Wire Stripper 1 $10.15 $10.15
161411 Diagonal Cutter 1 $7.49 $7.49
35474 Needlenose Pliers 1 $5.49 $5.49
127271 Mini Screwdriver 1 $1.89 $1.89
681002 Helping Hands 1 $8.75 $8.75
159611 Power Connector 2 $1.79 $3.58
10444 Alligator Test Clip Leads 2 $4.39 $8.78
103377 Header Pins 10 $0.16 $1.60
119011 Push Button (PCB Type) 10 $0.27 $2.70
29082 Potentiometer 2 $1.05 $2.10
242115 LM1117T-3.3 Voltage Regulator 3 $1.39 $4.17
51262 7805T 5v Voltage regulator 3 $0.32 $0.96
38236 2N2222A Transistor NPN 5 $0.41 $2.05
32993 TIP120 Power Transistor 5 $0.45 $2.25
643488 3.3V Zener Diode 5 $0.03 $0.16
35991 1N4004 Diode 5 $0.04 $0.20
152792 LED Yellow 10 $0.17 $1.70
152805 LED Red 10 $0.21 $2.10
153139 LED Orange 10 $0.35 $3.50
156962 LED Green (567 nm) 10 $0.20 $2.00
334529 LED Bargraph Red 1 $1.31 $1.31
334537 LED Bargraph Yellow 1 $1.23 $1.23
334511 LED Bargraph Green 1 $1.28 $1.28
17187 7-segment LED Display 3 $0.88 $2.64
38818 4-switch DIP 4 $0.48 $1.92
38842 8-switch DIP 2 $0.89 $1.78
103166 Resistor Refill 1 $12.95 $12.95
15270 0.1 uF 10 $0.15 $1.53
94161 1 uF 10 $0.12 $1.20
29891 10 uF 10 $0.06 $0.60
158394 100 uF 10 $0.11 $1.08
MPJA
4443 TE Solderless Breadboard 1 $4.95 $4.95
4447 TE Large Solderless Breadboard 1 $22.95 $22.95
7027 TE Jumpers 2 $3.95 $7.90
14213 TE Digital Multimeter 1 $14.95 $14.95
15860 TL Mini Soldering Station 1 $14.95 $14.95
Sparkfun
Wiring Platform DEV-00744 1 $84.95 $84.95
Radio Shack
64-025 Lead Free Solder 1 $3.89 $3.89

Note that the light gray items are optional, and not necessary.

Also, this list does not include some sort of power supply. Pulling one out of an old computer is an easy option. Or rechargeable batteries work well too (in which case you will need battery holders).

Last, there are special items in the book Making Things Talk that you may decide to purchase separately, such as flex sensors, or bluetooth boards, etc.

You can store your electronics in much the same way you store your small LEGO parts. Check out the article on Storage.

Enjoy Hacking!

Hacking the LEGO Mindstorms NXT Standard Motor

We are working on interfacing the LEGO sensors and motors to a compact lightweight computer for more sophisticated control. Aret Carlsen brings us a video demonstrating how one can hack into the NXT Standard Motor:

See also quadrature encoder or rotary encoder at wikipedia and the LEGO NXT Hardware Developers Kit (LEGO NXT data sheets). Philo also has the pinout diagram on his page on deriving power from the Motor A port.

Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.

Hacking the LEGO Mindstorms NXT Light Sensor

We are working on interfacing the LEGO sensors and motors to a compact lightweight computer for more sophisticated control.  Aret Carlsen brings us a video demonstrating how one can hack into the NXT Light Sensor:

Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.

Storing your LEGO Collection

It can be very difficult to figure out exactly how to store one’s LEGO parts. This depends greatly on the extent of your collection, and how mobile it needs to be. Below I offer a wide array of suggestions ranging from the size of one NXT set through tens of NXT sets with thousands of dollars of extra parts. Here I will review the solutions that I have found useful, and at the end I will provide a detailed description of my particular storage strategy.


Utility Boxes with Compartments
Clear plastic utility boxes with adjustable compartments are excellent for storing LEGO parts, keeping them separated, and making sure that they are accessible. I have found the products manufactured by Plano Molding Company to be especially useful. The Plano Prolatch with Adjustable Dividers
is secure and allows one to carry the box around without fear of accidental opening. These utility boxes are also included in the larger Plano Tackle Boxes, which provides an excellent means of both storage and transport.The new Custom Divider Systems (CDS) give you a great many ways to divide each box into bins with the greatest versatility. The other divider systems work well, but this is a nice option.

Small Box
Plano No. 2-3500-20
9-1/8″ Wide. x 1-1/4″ High x 5″ Deep
Up to 9 adjustable compartments
Order from Amazon.com
These fit into the Plano 1354 Tackle Box
below
Medium Box
Plano No. 2-3650-20

11″ Wide x 1-3/4″ High x 7-1/4″ Deep
Up to 18 adjustable compartments
These fit into the Plano 1364 Tackle Box below
Large Box
Plano No. 2-3750-20

14″ Wide x 2″ High x 9-1/4″ Deep
Up to 20 adjustable compartments
These fit into the Plano 1374 Tackle Box below

Tackle Boxes
Plano tackle boxes are designed to hold multiple (typically four) utility boxes above. This provides for a readily mobile storage solution. Your LEGO collection can be carried from your home, to the lab, a friend’s house, or into the field at a moment’s notice. Here is a photo of my Plano 1364 Tackle Box that I use for most of my construction needs.

Plano 1354 Tackle Box (3500 size)
I have found that the 1354 Tackle Box is a bit on the small side for even the smallest collections. You will be surprised at how many distinct kinds of Lego parts there are, when you find that they will never fit into the 9×4 compartments. However, this tackle box can hold 4 utility boxes, and you often can put an additional box in the top compartment.
Order at Amazon.com
Plano 1364 Tackle Box (3650 size)
This is a really nice size for a tackle box. I can easily store at least two NXT sets in this tackle box as well as many extra parts. Four Plano ProLatch 3650 stowaway boxes
fit in the tray resulting in 4×18 = 72 compartments. I also manage to keep an additional 3650 box in the top of the tackle box. I can often work with just this subset of my collection. In addition, it makes travel easy.
Plano 1364 Tackle Box at Amazon.com
Plano 1374 Tackle Box (3750 size)
This tackle box can hold a large number of parts. The top bulk storage compartment is sufficiently large and deep to actually hold smaller robots! The 3750 size utility boxes are very spacious, and this tackle box comes with one of the newer Custom Divider System (CDS) utility boxes, and one flip-sider, which is good for fishing tackle, but not so useful for LEGO parts. For this reason, you may need to buy an extra 3750 box to replace the flip-sider. And you may want an extra 3750 to fit in the top compartment.
Plano 1374 Tackle Box at Amazon.com

Compartmentalized Storage
For a more extensive LEGO collection, one may require more storage space for small parts, such as pins, axles, etc. Akro-Mills makes some very nice organizers with a large number of small drawers.

Akro-Mills 10724 24 Drawer Storage

This organizer can hold a healthy supply of small LEGO parts. The organizer comes with partitions that can be inserted into the drawers allowing one to keep more parts.Overall Size: W=20″ H=15.81″ D=6.38″ (inches)
Drawer Size: 4.25″ W x 5.25″ D x 2.0″ HI have three of these. One holds all of my pins and connectors. The second holds all of my axles and axle connectors, and the third holds all of my gears.
Akro-Mills 10124-2 44 Drawer Storage
This organizer can hold a healthy supply of small LEGO parts. The organizer comes with partitions that can be inserted into the drawers allowing one to keep more parts.Overall Size: W=20″ H=15.81″ D=6.38″ (inches)
Large Drawers: 4.38″ W x 5.25″ D x 2.0″ H
Small Drawers: 2.13″ W x 5.25″ D x 1.50″ H
Akro-Mils 10764 64-Drawer Storage

This organizer can hold many small LEGO parts. The organizer comes with partitions that can be inserted into the drawers allowing one to keep even more parts.Overall Size: W=20″ H=15.81″ D=6.38″ (inches)
Small Drawers: 2.13″ W x 5.25″ D x 1.50″ H

Large Storage Bins with Drawers
The larger collections require more extensive storage. Storage bins with drawers are excellent for storing large numbers of bricks of many colors and types. Stackable bins with drawers facilitate organization and access, although they require a good bit of space… or rather, your collection does!

Three Drawer Organizer
I have found the Sterilite ClearView™ Wide Three Drawer Organizer 2093 to work very well. Its dimensions are suffciently large to hold a large number of brick. Or one could make partitions (they do not come with the drawer) to store a wide array of parts in a single drawer. At this point, I use 20 of these to store my bricks, plates, liftarms, wheels, and specialized NXT parts. The clear drawers make it easy to see what is inside, and one can easily afix large easy-to-read labels.The dimensions of the three drawer organizer is:
14 5/8″ L x 14 1/2″ W x 10 5/8″ H.

Large Mobile Storage
My lab requires that a large proportion of my parts be easily transported. The best solution that I have found for this is the mobile toolbox together with a healthy set of Plano Utility Boxes (above). I was surprised to find that there is not the diversity in toolbox designs that I expected. I finally settled on the
Stanley Consumer Storage 033023R Pro Mobile Tool Chest.

This tool chest when packed full holds:
4 large Plano 3750 compartment boxes
3 medium Plano 3650 compartment boxes
6 small Plano 3500 compartment boxesThis is in addition to the large top tray that can hold Mindstorm NXT bricks, a great deal of cabling, and other tools that you might need.The tool chest has a handle and wheels, which makes for easy transportation.
Order from Amazon.com here.

See the more recent posts: COLORFUL LEGO STORAGE IDEAS and New LEGO STORAGE OPPORTUNITIES for more ideas.

Content Protected Using Blog Protector By: PcDrome.