Arduino GCode Interpreter

From RepRap
Revision as of 16:04, 26 February 2008 by ZachSmith (talk) (version migrated from twiki)
Jump to: navigation, search

Arduino GCode Interpreter

Files

The GCode firmware source is available from SourceForge as part of the RepRap Arduino firmware package. Make sure you get the latest version.

Installation

Once you download the proper files, there are a couple steps you need to do:

  1. Copy the folders in reprap-arduino-firmware-x.y/library to arduino-00xx/hardware/libraries
  2. Open the GCode_Interpreter sketch in reprap-arduino-firmware-x.y/gcode/GCode_Interpreter/GCode_Interpreter.pde with the Arduino software.
  3. Upload the sketch to your Arduino.

Usage

Firmware Configuration

In order for the firmware to operate properly, you must configure the proper variables in the firmware and then upload the firmware to your Arduino. We'll cover each of the variables below:

X_STEPS_PER_INCH

This variable stores how many steps to take to move the X axis 1 inch. You will need to set this as accurately as possible if you want your machine to be accurate. There are two ways to set it:

  1. Move and Measure - slap a pen or marker on as a toolhead and draw a 1000 step line. Measure it and divide 1000 by the length in inches.
  2. Calculate Step Size - this one is the preferred way of doing things. Its rather easy to calculate step size based on your drive mechanism.

For threaded rod drive systems:

Find your TPI (threads per inch). for example, 1/4"-20 threaded rod means that there are 20 threads per inch (aka 20 turns = 1 inch.) Simply take that number and multiply it by the steps in a revolution. With a 400 step motor, it would be 8000 steps per inch.

For belt/pulley systems:

  1. Find the circumference of your drive pulley. (remember circumference = 2*pi*r) (say: 2.75")
  2. Calculate step size (ie: circumference / steps per revolution) (say: 2.75" / 400 = 0.00625")
  3. Divide 1 inch by step size (1" / 0.00625" = 160 steps/inch)

X_STEPS_PER_MM

This variable stores how many steps to take to move the X axis 1mm. You can either calculate it independently, or take the number above and divide by 25.4.

X_MAX_SPEED

This variable stores the maximum speed of the stepper in RPM (revolutions per minute). This is important as it determines the fastest speed to move the stepper. Start low and work your way up if you are unsure of the proper speed.

X_MOTOR_STEPS

This variable stores the number of steps per revolution. This is important as it factors into how many steps to take for a line, as well as how fast your stepper will move. Your stepper will have a fixed number of steps per revolution and should say it on the datasheet.

If you are driving your stepper in half-stepping mode, double the number of steps. Similarly, if you are using a microstepper driver, multiply the steps by the appropriate factor. Make sure you use this new step number when you are calculating steps per inch/mm.

Y_*, Z_*

These variables are the same as the variables above, but allow for different drive systems on the Y and Z axes respectively. You must still fill them out, even if all drive systems are the same.

Sending Commands

The Arduino firmware waits for commands on the serial port and will start processing a command after either encountering a newline, or when there are no more characters to read.

You can either write your own custom host software to send commands, use the RepRap software to send commands, or use the Processing app that we've bundled to send commands.

Implementation

Due to the limited size and processing power available on the Arduino, only a limited subset of G Coode has been implemented. However, the vast majority of uses of G Code are limited to these commands. Below, we cover the implemented commands as well as limitations.

G Codes

G0 - Rapid Motion

Implemented - only supports X, Y, and Z axes.

G1 - Coordinated Motion

Implemented - only supports X, Y, and Z axes.

G2 - Arc - Clockwise

Not implemented - coming soon!

G3 - Arc - Counter Clockwise

Not implemented - coming soon!

G4 - Dwell

Impemented. =)

G20 - Inches as units

Implemented. =)

G21 - Millimeters as units

Implemented. =)

G28 - Go Home

Implemented. =)

G30 - Go Home via Intermediate Point

Implemented. =)

G90 - Absolute Positioning

Implemented. =)

G91 - Incremental Positioning

Implemented. =)

G92 - Set current as home

Implemented. =)

M Codes

Standard Codes

M7 - Coolant on

This turns the fan on.

M9 - Coolant off

This turns the fan off.

Custom RepRap Codes

M100 - Extruder Speed

Accepts the 'P' parameter as a number between 0 and 255. This is the speed to use for extruder motor PWM (when extruder is turned on.)

M101 - Extruder on, forward

Turns the extruder motor on in the forward direction at the speed specified with M100. It will also cause a delay if the extruder is not at the target temperature as it heats up. It will print the ASCII string "Temp: ###" to the terminal every second as feedback on the temperature. Measured in Celsius.

M102 - Extruder on, reverse

Turns the extruder motor on in the reverse direction at the speed specified with M100.

M103 - Extruder off

Turns the extruder off.

M104 - Extruder set temperature

Sets the target temperature for the extruder in Celsius. Accepts P parameter.

Example: M104 P50 sets the extruder target to 50 Celsius.

M105 - Extruder get temperature

Gets the temperature of the extruder. Printed to serial port as ASCII string: "Temp: ###"

TODO

  • Implement arcs.
  • Explore implementing offsets.
  • Remove library dependency.

Bugs

  • None so far, but they are lurking.