Generation 2 Electronics

From RepRap
Revision as of 01:47, 20 January 2009 by VikOlliver (talk | contribs) (version migrated from twiki)
Jump to: navigation, search

Arduino and Sanguino Based Electronics

Overview

Once you start putting electricity into your RepRap - even at just 12 volts - you have to take basic, common sense precautions to avoid fires. Just in case these fail, test your workshop smoke detector. Got no smoke detector? Get one!


Power Supply

PCPowerSupply-power-supply.JPG

The RepRap machine needs a regulated power supply giving at least 8 amps at 12 volts. The easiest way to do this is to convert a normal PC power supply into a RepRap power supply. Its simple, cheap, and all the boards are designed to accept the standard Molex connectors that are common on ATX power supplies.

More info and setup instructions here.


Individual Boards

Parts List

<iframe width='500' height='300' frameborder='0' src='http://spreadsheets.google.com/pub?key=pmEMxYRcQzzATwbOb71BmGA&output=html&gid=30&single=true&widget=true'></iframe>

Arduino, Arduino Clones, and Sanguino

Cache-arduino extreme 260.jpg

Arduino is an open source project that has created an easy and powerful microcontroller board based on the Atmel ATmega168. It is the brain of the RepRap electronics. You can get a premade Arduino, you can buy and assemble a kit, or you can even make it from scratch yourself. They all look the same to the rest of the electronics or to your computer. You will need an Arduino Nano, Diecimila, or Duemilanove or the latest equivalent.

Generation2Electronics-sanguino.jpg

Alternatively, you can use the Sanguino. Sanguino is an Arduino-compatible board based on the ATmega644P that was developed as a spinoff of the RepRap project by Zach Smith. It has four times the flash memory, four times the RAM, and many more pins than the Arduino. You can drive a RepRap with a standard Sanguino, but there will also soon be a special Sanguino RepRap Motherboard that makes the connections easier, has an SD card slot, and all sorts of other goodies.

A standard Darwin RepRap will run happily off an Arduino, but if you want expandability and upwards-compatibility for the future, go for the Sanguino.


Stepper Motor Driver v1.2

<div class="thumb tright"></div>

Each stepper driver board drives one of the stepper motors. You need three of these boards for a fully functioning RepRap. Each board controls the position of one axis. Together, they position the print head anywhere in the 3 dimensional build area.

More info and build instructions here.


DC Motor Driver v1.1

<div class="thumb tright">
Cache-1890054055 f5d5293028 m.jpg
</div>

This board is capable of controlling two low current DC Motors in both forward and reverse. It has a speed/direction interface and is easy to control.

More info and build instructions here.


PWM Driver v1.1

<div class="thumb tright">
Cache-1625658283 432f1c7af9 m.jpg
</div>

This board is capable of driving medium DC loads with TIP120 power transistors. It has a PWM interface and is also easy to control.

More info and build instructions here.


Opto Endstop v2.1

<div class="thumb tright">
Cache-2053713286 95af08be87 m.jpg
</div>

All of a RepRap's axes all need a datum (also known as home position or end-stop) to reference their movements. At the start of each build each axis needs to back up until the datum point is reached. We use one opto-switch for each axis to define its position. This page tells you how to wire one up.

More info and build instructions here.


Temperature Sensor v1.1

<div class="thumb tright">
Cache-2421252100 0661d6020c m.jpg
</div>

This sensor allows you to read a thermistor as an analog value. It is a very small and simple helper board.

More info and build instructions here.


Optional Boards

These boards are not required, but can be used to improve your machine or do different things.

Thermocouple Sensor v1.0

<div class="thumb tright">
Cache-2379552521 e02d9a539a m.jpg
</div>

The thermocouple sensor is a different type of temperature sensor board. Unlike the thermistor based temperature sensor which can only really handle temperatures up to 300C, the thermocouple sensor can handle temperatures up to and over 1000C. It uses a thermocouple for temperature measurement, and it is much easier to read values from (as well as being a bit more accurate over a wider range.

Pro's: This board may be especially interesting if you're tight on memory space on the Arduino, using the thermocouple will allow you to leave out thermistor conversion tables. It also saves you the hassle of calibrating a thermistor. It will probably give a more accurate result (within 1-2 'C).

Con's: Unfortunately, it is also more expensive (by about $25)

More info and build instructions here.


Magnetic Rotary Encoder v1.0

<div class="thumb tright">
Cache-2582992504 0745333fee.jpg
</div>

The magnetic rotary encoder is an optional board to determine the rotational speed of the extruder motor. A different method is laser-cut version, using a H21L0I (also used for endstops).

Pro's: Allows you to achieve better print quality than with open-loop controlling (without feedback) of the extruder motor.

Con's: Slightly added complexity due to another board in the system. The costs. Also, this board is surface mounted technology (SMT), which is slightly harder to solder and needs some extra (inexpensive) tools, such as a flux pen.

More info and build instructions here.


Arduino breakout shield

This is a board that allows you to make screw-tab connections to the Arduino: less fiddly than the standard connections. See details here.

Wire It Up

Now that all the boards are created, you'll need to wire it all up. One of the main advantages of the Arduino/Sanguino based system is that it is highly configurable. Each board can be wired to the microcontroller in a number of ways. The Arduino can use the SNAP communications protocol or G Codes. SNAP is compatible with the older PIC RepRap control system. G Codes are the newer and more versatile way of controlling the machine. The Sanguino just uses G Codes.

Wiring up with an Arduino

Generation2Electronics-single-arduino-with-valve-small.png


This is how to run an entire RepRap machine off of a single Arduino. The Arduino can simply be powered directly off the USB port of your computer. The only real downside is that the code takes up most of the space on the Arduino, and every single pin is in use. Basically, there is not much room for hacking either the firmware or the electronics... but it will definitely get you printing in a minimum of time and effort.

The Max endstops are optional; they are seldom used in practice. Indeed, if you're using an extruder with a valve, that takes up the pin used by Z Max.

Click for a bigger circuit diagram. This wiring diagram is available as an Eagle file in the RepRap repository here.



Wiring up with a Sanguino

Generation2Electronics-sanguino-connections-small.png

The Sanguino can simply be powered directly off the USB port of your computer, but it needs a USB->serial connector wire such as this one. There is plenty of room for code and data in the Sanguino, and no shortage of input and output pins.

As with the Arduino, the Max endstops are still optional; however, there is no shortage of Sanguino pins, so (apart from economics...) there is no reason to do without them.

Click for a bigger circuit diagram. This wiring diagram is available as an Eagle file in the RepRap repository here.



Mounting and Wiring

There are two alternatives here. You can put all the electronics in one place, and run wires from it to the components of your RepRap machine, or you can clamp the various circuit boards to the machine next to the devices they control and run control signal wires to them from the Sanguino/Arduino.

Electronics all in one place

First, find or cut a flat piece of thin plywood, about 300mm x 300 mm (12" x 12").

Next, place all your boards on the wood so that each board is close to where it will be wired to. Mark with a pencil through each hole, and also optionally around each board for drill holes and as a board outline.

Then, take all the boards off and drill a blind hole at each drill mark with a 2mm drill bit. (Use 3mm if you want to use nuts and bolts and drill right through - see below.)

Take a foot or so of silicone aquarium tubing and cut 5 mm (1/4") lengths of it. You will be using these to mount the boards to the wood. Optionally, you can use spacers if you want a more professional look.

Mount each PCB on the board using small round-headed woodscrews. Use the lengths of silicone tube as spacers between the wood and the PCBs.

Alternatively, mount each board on to the wood with M3 x 15mm bolts. Use washers on both sides, and use a short piece of tubing between the board and the wood for spacing (and shock absorbtion). Tighten down the nut by hand, and then a little bit with pliers or a wrench. It should be solidly attached, but not wrenched down too much. (For the brits: dont use too much welly ;)

Electronics distributed around the machine.

Generation2Electronics-electronic-layout.jpg

There are U-shaped PCB clamps in the RP parts for RepRap. These allow PCBs to be clamped to the 8mm rods that form the frame.

X, Y, and Z are the stepper controls for those axes. M is the microcontroller (this is the Sanguino, but the Arduino goes in the same place). The extruder control boards are at E behind the X stepper on the carriage.

Lasercut kits may use cable-ties, or excess small clamps normally used for clamping drive chain or drive belts.


Wiring connections

Once you have the boards laid out and mounted, its time to wire them up. Currently, there are four different ways to hook the boards up to your Arduino/Sanguino:

  1. Strip 5 mm (1/4") from the end of the wire, and stick it directly into the header on the Arduino/Sanguino. This is the easiest, but also most prone to failure (the wires will vibrate out, break, etc.) This works much better with single-strand wire than multi-strand.
  2. Solder each wire to a .100 pin strip, and plug that directly into the appropriate spot on the Sanguino/Arduino. This is the hardest method, but it is the most permanent. The downside is that its hard to reconfigure your system without resoldering everything.
  3. Solder each wire to an individuaL .100 pin strip pin, put a little heat-shrink on the join, and plug that directly into the appropriate spot on the Sanguino/Arduino. This is more fiddly, but more reconfigurable and versatile. It gives reliable connections too.
  4. There is an Arduino and a Sanguino breakout shield which you can insert into the Arduino or Sanguino to provide the same access to the pins, but in a screw terminal form-factor. This gives a nice blend of easy configuration, with a strong, semi-permanent connection.

Program the Arduino or Sanguino

You can set the Arduino or Sanguino up to communicate with the host using G Codes, or - in the case of the Arduino - with the SNAP protocol that we used for the original PIC-controlled RepRap. New users should go for G Codes.

Program the Arduino or Sanguino to talk G Code

Download all the files at:

http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/reprap/firmware/Arduino/GCode_Interpreter/

into a directory called GCode_Interpreter.

Copy the files extruder.h.dist, parameters.h.dist and pins.h.dist to extruder.h, parameters.h and pins.h. These are your local copies that you will configure to your particular RepRap machine.

Plug your Arduino or Sanguino into a USB port on your host computer, then open the Arduino/Sanguino development environment. Load up the file GCode_Interpreter.pde. You should get eight tabs: GCode_Interpreter, <nolink>ThermistorTable.h, extruder, extruder.h, parameters.h, pins.h, process_string and stepper_control.

<nolink>ThermistorTable.h

Near the top of the file <nolink>ThermistorTable.h there is a commented-out line that says #define USE_THERMISTOR. Uncomment the line if you are using a thermistor to measure temperature in your extruder; leave it commented out if you are using a thermocouple (see the Thermocouple Sensor section above). This file also contains a table of values that depends on the particular characteristics of the thermistor you are using. See this page for details on how to set-up that table for your thermistor.

extruder.h

Near the top of the file extruder.h there is a line that says #define EXTRUDER_COUNT 1. Change the 1 to 2 if you have two extruders.

parameters.h

Near the top of the file parameters.h there is a line that says #define SANGUINO. Comment that out with // in front if you are using the Arduino.

Following are the definitions of the number of steps of the stepper motors that your RepRap does to cover 1 mm. Change these if need be. If you are not sure exactly what the gearing in your machine is, run it under control of the Java host software, instruct it to move 50 mm in the various directions, measure how far it really does move (let's call that D), then multiply the appropriate steps-per-mm value by D/50.

There are also definitions of how many steps your axis motors take to do a complete revolution. The default values for all these is 400.

Then there are the maximum feedrates that the machine can do. You can experiment with these using the host software again - set the largest values that your machine can reliably manage.

Programming

Once you have all the parameters set as you want, compile the firmware in the Arduino development environment (there should be no errors...). Then select the Upload to I/O Board button (right arrow) on the development environment. If you're using a Sanguino press its reset button just before you do the upload.

Program the Sanguino to test your RepRap

Near the top of the file parameters.h there is a commented-out line that allows you to run stand-alone testing programs if you have a Sanguino (the Arduino is too small to run these). This program allows you to drive your RepRap machine from a serial terminal connected to the USB port driving the Sanguino to test its various functions without running the RepRap host software on your computer. To use this, uncomment the line that says #define TEST_MACHINE, then load the program into your Sanguino.

The first test is a communications exerciser. Select the serial-port window of the Arduino development environment and it just echoes what you type.

When that is working, comment out the line that says #define COMMS_TEST. Load the program into your Sanguino again, and you will get a menu of options in the serial-port window of the Arduino development environment that allow you to exercise the RepRap machine's stepper motors and extruder (only one extruder is supported at the moment by the test software).



Program the Arduino to talk SNAP

Once you have everything wired up and ready to go, its time to program the Arduino with the appropriate firmware. There are a few simple, easy steps to do this:

  1. Download and install the most recent Arduino program.
  2. Download the most recent RepRap Arduino firmware source.
  3. Copy the folders in the library folder of the file above into your Arduino library folder (arduino/hardware/libraries)
  4. Open the appropriate firmware in the file above and upload it to your Arduino board(s).

The appropriate firmwares are:

Single Arduino

/snap/Single_Arduino_SNAP/Single_Arduino_Snap.pde - just upload this file and you're good to go!

Once you have compiled and uploaded your firmwares, you should be good to go! Fire up the RepRap host software, double check that you've specified the proper serial connection, and you should be good to go! We recommend using the various exerciser programs to test each part of your machine before you go ahead and print stuff. If all goes well, then you'll be printing in no time.


Update Temperature Settings

Since the Arduino based electronics emulate the PIC style of temperature measurement, you may need to update certain temperature settings in the firmware and in your reprap.preferences file on your host computer. The default is setup for the RRRF 100K thermistor, and you will need to change values if you are using a different thermistor.

  1. Lookup the values for your thermistor.
  2. In the ThermoplastExtruder subdirectory of your Arduino library, create a symbolic link to the appropriate file (which will be something like Thermistor_r0_100000_t0_25_r1_0_r2_4700_beta_3960.h) called TemperatureSensor.h.
  3. Delete ThermoplastExtruder.o (if it exists) This is the old object file and will force the library to recompile.
  4. Run the host software for driving RepRap on your computer. Select Files->Preferences->Extruder_0
  5. Change Extruder0_Beta(K) to 550.0, Extruder0_Capacitor(F) to 0.000003, and Extruder0_Rz(ohms) to 4837 regardless of what your actual thermistor values are. Click on OK.

After that, you'll need to re-compile the firmware and re-upload it to your Arduino.

If you are using a K-type thermocouple and the RepRap thermocouple PCB, follow the above procedure, but link the file !Thermocouple-type-K.h to TemperatureSensor.h.

Setup Host Software

Install the RepRap host software as normal. Instructions for all platforms are located here.

Once you have the host software installed, open the software and pull up the Preferences menu. Switch to 'Extruder0' and change the preferences stated to the values below:

Preference Value
Extruder0_Beta(K) 550.0
Extruder0_Capacitor(F) 0.000003
Extruder0_Rz(ohms) 4837

The reason for this is that the Arduino emulates the PIC temperature measurement system with an 'ideal' thermistor. Those values are hardcoded into the header in ThermoplastExtruder_SNAP_v0.h. If you change the values there, make sure you update your host prefs too.