Generation 2 firmware

From RepRap
(Redirected from Generation2Firmware)
Jump to: navigation, search

This page describes something which is no longer the most recent version. For the replacement version see: "Official" Electronics


RepRap 2nd Generation Firmware

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.

If you have a Sanguino and a stepper-driven extruder, you can use the new five-dimensional GCode interpreter. This allows the head to move with accelerations, and synchronizes extrusion with movement so that the right amount of extrudate is always laid down, no matter what speed the head moves when it is building. See the end of this page for details on that.

Soon we will be supporting the Arduino Mega as a controller as well.

Program the Arduino or Sanguino to talk G Code


IMPORTANT: If using Gcode 3D firmware (linked here) You must set the FiveD parameter in the host software's preferences to FALSE.



Download all the files at:

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

into a directory called GCode_Interpreter.

Make sure you have an up-to-date Arduino IDE. I'm using Arduino 0015, and that works fine.

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.

ThermistorTable.h

Near the top of the file 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. The standard RepRap thermocouple is K type. 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.

If one of your axes travels in the wrong direction (typically the Y axis) you will find the constants INVERT_[X,Y,Z]_DIR in parameters.h and setting the definition to 1 will reverse the direction of travel.

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

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.

The Five-dimensional GCode Interpreter

Five dimensions? Uh? Like, I only see three...

Nope. This firmware treats the RepRap machine as a five-dimensional system: the three dimensions of space, X, Y, and Z, the length of extrudate produced, E, and the feedrate at which the head is moving over the surface, F. These are all controlled by a five-dimensional DDA that automatically synchronizes them. This means that the length of extrudate laid down is always right, no matter how fast the head moves over the build. It also means (as the feedrate can be varied in a move) that the machine can accelerate and decelerate as it is building. This allows the X, Y and Z steppers to be run at a much lower current, without sacrificing build speed, because taking a few millimeters to accelerate up to speed (and slow down from it) needs much less current than hitting that speed from the first step.

This firmware also buffers the moves queued to it. This means that there is no pause between one move and the next, giving a much smoother and cleaner build.

This firmware only works on the Sanguino at the moment (it's too big for the Arduino's memory), though we will shortly be supporting the Arduino Mega with it too. It also needs a stepper-driven extruder, such as the RepRap Extruder Version 2. Again, we will be adding backwards compatibility to drive DC motor extruder too soon.

Start by downloading all the sub-folders and files from this directory in the repository into a directory called <nolink>FiveD_GCode.

Copy the files cartesian_dda.h.dist, extruder.h.dist, parameters.h.dist, pins.h.dist and vectors.h.dist to cartesian_dda.h, extruder.h, parameters.h, pins.h and vectors.h. These are your local copies that you will configure to your particular RepRap machine. If you are using Linux/Unix, there's a shell script called download-copy that will do all the copies automatically.

Plug your Sanguino into a USB port on your host computer, then open the Arduino/Sanguino development environment. Load up the file <nolink>FiveD_GCode_Interpreter.pde. You should get ten tabs: <nolink>FiveD_GCode_Interpreter, <nolink>ThermistorTable.h, cartesian_dda, cartesian_dda.h, extruder.h, extruder, parameters.h, pins.h, process_g_code and vectors.h.

<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. The standard RepRap thermocouple is K type. 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.

cartesian_dda.h

As it's name suggests, this is the heart of the five-D DDA. You should not need to change this file.

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

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. Note that you have to set a value for extruder feed: E_STEPS_PER_MM. This is the number of steps that the extruder stepper needs to take to produce one millimeter of filament.

There is a line defining ACCELERATION_ON. If you comment this out, it will disable the acceleration function and your machine will move at constant feedrates for each move. Note that this is how G Codes are normally used in general CNC machines. Thus, on a conventional machine (or on RepRap with ACCELERATION_ON commented out), this code:

G1 X23.9 Y39.0 Z0.2526 E66.5 F1500.0 ;print segment

G1 X23.9 Y39.7 Z0.2526 E67.2 F3000.0 ;print segment

would do the first move at a constant 1,500 mm/minute, and the second at a constant 3,000 mm/minute. On RepRap with ACCELERATION_ON defined, however, the second line would move 0.7mm in Y from where you last were, extrude 0.7mm of filament during the move, and accelerate from 1500.0 mm/minute to 3000.0 mm/minute while doing so.

You can move at constant speed with ACCELERATION_ON defined. Simply set the feedrate first:

G1 F1500.0 ;set feedrate

G1 X23.9 Y39.7 Z0.2526 E67.2;print segment.

If one of your axes travels in the wrong direction (typically the Y axis) you will find the constants INVERT_[X,Y,Z]_DIR in parameters.h and setting the definition to 1 will reverse the direction of travel.

pins.h

In the pins.h file there are two sections: the first is the one for the Sanguino. Make sure you make the following change in the Sanguino section. If need be, change the line

#define EXTRUDER_0_STEP_ENABLE_PIN (byte)-1 // 3 - Conflicts with the fan; set -ve if no stepper

to

#define EXTRUDER_0_STEP_ENABLE_PIN (byte)3 // 3 - Conflicts with the fan; set -ve if no stepper

If you have two extruders, both stepper driven, also make sure that the equivalent line for the second extruder is:

#define EXTRUDER_1_STEP_ENABLE_PIN (byte)7 // 7 - Conflicts with the fan; set -ve if no stepper

This switches on all the code to drive a stepper-driven extruder.

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. Press the Sanguino's reset button just before you do the upload.

Preferences

To turn accelerations on, run the RepRap Host Software, select the Preferences button, and set the values of <nolink>MaxXYAcceleration(mm/mininute/minute) and <nolink>MaxZAcceleration(mm/mininute/minute) positive to turn on the generation of accelerating G Codes. The values I use are 1200000 and 3000 respectively. To turn on the generation of the appropriate extruder parameters in the GCodes produced, set the parameter <nolink>FiveD to be true. For more details of the extrusion and acceleration parameters, see the Preferences Page.

-- Main.ZachSmith - 26 Mar 2009