Sunday, February 15, 2009

#4 – The Sanguino is Alive!!

Well after many weeks of waiting for all the parts to arrive from various places in the world, I have just about everything I needed to get started. So this weekend I set up shop in the guest room (temporarily because mom is recarpetting).

I set up my new soldering station - complete with delsoldering gun, got to try out my breadboard vices, and utilized my DIY solder fume filter! The eifel tower lamp is just for some extra light, or should I say...lumière!

It’s a good thing that DIY projects aren’t an all or nothing thing. What I mean is that, I can choose to build my RepRap in steps. I don’t have to choose to spend $5k on a product that might not end up worth being $5k of awesomeness. Even if this project ends up costing $1000, I can choose to build it, or more importantly, buy it in steps. So think about all the parts that go into building something like this. There’s the frame, the hardware (motors, and nozzles and stuff), and the electronics. Well, if I can’t get the electronics working, there’s no point in building a frame or buying expensive motors. So there’s my starting point. And luckily, electronics are relatively inexpensive.

The Brain and How it Works
I love microcontrollers. I do, it’s just one of those things that I excel at, and I understand, and will probably make a career out of. Computers are cool, sure, but my brain wants to know how everything works. Why does a computer take so long to start up? How can it display something that I type and you’re now reading? How can a machine “think?” Knowing the basics of microcontrollers gave me the knowledge, or at least the basis to answer some of these ethereal questions. But it’s beyond the scope of this blog to talk about the inner workings of a microcontroller (and I’m restraining myself because I want to spew out information about the ALU, bits and bytes).

While in college I worked primarily with the Motorola HC6811 microcontroller. We had 30 development boards, and the course I was taught in “Microcomputer Engineering” was based on these boards. A development board is an electronics board that has LEDs, speakers, LCD’s, and Input/Output terminals that are all hooked up to the microcontroller. When connected to a computer, the microcontroller can be programmed to control the different peripherals to make sure that everything is working. I programmed the HC6811 with very low level code. Let’s say that you wanted to get the HC6811 to add 1 + 2. I would type in a program to control the HC6811’s registers with easy to remember mnemonics. These mnemonics would be translated by the program I was writing it in (THRSim) to Op Codes, which would be sent (via serial cable) to the microcontroller where it would understand what to do in binary code (1’s and 0’s).

Mnemonic Code (What I wrote):
LDAA #$01
ADDA #$02

OP Code (Translation):
86 (LDAA)
01
8B (ADDA)
02
Binary Code (What the HC6811 Understands):
1000 0110 (86)
0000 0001 (01)
1000 1011 (8B)
0000 0010 (02)

The above code sections are equivalent. The Mnemonic code is easy for a human to remember, but cannot be understood by the microcontroller. This was often a very tedious and cumbersome process. Though I LOVE writing in Mnemonics (because it’s so cool to manipulate and understand exactly how your computer is working) I was having to worry about how to have the microcontroller do things, instead of what I wanted it to do. It’s quite literally micromanaging (pardon the pun) the computer. Early on, engineers decided the best ways for how the microcontroller should do simple things like adding, and standardized the way things should be done. They put this efficiency into a translator known as a compiler so that engineers and programmers could focus on the “what” instead of the “how.” This is what we now call high level language (C, C++, Java…). So now I can control my computer with a language that looks strikingly similar to English, and not have to worry about low level concepts like how many accumulators does the microcontroller have, and what are the general purpose ones?

Now I can write this:

int a = 1;
int b = 2;
int c = a + b;

Unfortunately for me, a high level language compiler hadn’t been written for my precious HC6811, so in college I had to stick with the basics (literally).

Enter the Arduino
The Arduino is the name of a line of development boards based on the Atmel Atmega microcontrollers. It has several different “flavors” based on the users needs, but I’ve found that most of the different microcontroller boards out there are differentiated by their number of I/O ports. Lets say that Microcontroller A had one I/O port available. This usually means that there are only 8 Input/Output lines for use. So if one wanted to control 9 LEDS, well you couldn’t (at least independently) do it. The Arduino uses free software to program it in a C-like higher level language. It is geared for DIYers.

I’ve been led to believe that the Arduino is a great little board, and can (and has) controlled peoples RepRap’s quite well. The only problem is that the Arduino is stretched pretty thin, controlling all of the motors (no ports left). So expandability for the future is limited. And since the RepRap is evolving, expandibility is a big deal! So I chose to go with the Sanguino. This is a board based on the Atmel Atmega644P. Here are the differences:
 

Sanguino

Arduino

Processor

atmega644P

atmega168

GPIO Pins

32

20

Analog Pins

8

6

PWM Pins

6

6

Flash Memory

64K

16K

RAM

4096 bytes

1024 bytes

EEPROM

2048 bytes

512 bytes

External Interrupts

3

2

JTAG

yes

no

I2C

yes

yes

SPI

yes

yes

USARTs

2

1

Onboard USB<->Serial Converter?

no

yes

Breadboard compatible

yes

sort of1

Made by

RepRap Research Foundation

Arduino Team

All you really need to take from the above table, is that it has moar stuf! It’s also compatable with the Arduino software, and designed by a fellow RepRapper Zach Hoeken. So this is what I went with. I bought the kit from www.wulfden.org along with the P4B serial adapter to connect the Sanguino to my computer (to program it).

Sanguino - $27
P4B Adapter - $5
Shipping - $5

Putting it Together
When I received the kit it came in a little baggie with all the necessary components ready to be soldered.

I matched up the components with their holes and soldered away!

I had a problem with the headers. (The pins in the lower right hand corner). I originally soldered them upside down thinking that something would go on top of the board like a shield (an addon for Ethernet or something). I found out later that the pins needed to be soldered on the bottom so that I could put it into a breadboard. Duh! The desoldering took quite a bit of time, skill (that I didn’t have), and force (that I had way too much of). So now I’m waiting for my digikey order of replacement headers. /bonk

But once it was all in place, I found a plug that used to belong to a set of speakers and plugged it in. It worked as seen in the video below.

Connecting it to the Compy
The P4B serial adapter board took less time to solder because it was smaller.

In the end, it looked great without any mistakes!

When I was done, I hooked it up to my Sarduino, and my USB>Serial cord up to it. I downloaded the Arduino software, and typed my first program.
void Setup()
{
pinMode(0,OUTPUT);
}
void Loop()
{
int a = digitalRead(0);
digitalWrite(0, !a);
delay(2000);
}

After a bit of debugging (I forgot the () after Setup and Loop) I clicked on upload, and the results are in the video below!

Apparently you need 2 functions for the microprocessor, Setup and Loop. Setup happens first, and is used to set up values like whether a particular pin should be configured as input or output. Then the Loop function runs in a…Loop. Over and Over. In my little program, it sets up pin 0 (the debug LED) as an OUTPUT, and then finds out if it’s on or off. It then programs the Led to be what it wasn’t before (if it was on, then it’s off). Then there’s a delay of 2000mS (2 seconds), and it loops! Freaking fantastic. I love it. I’m programming in C what I used to do with registers and what not. This could be the beginning of a beautiful friendship.

What Next
I need to solder on the headers (that I hope to get in the next few days) to the board so I can do some prototyping. Then I need to program the Sarduino to control a stepper motor (my heart be still). Stay tuned!

Reference

All the rest of my pix from this build are here.

Tuesday, January 13, 2009

#3 - Choosing a RepRap Design

Reprap vs Repstrap

So you've looked at some of the pictures over @ http://www.reprap.org/ and decided that you are going to make a reprap. Fantastic!

Now just go down to your local hardware store and buy these parts:

Hmmm. The store manager might have trouble finding them. These parts are designed to be printed out on a RepRap machine, but the problem is that you don't have a RepRap to print them out! It's a bit of a chicken and the egg problem. So you can either:
1. Find someone willing to print out all the parts for you or
2. Build a machine that is capable of printing out those parts.

Any machine built with parts that itself cannot create is called a Repstrap. It is bootstrapping the process of building a reprap. There are currently 2 options for repstrap machine designs:

1. The McWire (based on the design by Tom Mcwire) is a Repstrap whose structure is composed of common pipe components.
2. The Acrylic Repstrap's structure is made from pieces of custom cut acrylic. These custom cuts could come from an online acrylic cutting service like Ponoko.
The acrylic repstrap is also known as a rep(st)rap. The reason for the parenthesis, is that one day we hope to be able to strap a laser to a reprap so that it can cut acrylic. When that day comes, the acrylic repstrap will be an acrylic reprap because it can then manufacture its own parts. Thus the "st" is in parenthesis in anticipation that it will be dropped.

As an aside, I would like to be one of the first ones to strap a laser to this sucker. I've already bought a fire extinguisher for experimentation ;-)


Differences in Repstraps
Since I am not the most social person in the world, and don't feel like meeting someone craigslist style at a mall to get reprap parts, I decided to build a repstrap. But which one?

Remember the components of a cnc?
Power supply
Electronics
Stepper Motors
Structure
Head


It turns out that the electronics (and the power supply), the motors, and the head can be used in all three styles of reprap. The only difference between reprap, repstrap and rep(st)rap is the structure. Hazaa! I like simplicity. So the cost difference between repraps is the structure.

Looks like i'll need to break down the Bill of Materials (BOM) for the McWire, and the Acrylic designs to see which one is cheaper. Though I must admit, the Acrylic one looks very sexy!












Monday, January 12, 2009

#2 - Components of a RepRap

The Heart of A CNC Machine
If you were to ask me what the most important part of a cnc machine is, I would have to say the motors. Everything else is not necessarily fluff, but is around arguably to soley support the motors.

A CNC machine is defined by the amount of degrees of freedom it has. A regular desktop printer is a 1-dimension cnc machine. If you've ever peered inside an inkjet printer, you can see the print head moving across the page as the page is fed through. There is one motor controling the exact movements of the print head.

A 2-dimension cnc machine is something that you might find in an industrial shop. If you've ever seen a show on how things are made, then you've probably seen a large robot laser cutting out precise shapes out of metal for car parts. For this type of machine the worker places a large square piece of material down on a platform, and the cutting head will move in two dimensions over the sheet of material, cutting as it moves along. One motor is used to control the cutting head in the right to left direction (called the x direction) and another motor is used for the back to front direction (called the y direction). Perhaps you've used an etch-o-sketch before. It's the same concept. Just pretend that your right hand is one motor, and your left hand is the other motor.
A 3-dimension cnc machine is, you guessed it, a machine that can move in 3 dimensions. In addition to the left to right, and back to front motion that the 2-d machine uses, it can also move the print head toward and away from the material. Or in the case of the RepRap, will move the stage away from the print head. And unless you haven't been following thus far, you'd know that the 3-d machine utilized 3 motors for all three directions of movement.

The Motor
I'm sure you've hooked up a toy motor to a battery before. It's neat, just connect one side of the motor to the positive pole of a battery, and the other side to the negative end. The axle turns, maybe powering a fan, or a remote control car. At best these motors are either on (forward/backward) or off. Now you probably could hook one of these motors up to the reprap head and if you wanted to go 3" to the right, you could turn it on for 2.46 seconds (a guess?). Of course, only the best guesses for the timing of these on/off motors, wouldn't be very accurate.

There is a different kind of motor: the Stepper Motor! A stepper motor would confuse anyone. It doesn't have just two wires, but anywhere from 4 to 8. And connecting these wires to batteries wouldn't actually do anything. The axle wouldn't turn, it would just sit there. Very unimpressive until you know how they actually work.

In a stepper motor, there are several different windings of wire, that when power is applied creates an electro magnet. There is a permanent magnet situated in the middle of the electromagnet windings. If the windings are turned on in the correct order, the axle (attached to the permanent magnet) will turn. In the figure on the right we will label the top winding (1), right winding (2), bottom winding (3) and left winding (4). When we attach a power source to winding 1 an electromagnet forms with the south pole pointed down. Since opposites attract, the permanent magnet's north pole is pulled toward the electromagnet. If winding 1 is then turned off and winding 2 is turned on, the permanent magnet will turn to the right, orienting its north pole to the electromagnet formed by winding two. The same thing will happen if we turn off winding 2 and turn on winding 3. The magnet will turn, orienting its north pole down because of the attraction to winding 3. And of course with winding 4, it's completely similar. If you had 4 switches that turned on and off the windings corresponding to the switch number, you may do this to turn the motor one full clockwise rotation.

Step 1: Turn On Switch 1
Step 2: Turn Off Switch 1
Step 3: Turn On Switch 2
Step 4: Turn Off Switch 2
Step 5: Turn On Switch 3
Step 6: Turn Off Switch 3
Step 7: Turn On Switch 4
Step 8: Turn Off Switch 4

It may seem like a hassle at first, but this verbose way to turn "on" the motor, has granted us exceptional control in controlling our motor. Many of today's stepper motors have excellent precision, down to around 400 steps per revolution. That means you could turn the axle less than a degree for each on/off of a winding.

If you want even more precision from your stepper motor, many of them allow "half-stepping." When two windings are on at once, the permanent magnet experiences equal pull by both of them and is pulled in between them. This allows for double precision. This process is shown below.


Everything else plays support
The component breakup of a reprap, or any cnc machine is:

Power Supply - Transfers power from the wall outlet/power source, to the electronics
Electronics - Microprocessor, and other circuitry to translate commands to move around the head
Stepper Motors (1 for each dimension of freedom) - Moves the head around with great precision
Structure - The platforms that holds the material being worked on, holds the head, and contains the electronics
Head - The device responsible for cutting, extruding, or manipulating the material being worked with

The structure can be seen clearly here. It is the metal rods joined by the white pieces. The electronics are strapped onto the structure in this reprap.

Friday, January 9, 2009

#1 - Intro and Resolution

Over the past couple years I keep coming across sites for CNC machines (computer numerical control). In short, it is a machine that can take coordinates from a computer and do "something" at those coordinates. Some cnc machines use a laser to cut out exact shapes from materials, some cnc machines can etch out a pc board for circuits, and some can even create 3d objects. I've always thought about how much I might be able to use one, but as the commercial models are $5k-$30k they've definitely been out of my grasp.

Though my desire for a personal cnc machine was solidified at Messiah College when I used one to etch out circuits for my senior project. It was the coolest thing ever. I designed the circuit in Multisim, transferred it to Ultiboard to lay out the physical components, and then took the pattern to the cnc. There Steve would help me throw in a bit of copper plated pcb and pop in a bit and watch it go to town. The machine would drill the holes for the through hole components, and then take off a thin layer of copper to form the traces. When it was done, I had a custom board that I could solder my parts to. Talk about rapid prototyping!

When I found a collaborative project entitled, "RepRap" (the Replicating Rapid-prototyper, reprap.org) that claimed to have plans to build self replicating cnc machines I was intrigued. Over the next few weeks I poked and prodded the site to see if the instructions were easy enough to follow, that the idea was solid enough to invest time and money in. The more I read, the more excited I got. Here was a community born out of a man's (Adrian Bowyer) 2005 conceptual paper to design a robot that could produce its own parts. Now I know what I thought when I heard that, "how can a robot build itself?" Well as of right now it can't. But a reprap is essentially a cnc machine that can "print" out about 60% of the components needed to build another reprap. It does this with what is essentially a glorified glue gun called a, "thermoplastic extruder." The reprap will build a part by laying down layers of molten plastic until a 3d part takes shape.

Since this RepRap is an ongoing collaborative effort by several diy'ers around the web, it is quite constantly changing. The goal of the project is to have everyone who wants to, have a rapid 3d printer sitting on their desk. I'd like to help out their effort, and in doing so create a bleeding edge piece of technology myself.

And that is my 2009 new years resolution.