CHAPTER 4

image

Configuring the Software

Building a 3D printer and seeing the mechanical bits together for the first time is quite an accomplishment. However, you aren’t done yet. To make the most of your new printer, you need to configure and load the firmware on your printer as well as install software on your computer to control the printer.

This chapter will show you how to configure the firmware for your printer and show you an example of printer controller software for your computer. I will use the Marlin firmware and the Repetier-Host printer controller software to demonstrate how to complete the software setup for a typical RepRap printer. I will also demonstrate some simple modifications to the firmware to add new functions for the LCD panel menu.

If your printer is not a RepRap design or your printer was delivered fully configured, you may want to skim the section on firmware. The section contains a number of insights into how the firmware directs the motors to move the axis. You may find this interesting if you plan to build your own RepRap printer in the future.

I will first discuss printer firmware. If you are building your own printer, you will have to install the firmware before you can use the printer controller software to test the printer for correct orientation of the axis.

Setting up and Configuring the Firmware on Your Printer

Recall the firmware on your printer is responsible for accepting connections from your computer and receiving and executing the G-code commands via the connection. The firmware therefore is the software installed on your printer that makes it work. But it is a bit more complicated than that. The firmware must be configured to execute the commands that control the printer’s axes based on the geometry of those axes. For example, the firmware must know how many steps to turn the motor in order to move a fraction of a millimeter in each direction. Fortunately, there are some excellent tools for figuring out the specifics of the geometry.

In this section, I will demonstrate how to set up and configure the Marlin firmware on your printer. I will show you how to get the firmware, how to configure it for your printer’s geometry, and how to load it on your printer.

Choosing Your Firmware

If your printer arrived without any firmware installed, or you built your own printer, you will need to decide which firmware to use. There are a few firmware choices you can use and Chapter 1 listed the more popular choices. I have found the Marlin firmware to be the best choice for my RepRap printers. Marlin is derived from the Sprinter firmware that was popular among early RepRap adopters. Marlin combines a number of features from Sprinter and other firmware, providing a more comprehensive set of printer functions. It is also one of the few that seem to have regular contributions and are continuing to evolve.

WHICH MARLIN?

It may surprise you to know there are many variants of the Marlin firmware. Most variants are designed for a specific printer vendor or to support a specific hardware feature (like a particular LCD or electronics board). I use the Marlin variant originally developed by Erik van der Zalm (https://github.com/ErikZalm/Marlin). Other variants include the following (listed by printer model/design):

The bottom line here is if your printer vendor (kit or assembled) has its own variant of the Marlin firmware, you should refer to that repository to download and use when configuring your printer.

You may not think this important if all you want to do is operate your printer, but if you are thinking about adding new features to your printer over time, you may find some of those features are supported in Marlin before others. For example, the auto bed leveling feature was added to Marlin as it was being developed.

Getting Started with Marlin

Marlin is written for a number of microcontrollers, including the Arduino Mega. The newer Arduino Mega 2560 microcontroller is a popular choice for hosting Marlin. As such, Marlin is a large, multiple-file sketch that you must download, modify, and compile before uploading it to your printer. In order to compile Marlin, you will need to first download and install the Arduino Integrated Development Environment (IDE). The following sections present a short tutorial on how to download, install, and use the Arduino environment.

WHAT IS AN ARDUINO?

The Arduino is an open source hardware prototyping platform supported by an open source software environment. It was first introduced in 2005 and was designed with the goal of making the hardware and software easy to use and available to the widest audience possible. Thus, you don’t have to be an electronics expert to use the Arduino. This means you can use the Arduino for all manner of projects—from reacting to environmental conditions to controlling complex robotic functions to controlling a 3D printer. The Arduino has also made learning electronics easier through practical applications. For more information about Arduino, visit http://arduino.cc.

Arduino Tutorial

This section is a short tutorial on getting started using an Arduino. It covers obtaining and installing the IDE and writing a sample sketch. Rather than duplicate the excellent works that precede this book, I cover the highlights and refer readers who are less familiar with the Arduino to online resources and other books that offer a much deeper introduction. Also, the Arduino IDE has many sample sketches that you can use to explore the Arduino on your own. Most have corresponding tutorials on the Arduino.cc site.

The Arduino IDE is available for download for the Mac, Linux (32- and 64-bit versions), and Windows platforms. There is also a download for the source code itself so that you can compile it for other platforms or even customize it for you own needs. The current version is 1.0.5. You can download the Arduino IDE from http://arduino.cc/en/Main/Software. There are links for each platform, as well as a link to the source code.

Installing the IDE is straightforward. I omit the actual steps of installing the IDE for brevity, but if you require a walkthrough of installing the IDE, you can see the Getting Started link on the download page, or read more in Beginning Arduino by Michael McRoberts (Apress, 2010). Figure 4-1 shows the Arduino IDE with one of the sample sketches loaded.

9781430268093_Fig04-01.jpg

Figure 4-1. The Arduino IDE

Once the IDE launches, you see a simple interface with a text editor area (a white background by default), a message area beneath the editor (a black background by default), and a simple button bar at the top. The buttons are (from left to right) Verify, Upload, New, Open, and Save. There is also a button on the far right that opens the serial monitor. You use the serial monitor to view messages from the Arduino sent (or printed) via the Serial library. You see this in action in your first project.

Notice that in Figure 4-1 you see a sample sketch (called blink) and the result of a successful compile operation. Notice also at the bottom that it tells you that you’re programming an Arduino Uno board on a specific serial port.

Due to the differences in processors and supporting architecture, there are some differences in how the compiler builds the program (and how the IDE uploads it). Thus, one of the first things you should do when you start the IDE is choose your board from the Tools image Board menu. For most 3D printers, you will want to choose the Arduino Mega 2560 entry. Figure 4-2 shows a sample of selecting the board on the Mac.

9781430268093_Fig04-02.jpg

Figure 4-2. Choosing the Arduino board

Notice the number of boards available. If your 3D printer uses a different board, check the manufacturer’s site for the recommended setting to use. If you choose the wrong board, you typically get an error during upload, but it may not be obvious that you’ve chosen the wrong board. Because I have so many different boards, I’ve made it a habit to choose the board each time I launch the IDE.

The next thing you need to do is choose the serial port to which the Arduino board is connected. To connect to the board, use the Tools image Serial Port menu option. Figure 4-3 shows an example on the Mac. In this case, no serial ports are listed. This can happen if you haven’t plugged your Arduino in to the computer’s USB ports (or hub), or you had it plugged in but disconnected it at some point, or you haven’t loaded the FTDI drivers for the Arduino (Mac and Windows). Typically, this can be remedied by simply unplugging the Arduino and plugging it back in and waiting until the computer recognizes the port.

9781430268093_Fig04-03.jpg

Figure 4-3. Choosing the serial port

Image Note  If you use a Mac, it doesn’t matter which port you choose: either the one that starts with tty or the one that starts with cu will work.

Image Tip  See http://arduino.cc/en/Guide/Howto if you need help installing the drivers for Mac and Windows.

OK, now that you have your Arduino IDE installed, you can connect your printer electronics to your computer using the appropriate USB cable. When you plug in the board, you should see some of the LEDs illuminate, and if your printer has an LCD panel, it may also power on. This is because the electronics board (the Arduino Mega) is getting power from your computer’s USB port. This is normal.

Image Note  While your USB connection can power the Arduino and, in most cases, the LCD panel, it is not enough power to enable the motors, heaters, or any of the 12v systems. This is because the USB port produces only 5v, which is not enough to power all of the components. Thus, all printers require an additional power supply wired through the electronics board.

Go ahead and open the Arduino IDE and choose the correct board and serial port if you have not done so already. Try out the blink sketch by opening it, compiling, and uploading it to your Arduino. Once the sketch starts, you will see the hard-wired LED on pin 13 blink periodically. Once your IDE is installed and you are able to compile the simple blink sketch, you are now ready to open the Marlin firmware and start configuring it for your hardware.

Downloading Marlin

To download the latest version of the Marlin firmware, visit https://github.com/ErikZalm/Marlin and click the Download Zip button located on the right side of the page. Once the file is downloaded, unzip the file and copy or move it to your Documents/Arduino folder.

By default, the Arduino install creates the Arduino folder for you. However, if it does not exist, you can find the default location for project files by checking the preferences and looking for the sketchbook location entry, as shown in Figure 4-4. For example, on Mac OS X, the default location is in your Documents folder.

9781430268093_Fig04-04.jpg

Figure 4-4. Arduino IDE Preferences

In the next section, I discuss the prerequisite values you will need in order to successfully configure Marlin. More specifically, you must calculate the values used in the axis movement. This is one area most 3D printer builders struggle with. If you take the time to gather the correct data and perform the calculations in advance, you will be in a much better state to calibrate your printer.

Indeed, if your calculations are accurate, you may not need to alter the values during calibration. In other words, your axis movement will move precisely 100mm when instructed to do so. I present techniques for calibrating and fine-tuning your printer in the next chapter.

Prerequisite: Do the Math

There are a number of areas that you will need to modify in the Marlin firmware (but you will only be modifying one file). One of those areas involves calculating the value for steps per millimeter that controls axis movement. Another involves calculating how far your extruder motor must turn to move the filament a given distance (also expressed as steps per millimeter).

There are two ways to go about this. First, you can perform the calculations using a formula for each type of axis movement: belt, threaded rod, and geared. Second, you can use the excellent online RepRap calculator from Josef Prusa.

So why would you do the math by hand if you could use a calculator? Is that cheating1? Perhaps, but being one of those type-A personalities, I like to know what is going into the calculations even if I do use a calculator to get the right answer. At least afterward I know it is the right answer (again, type-A). So let’s see how the calculations are done first, and then look at the same calculations using the calculator.

But before we do that, you must gather a certain amount of data about your hardware. You will need to know the number of teeth on each of your drive pulleys (the ones mounted on the motors for belt-driven mechanisms), the spacing or pitch of the belts, the thread pitch for threaded rod–driven mechanisms, and the number of teeth on the gears of your extruder. You will also need to know the number of steps-per-revolution for your stepper motors and the microstep for your stepper motor driver. Typically, 3D printers use Nema 17 stepper motors with 200 steps per revolution and 1/16th microstep. To summarize, you need the following data.

  • Stepper motors
    • Steps-per-revolution
    • Microstep
  • Belt-driven axes
    • Number of teeth on drive pulley
    • Belt pitch (distance between belt notches)
  • Threaded rod-driven axes
    • Thread lead (for single-start screws, thread pitch for multistart screws)
  • Geared extruders
    • Number of teeth on small gear
    • Number of teeth on large gear
    • Effective diameter of the hobbed bolt

Image Note  If you are using a direct-drive or other extruder mechanism, consult your documentation for specifics on calculating the steps per millimeter for the extruder.

Method 1: Manual Calculations

Belt-driven mechanisms for Marlin and similar firmware are calculated using the following equation. Here we derive the steps per millimeter using the number of steps the motor has per a single revolution multiplied by the microstep setting for the driver. This value is then divided by the pitch of the belt (the spacing between the teeth) and the number of teeth in the drive pulley. Wow!

steps_per_mm = (motor_steps_per_rev * driver_microstep) /
                  (belt_pitch * pulley_number_of_teeth)

For example, let’s say we have a typical Nema 17 stepper motor common to almost all 3D printers. It has 200 steps per revolution and the driver microstep is 1/16th. We use the denominator for the value of the microstep. Now, let’s say our drive pulley has 16 teeth and the belt pitch is 2.0mm (GT2). The steps per millimeter is therefore calculated as follows.

100 = (200 * 16) / (2.0 * 16)

Let’s see another example, but this time we will use a T2.5 belt with 20 teeth on the drive gear. Our steps per millimeter is calculated as follows.

64 = (200 * 16)  / (2.5 * 20)

Threaded rod-driven mechanisms are calculated a little differently using the following formula. Here we still need the stepper motor steps per millimeter and the stepper motor driver microstep, but we also need to know the thread pitch—that is, the number of threads to turn one increment (number of millimeters, inches, etc.). We divide the same calculation for the stepper motor by the thread pitch.

steps_per_mm = (motor_steps_per_rev * driver_microstep) / (thread_pitch * thread_starts)

Image Note  The formula is in millimeters. If you use SAE rods, you will have to convert the units. For example, a 5/16-inch threaded rod has 18 threads per inch or 25.4/18 = 1.41112 threads per millimeter.

For example, using the same Nema 17 stepper motors and a 5mm threaded rod (common among Prusa i3 variants) with a 0.8 mm thread pitch, we calculate the steps per millimeter as follows.

4000 = (200 * 16) / 0.8

Let’s see another example but this time we will use a SAE 5/16" threaded rod. Notice I have rounded the value up (the actual value is 2267.735)

2268 = (200 * 16) / 1.4111

Gear-driven axes (the extruder) require a few more calculations. In this case, we need the same values for the stepper motor but also the gear ratio (the number of teeth in large gear divided by the number of teeth in the small gear), which we divide by the diameter of the filament drive (the hobbed bolt) times pi. The formula is as follows.

e_steps_per_mm = (motor_steps_per_rev * driver_microstep) *
                 (big_gear_teeth / small_gear_teeth) /
                 (hob_effective_diameter * pi)

This is the one calculation that trips almost everyone up when building a 3D printer. If you miscount the number of teeth in the gears or measure your hobbed bolt incorrectly, your calculation will be off a bit. This can result in either too much or not enough filament extruded during a print.

For example, your extruder may extrude only 95mm of filament when instructed to extrude 100mm. Since this is such an issue, I will go over the calibration of the extruder in much greater detail in the next chapter. For now, let’s get the calculation as close as possible.

Image Tip  To measure the hobbed bolt diameter, use a digital caliber set to millimeters and measure the inside-most diameter of the bolt at the center of the hobbed area. This will provide a good starting point for finer calibration of the extruder.

For example, using the same Nema 17 motor and a Greg’s Wade hinged extruder with a large gear of 51 teeth and a small gear with 11 teeth, and a hobbed bolt diameter of 7mm, we calculate the steps per millimeters as follows.

674.65 = (200 * 16) * (51 / 11) / (7 * 3.1416)

Let’s see another example. This time, we will use gears with 49 and 13 teeth. Clearly, the difference in gear ratio has a profound effect on the steps per millimeter that the extruder will turn. This is why this calculation is the most error-prone of the three. But never fear, we will get this right in the next chapter.

548.47 = (200 * 16) * (49 / 13) / (7 * 3.1416)

If you feel a little overwhelmed at this point, don’t worry. This is really the hardest part of configuring the firmware. Everything else will be much easier to deal with. If you take your time and get the data right for the calculations, the resulting values should be sufficient to get you close to the correct values and a great deal closer to having the printer calibrated. If, on the other hand, you do not know some of the values for the calculation, you may need to dig a little deeper in your documentation or ask your vendor for the specifics.

Method 2: Using the RepRap Calculator

You may also be thinking that there simply must be a better way. Well, there is! In fact, the online RepRap calculator has many of the common values for axes movement in a drop-down list, making it very easy to calculate the steps per millimeter for the most common drive mechanisms. The only one curiously absent is the gear-driven calculations. I suppose that is because there are so many different extruders out there.

To use the RepRap calculator, navigate to http://calculator.josefprusa.cz/ and observe the formula areas. Figure 4-5 shows the RepRap calculator. Go to the site now and scroll through the calculations available. Notice there are four: belt-driven, gear-driven, layer-height, and acceleration (but no geared calculator). I will go through each of these in turn.

9781430268093_Fig04-05.jpg

Figure 4-5. RepRap calculator

Figure 4-6 shows the calculator for belt-driven mechanisms. Notice there are text boxes for belt pitch and the number of teeth for the drive pulley. There are also drop-down boxes for the stepper motor, stepper motor driver, and belt presets. This last drop-down box will automatically fill in the belt pitch for you, so if you are not sure what the belt pitch is but know the type of belt, the calculator has saved you a possible headache later if you accidentally thought the belt pitch was 2.0, but it was really 2.5. Mistakes like this are a bane for those trying to calibrate their printer. Which is all the more reason to get it right the first time!

9781430268093_Fig04-06.jpg

Figure 4-6. Belt-driven axis calculations

Notice in Figure 4-6 I have entered the same values from the sample calculation in the previous section. As you can see, the numbers are correct. If you prefer to do the calculations by hand or if you want to check any previous calculations, I recommend using the RepRap calculator to check those values. Go ahead and try out the second belt-driven example from the previous section. Is the value shown correct?

Notice something else in the bottom of the figure. This is the G-code (actually an M-code) for setting this value. You can use this command from your printer controller software to make the change on the fly and test it. We will use this technique during calibration.

Figure 4-7 shows the calculator for threaded rod–driven (or lead screw) mechanisms. Once again, we have the same drop-down lists for the stepper motor and the stepper motor driver. Similar to the belt-driven calculator, we have a preset option to choose from the most common threaded rods used. Wow, can this be any easier?

9781430268093_Fig04-07.jpg

Figure 4-7. Lead screw–driven axis calculations

Notice the gear ratio text boxes. This calculator also allows you to calculate the steps per millimeter for threaded rods driven by gears. That is, some 3D printers use a stepper motor connected via a gear-driven rod. For those, use the large gear divided by the small gear to get the gear ratio. Use 1:1 as shown in the figure for threaded rods mounted directly to stepper motors. Once again, the M-code for setting the value on the fly is provided for us.

Go ahead and plug in the data from the previous section to check the calculations. Are they correct? You bet!

The next calculator shown in Figure 4-8 is used to calculate the optimal layer height for your Z axis. This allows you to calculate what the best layer height is for your Z-axis mechanism. Since most Z-axis systems are threaded rod–driven, the values for the calculations use many of the same variables: stepper motor steps per revolution, thread pitch, and gear ratio. You can also specify your desired layer height to check its accuracy estimate.

9781430268093_Fig04-08.jpg

Figure 4-8. Optimal layer height calculations

Image Note  As of this printing, the calculator is not accurate. I explain choosing an optimal layer height next.

I have read some 3D printer build documents that suggest using a layer height of 0.25 because it is easier to calculate the number of layers there are in a calibration object. For example, there are exactly 40 layers in a 10mm tall object. Other build documents suggest using a layer height of 0.3mm to do calibration. Neither of these may be optimal in the sense you will get a perfectly sized object. It will depend on the actual height of the object.

For example, if you use 0.2mm or even 0.25mm to print a 10mm tall object, we expect it to print exactly 10mm tall because 0.2 and 0.25 divide evenly into 10. However, if you use 0.3, it cannot be divided evenly into 10 and thus if you print a 10mm tall object with a 0.3mm layer height, it will be only 9.9mm tall. This is considered a nonaccumulating error because it affects the final height of the object due to the rounding error on division. Figure 4-9 shows the measurement of a 10mm tall test cube printed with a 0.3mm layer height next to the same cube printed with a 0.25mm layer height.

9781430268093_Fig04-09.jpg

Figure 4-9. 10mm cube printed with 0.3mm and 0.25 layer heights

Notice that the cube on the left is slightly shorter than the one on the right.3 The one on the left measures 9.97mm while the one on the right measures 10.08mm. To avoid printing objects that are too short, I use a layer height that is closest to producing an accurate height. That is, a layer height with the lowest rounding error.

The last calculator is another calculation that is used to set expectations. Figure 4-10 shows the maximum acceleration calculator.

9781430268093_Fig04-10.jpg

Figure 4-10. Acceleration calculations

This calculator allows you to enter the acceleration in the form of millimeter per second squared (default if 3000), the maximum distance of the axis in millimeters, and the desired speed in millimeters per second. This speed is the speed at which your axis will move across its range. For belt-driven systems, 120mm/s is considered a fast but stable speed (consider it a goal).

Notice I chose to enter 200mm for the axis length and 120mm/s for the desired speed. The chart shows a vertical axis that represents the maximum speed the axis can achieve over the maximum length. As you can see, even with an acceleration value of 3000, the axis can at most achieve a movement peak of just under 800mm/s, but only when the axis reaches its midpoint. From there, the speed drops off because the axis must decelerate. This may not see very interesting or important at this point (and you’re right), but it is something to consider when you start fine-tuning your prints to get the fastest print possible.

Now that we have the calculations for our axis movement, we have all of the mathematical values we need to perform the configuration. So let’s get to it!

Configuring Marlin

Configuring Marlin for use with your printer involves modifying the Configuration.h file in a number of places. Depending on the hardware used in your printer, you may need to modify only a few locations. The areas most often modified include the following (listed in the order they appear in the file). I explain how to modify each of these in the following sections.

  • Author and Version
  • Baudrate
  • Electronics Board
  • Temperature
  • Endstops
  • Axes Movement
  • EEPROM
  • LCD Panel

Begin by opening the Marlin firmware by navigating to the folder you unzipped and placed in your Arduino folder in your Documents folder. Under that folder is another folder named Marlin. Within that folder is the Marlin.ino file. Double-click the file. This will automatically open the Arduino IDE. Alternatively, you can first open the Arduino IDE and then use the File image Open menu to locate and open the file. Once the file is open, locate the Configuration.h tab and click it. You are now ready to edit the file.

Image Note  The following sections refer to “the file,” which is henceforth the Configuration.h file because there is no other file you should be changing for basic configuration steps. I present the changes in order, starting from the top of the file. If you are using a different Marlin variant or a newer version, the order of the changes in the file may be slightly different. Use the search option to locate the code if this is the case.

I recommend making one change at a time and saving the file after each change. Use the File  Save menu item to save the files.

Author and Version

Changing the author and version is optional, but can be very helpful if you have several printers or if you plan to modify the printer at a later date. I don’t change the date and time values. Rather, I allow the firmware to compile with the __DATE__ and __TIME__ directives, which are the defaults. This means the date and time will be filled in when the firmware is compiled.

However, I do change the author. This helps me identify printers that I have made custom firmware changes (or I just set up myself). The following code shows the lines changed in the file. Find those lines and change the author to yourself.

#define STRING_VERSION_CONFIG_H __DATE__ " " __TIME__ // build date and time
#define STRING_CONFIG_H_AUTHOR "Dr. Charles Bell" // Who made the changes.

So how do you read these values on your printer? When you connect to your printer using a printer controller software like Repetier-Host and have the log turned on, you can use the M115 code to see these values in the lower panel, as shown in Figure 4-11.

9781430268093_Fig04-11.jpg

Figure 4-11. Showing author, version from firmware in Repetier-Host

Baud Rate

The next area to change sets the baud rate of the serial (USB) connection. Most will choose 250000 but in some cases you may want to set it slower. Locate the code to change it as follows.

#define BAUDRATE 250000

Electronics Board

The firmware must know what electronics board you are using. You can find a long list of the types of boards supported (called motherboards) in the file near the top. Listing 4-1 shows the code comments that define the list and an example of how to set the motherboard value to a RAMPs setup with a single extruder, a fan (pointed at the extruder nozzle), and a heated bed. Choose the value that matches your own board.

Listing 4-1. Selecting the Electronics Board

//// The following define selects which electronics board you have. Please choose the one that 
matches your setup

// 10 = Gen7 custom (Alfons3 Version) "https://github.com/Alfons3/Generation_7_Electronics"
// 11 = Gen7 v1.1, v1.2 = 11
// 12 = Gen7 v1.3
// 13 = Gen7 v1.4
// 2  = Cheaptronic v1.0
// 20 = Sethi 3D_1
// 3  = MEGA/RAMPS up to 1.2 = 3
// 33 = RAMPS 1.3 / 1.4 (Power outputs: Extruder, Fan, Bed)
// 34 = RAMPS 1.3 / 1.4 (Power outputs: Extruder0, Extruder1, Bed)
// 35 = RAMPS 1.3 / 1.4 (Power outputs: Extruder, Fan, Fan)
// 4  = Duemilanove w/ ATMega328P pin assignment
// 5  = Gen6
// 51 = Gen6 deluxe
// 6  = Sanguinololu < 1.2
// 62 = Sanguinololu 1.2 and above
// 63 = Melzi
// 64 = STB V1.1
// 65 = Azteeg X1
// 66 = Melzi with ATmega1284 (MaKr3d version)
// 67 = Azteeg X3
// 7  = Ultimaker
// 71 = Ultimaker (Older electronics. Pre 1.5.4. This is rare)
// 77 = 3Drag Controller
// 8  = Teensylu
// 80 = Rumba
// 81 = Printrboard (AT90USB1286)
// 82 = Brainwave (AT90USB646)
// 83 = SAV Mk-I (AT90USB1286)
// 9  = Gen3+
// 70 = Megatronics
// 701= Megatronics v2.0
// 702= Minitronics v1.0
// 90 = Alpha OMCA board
// 91 = Final OMCA board
// 301 = Rambo
// 21 = Elefu Ra Board (v3)

#ifndef MOTHERBOARD
#define MOTHERBOARD 33
#endif

Temperature

The next area to change concerns the temperature sensors. More specifically, the type of temperature sensor you have to measure the temperature of the extruder or print bed. Listing 4-2 shows the documentation with the possible values and the code changes to choose a 100k thermistor, which is the most common type for RepRap kits. Check with your vendor to choose the correct sensor.

Image Caution  This is another area where novice 3D printer builders sometimes get confused. If you choose the wrong sensor type, your printer may heat the extruder to the wrong temperature, possibly even overheating it. Take some time to make sure you get this part right. Don’t hesitate to contact the vendor to verify the setting.

Listing 4-2. Setting the Temperature Sensors

//===========================================================================
//=============================Thermal Settings  ============================
//===========================================================================
//
//--NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table
//
//// Temperature sensor settings:
// -2 is thermocouple with MAX6675 (only for sensor 0)
// -1 is thermocouple with AD595
// 0 is not used
// 1 is 100k thermistor - best choice for EPCOS 100k (4.7k pullup)
// 2 is 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup)
// 3 is mendel-parts thermistor (4.7k pullup)
// 4 is 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !!
// 5 is 100K thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (4.7k pullup)
// 6 is 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup)
// 7 is 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup)
// 71 is 100k Honeywell thermistor 135-104LAF-J01 (4.7k pullup)
// 8 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup)
// 9 is 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup)
// 10 is 100k RS thermistor 198-961 (4.7k pullup)
// 60 is 100k Maker's Tool Works Kapton Bed Thermister
//
//    1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k
//                          (but gives greater accuracy and more stable PID)
// 51 is 100k thermistor - EPCOS (1k pullup)
// 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup)
// 55 is 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (1k pullup)

#define TEMP_SENSOR_0 1
#define TEMP_SENSOR_1 0
#define TEMP_SENSOR_2 0
#define TEMP_SENSOR_BED 1

Notice there are four settings. The values support up to three extruders and one for the bed. If your printer does not have a second (or third) extruder, set those to 0. Likewise, if your printer does not have a heated bed, set that to 0 to turn off monitoring of the sensor. In this example, there is a single extruder and a heated bed, both with 100k thermistors.

Image Note  If your printer has multiple extruders, you should also change the #define EXTRUDERS 1 statement to indicate the number of extruders that are included.

Endstops

The next area is another area that can cause some hiccups. This is partly because the variable names are a bit confusing.4 In this case, we may need to do several things, but it depends on your choice of electronics and the type of endstops. For example, if you are using a typical RAMPS setup with mechanical endstops that are opened until triggered, you may need to enable the endstop pull-up resistors and set the endstop behavior to the opposite of the default. That is, the default is normally closed, which means closed until triggered. If you use a mechanical endstop that is normally open, which means open until triggered, you need to invert the logic. Listing 4-3 shows the lines involved, with the ones I changed in bold.

Listing 4-3. Endstop Settings

// coarse Endstop Settings
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the
endstop pullup resistors


#ifndef ENDSTOPPULLUPS
  // fine Endstop settings: Individual Pullups. will be ignored if ENDSTOPPULLUPS is defined
  // #define ENDSTOPPULLUP_XMAX
  // #define ENDSTOPPULLUP_YMAX
  // #define ENDSTOPPULLUP_ZMAX
  // #define ENDSTOPPULLUP_XMIN
  // #define ENDSTOPPULLUP_YMIN
  // #define ENDSTOPPULLUP_ZMIN
#endif

#ifdef ENDSTOPPULLUPS
  #define ENDSTOPPULLUP_XMAX
  #define ENDSTOPPULLUP_YMAX
  #define ENDSTOPPULLUP_ZMAX
  #define ENDSTOPPULLUP_XMIN
  #define ENDSTOPPULLUP_YMIN
  #define ENDSTOPPULLUP_ZMIN
#endif

// The pullups are needed if you directly connect a mechanical endswitch between the signal and
ground pins.

const bool X_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
const bool Y_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
const bool Z_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
const bool X_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
const bool Y_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop.
#define DISABLE_MAX_ENDSTOPS
//#define DISABLE_MIN_ENDSTOPS

OK, so if you read the code changes, you may see something odd. Notice that the only thing I did was uncomment out the #define to disable the maximum endstops. This is because my printer does not have any maximum endstops. You don’t see other changes because it just so happens the default settings will work for me—only minimum, mechanical normally open endstops.

As I said, this is one area that can be an issue. If you get the settings wrong, your endstops will not be triggered correctly. Recall from Chapter 3 we used the M119 code to get the values of the endstops. If you perform this preflight test and the endstops do not behave correctly (they aren’t reporting “triggered” or “open” in response to your tests), try changing the ?_MIN_ENDSTOP_INVERTING value to false.

Image Tip  Always double-check your wiring connections before changing these values! It can be wildly irritating to switch the settings and retest, only to discover nothing has changed. If your wiring is wrong, no amount of fiddling with the source code will fix it.

Another thing to check if the endstops are not triggering correctly is whether you need the pull-up resistors. This may be dependent on the type of endstops. For example, I used the MakerBot mechanical endstops on one of my printers (they are normally open). They needed the pull-up resistors enabled to work correctly. Sometimes fiddling is the quickest way to get the endstops working. If in doubt, leave the pull-up resistors on.

There is one other portion of the code that you may need to change with respect to endstops, shown as follows. This defines how the endstops are used in the homing process. If your endstops are at the minimum position of the axes, make sure you check these settings and set them accordingly. If you fail to do so, or they get changed incorrectly, the axis will ram into the frame/mechanical portions during homing. You do not want that to happen.

// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1

Axes Movement

The next segment of code to change is the place where you will need those values from the calculations in the last section. But first, we need to set the min and max values for each axis. Locate the following code. This is where you set the build volume for your printer. For example, if you are building a Prusa i3 printer, your values may be similar to these.

// Travel limits after homing
#define X_MAX_POS 180
#define X_MIN_POS 0
#define Y_MAX_POS 180
#define Y_MIN_POS 0
#define Z_MAX_POS 80
#define Z_MIN_POS 0

So how do you know which values to use? For the X and Y axes, it is a simple matter of measuring the size of your build plate where the left-to-right length is the X axis and the forward-to-back length is the Y axis. You should check the movement of all of your axes to double-check that they move through their entire available length.

Image Tip  It is especially important to check the Z axis because the movement can generate enough mechanical force to cause damage if it runs into the hard parts (frame).

However, you should also consider how your build plate is configured. That is, if you are using a glass build plate on top of the heated build platform (the most common setup), consider where you are going to use binder clips or some other clip to hold the glass to the heated build platform. More specifically, make sure you subtract the length that these clips use. We need to do this so that the extruder nozzle will not run into the clips during movement.

For example, I use metal binder clips on my Prusa i3 printers on the front and back of the build platform. I set the Y-axis minimal endstop to stop the axis prior to when the extruder nozzle reaches the binder clip. I then measure from that point to the binder clip on the back of the build platform. This distance measures 180mm on my printer. You should check your setup equally as careful.

My X axis also has a travel limitation, but this is because I am using a belt tensioner set to the absolute minimum (so I can adjust it throughout its entire length). This also restricts movement of the X axis by about 20mm.

The Z axis is a little harder to determine and may take some careful measuring. I like to set the Z-axis travel really low (for example, 80), and then when I experiment with the axis during preflight checks I can adjust it. For example, I raise the extruder to its maximum after homing, and then measure the remaining clearance to hard obstructions and increase the max for the Z axis incrementally until I establish the maximum safe Z-axis travel distance. This is the safest way to do this.

Image Caution  Setting any axis to travel beyond its maximum length after homing is asking for trouble! If your axis runs into a hard obstruction, it can damage the movement mechanisms. For belt-driven systems, this can be a damaged belt or a damaged belt retention clip. For threaded rod–driven mechanisms, it can result in one of the Z-axis motor connectors slipping and therefore canting the axis, which can lead to breakage of plastic parts. It is always best to set these values conservatively and adjust them during preflight checks.

OK, so now I’ve scared you. Never fear, it isn’t all that bad and your printer won’t explode if you get the settings wrong. Just follow the advice as I’ve given by using conservative values until you can confirm the actual values.

Image Tip  If you use conservative values for your axis movement, but have the axis positioned more than 1.5 times the maximum movement, the home action for your axis and the mechanism may not run all the way to the endstop. You can simply home the axis again if this occurs. Once you have the correct maximum range, homing should work no matter where the axis is positioned on its travel.

Next, we need to enter those values from the calculations. It’s just a single line of code as shown next. Here we see an array of values that represent the X, Y, and Z axes, and extruder steps per millimeter settings in that order (X, Y, Z, extruder). Plug those in place of the defaults. For example, my Prusa i3 belt-driven X and Y axes have 100 steps per millimeter, my Z axis is 4000, and my extruder value is 524. Notice I use two decimals. Had any of my values needed to be expressed with more, I would likely use only four decimal places.

#define DEFAULT_AXIS_STEPS_PER_UNIT   {100.00,100.00,4000.00,524.00}

Wow, is that it? Yep. Once you do the calculations and get that right, you only need to enter the values in the array.  However, there is one other line you may need to change. For printers that use smaller, finer threaded rods, you may need to change the feed rate (sometimes called acceleration multiplier) to match.

For example, a Prusa i3 with 5mm threaded rods cannot handle the default acceleration settings. You can tell if this is a problem when you hear your Z motors chatter, skip steps, or simply refuse to turn more than a few microns at a time. That is, the axis moves OK slowly, but fast movement (say over about 4–5mm at a time) doesn’t work. The first line is the default settings and the second is the maximum values that I determined for my Prusa i3.

#define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 25}      // (mm/sec)
#define DEFAULT_MAX_FEEDRATE          {500, 500, 2.5, 25}    // (mm/sec)

Note the change in bold. This is for the Z axis. Set this to 1 if you experience movement problems and you have double-checked that the voltages on your stepper driver match your stepper motors. Increase it slowly by 0.5 until you reach an acceptable, reliable feed rate.

EEPROM

The next area concerns the behavior of the EEPROM. The EEPROM is a special nonvolatile memory area on the Arduino where the firmware can store the values for much of the variables. For instance, we can set the maximum travel for an axis on the fly as we saw in the RepRap calculator examples. Without using EEPROM, using the commands only updates the value in runtime memory. When the printer is turned off, the value reverts to what was specified in the code. Thus, using EEPROM can be very helpful in fine-tuning your printer calibration. Listing 4-4 shows the code for turning on the EEPROM feature (it is off by default).

Listing 4-4. EEPROM Settings

// EEPROM
// the microcontroller can store settings in the EEPROM, e.g. max velocity...
// M500 - stores paramters in EEPROM
// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
// M502 - reverts to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
//define this to enable eeprom support
#define EEPROM_SETTINGS
//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
// please keep turned on if you can.
#define EEPROM_CHITCHAT

Notice we have comments that tell us there are a number of codes we can use to control the EEPROM (if enabled). There is a code to store values, read them, and revert them. Thus, with these values enabled, we can do a preflight check of the Z-axis travel and adjust it accordingly, and then save it to EEPROM. You can at any time see the values stored in EEPROM or revert to the defaults if something goes wonky.

Image Tip  If you make changes during calibration and write them to EEPROM, always change your file to match any adjustments you make using the EEPROM feature. This will avoid nasty surprises if you later compile some unrelated feature and reupload the firmware. Imagine finding your Z axis won’t travel more than 80mm after a minor change to your firmware.5

LCD Panel

Finally, if your printer has an LCD panel, you must change the firmware to enable it, else your LCD will either power on but display lines of solid blocks, or perhaps display garbage, or partial or no data. Locate the code shown in Listing 4-5. It should be down the file a ways.

Listing 4-5. LCD Settings

 //LCD and SD support
//#define ULTRA_LCD  //general lcd support, also 16x2
//#define DOGLCD  // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family)
//#define SDSUPPORT // Enable SD Card Support in Hardware Console
//#define SDSLOW // Use slower SD transfer mode (not normally needed - uncomment if you're getting
volume init error)

//#define ENCODER_PULSES_PER_STEP 1 // Increase if you have a high resolution encoder
//#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
//#define ULTIMAKERCONTROLLER //as available from the ultimaker online store.
//#define ULTIPANEL  //the ultipanel as on thingiverse

// The MaKr3d Makr-Panel with graphic controller and SD support
// http://reprap.org/wiki/MaKr3d_MaKrPanel
//#define MAKRPANEL

// The RepRapDiscount Smart Controller (white PCB)
// http://reprap.org/wiki/RepRapDiscount_Smart_Controller
#define REPRAP_DISCOUNT_SMART_CONTROLLER

// The GADGETS3D G3D LCD/SD Controller (blue PCB)
// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel
//#define G3D_PANEL

// The RepRapDiscount FULL GRAPHIC Smart Controller (quadratic white PCB)
// http://reprap.org/wiki/RepRapDiscount_Full_Graphic_Smart_Controller
//
// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder:
http://code.google.com/p/u8glib/wiki/u8glib
//#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

// The RepRapWorld REPRAPWORLD_KEYPAD v1.1
// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626
//#define REPRAPWORLD_KEYPAD
//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click

// The Elefu RA Board Control Panel
// http://www.elefu.com/index.php?route=product/product&product_id=53
// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARUDINO library folder:
https://github.com/kiyoshigawa/LiquidCrystal_I2C
//#define RA_CONTROL_PANEL

As you can see, there are a lot of LCD panel options. Fortunately, this is one of the best-documented areas of the code. Notice there are links to most of the LCD panels supported. Choose the one that matches your LCD and uncomment the #define as I have done. For example, RepRap Discount Smart Controller made the LCD panel I used for this example.

Image Tip  If you sourced your parts yourself but don’t recall the vendor of your LCD panel, look at the PCB that it is mounted on. The manufacturer typically imprints their name on the PCB. If there it is not there, check with the vendor to make sure you get the right settings.

I have used some of the other panels listed here and even some clever clones. For example, I once had a RepRap Discount Smart Controller that was reproduced by another vendor. It had all the right parts in all the right places but the PCB was red, not white. It did not work with the RepRap Discount Smart Controller setting, so I did some further research and discovered it was not up to specification. Thus, it pays to make sure the parts you are buying are indeed the genuine article.

Notice also that some LCD panels require additional Arduino libraries. You can find these libraries in the ArduinoAdditions folder in the folder you unzipped and copied to your Documents/Arduino folder. If you need any of these, close the IDE and copy the subfolders to the Libraries folder for your platform, and then restart the IDE. The new libraries will be detected and used on the next compile.

If you scroll down a bit more, you will see a number of lines of code about the LCD panels. Ignore those. You need only set the correct #define from the preceding listing to enable your LCD. However, if you choose the wrong value, you most likely will encounter strange behavior on the display (wrong data, corrupted values, not refreshing, etc.), or the rotary button won’t work. If this happens, check your setting, correct it, compile, and upload the firmware.

WHAT ABOUT THE OTHER STUFF?

As you can see, there are a lot of other variables and definitions that you can change. What I’ve shown here are the typical ones you will need to change. Fortunately, the file contains a lot of comments that can help you determine if you should change the settings. Some, like the endstops, can be a little confusing but most are straightforward. If you are building a typical RepRap Prusa-style printer, what is shown here will suffice. Consult your vendor’s instructions or ask them if there are other settings you should change.

Now that we have our Marlin code configured, we must now compile and upload it to our printer.

Compiling and Uploading

I like to compile the firmware before I attempt to upload it. You can use the Compile button on the toolbar (the leftmost button) in the Arduino IDE to do this. You may see a few warnings in the other Marlin files. These are OK and are not normally an issue. What you want to make sure is that there are no errors and you see a successful compile message like the one shown here.

Binary sketch size: 133,188 bytes (of a 258,048 byte maximum)

If you encounter errors, scroll up in the messages window and read the error messages. Try to find the first error listed. Since the only file you changed was Configuration.h, you should only see errors related to your editing of the file. If you get errors, consult the examples and correct them, and then recompile. Sometimes a single error can produce a number of false errors, such that when the first one is fixed the false hits vanish. For example, unbalanced curly braces or a missing semicolon can cause false errors in several lines.

Now that the firmware compiles, it’s time to connect to your printer and upload the sketch. To do so, click the Upload button (second from the left). Even though you just compiled the code, the upload process will compile it again and begin transferring it to your printer’s electronics. When it is done, you should see a message stating that the compile is complete, and the progress bar will disappear.

Once the upload is complete (the progress bar in the lower right of the edit screen is gone), check the LCD panel. After a brief reboot, you should see the initial information screen on the display. For example, if you have a character-based LCD, you should see a menu similar to the one shown in Figure 4-12.

9781430268093_Fig04-12.jpg

Figure 4-12. Information screen (Marlin LCD support)

Once your upload is complete, your printer is now ready to use! You can now perform your preflight checks as described in Chapter 3.

For the really adventurous types (you know how you are), I’ve included some minor modifications that you may find interesting. The following sections briefly describe some simple modifications to extend the Marlin LCD menus.

Project: Customizing Marlin

One of the cool things about open source software and indeed firmware based on the Arduino platform is that it is easy to modify. But why would you?

If you have built your printer and included an LCD panel, you may encounter cases where there isn’t a menu item or you’d like to change one or more menu items. Take some time to explore the various menus on the LCD panel.  Don’t select any for execution, rather, just scroll through them.

LCD? WHAT LCD?

LCD panels are a relatively new feature for some printers. If your printer doesn’t have an LCD panel, you have been using the printer via your printer controller software. What an LCD panel can do for you is allow you to manage the printer without the computer. You can do things like print from an SD card, home the axes, preheat the heaters, and more.

One of the things that I noticed when I first began working with the Marlin firmware (and most RepRap printer firmware) is the lack of some operations that I performed regularly using the printer controller software. For example, in Marlin, there isn’t a separate home operation for each axis—only one for auto homing all three axes. Similarly, there is no menu item to move the build plate “out” of the printer by moving the Y axis to its maximum.6

Image Note  The extend function assumes your Y axis moves your print bed. This is the most common RepRap design, but it may not apply to other printers. For example, the Printrbot Simple moves the build plate on the X axis and the extruder arm as the Y axis. However, moving the extruder arm back out of the way on Printrbot has the same effect as moving the print bed out on RepRap designs. That’s because all movements are considered as movements of the extruder relative to the platform, and regardless of which piece is actually moving, a move to Y-maximum will “move” the extruder at the back of the platform.

Wouldn’t it be nice if you could add these functions? Well, you can! I will show you how to add these features to the LCD menus in the following sections.

Adding Custom Menu Items

To add custom menu items, we will first need to define a text string to use for each menu item, and then add code to insert the menu item in the Prepare menu. I used the Prepare menu because that is where the auto home function is located. Adding the per-axis homing seems to fit with it, and indeed I will show you how to add the items after the auto home function.

First, we need to add the #define statements.7 Locate the language.h file (by clicking the tab) and search for the MSG_AUTO_HOME label. Listing 4-6 shows the new menu items in bold in context within the file. Here we add the new lines to define the menu item text along with a label to match. Remember these labels because you will need them in the next step.

Image Tip  Use the small down arrow located on the right side of the tab bar to pull down a menu of all of the files associated with the project. Locate the file you want and click it. This will make it the focus of the edit window in the Arduino IDE.

Listing 4-6. Adding Message Strings

#define MSG_AUTO_HOME "Auto Home"
#define MSG_X_HOME "Home X Axis"
#define MSG_Y_HOME "Home Y Axis"
#define MSG_Z_HOME "Home Z Axis"
#define MSG_EJECT "Extend Bed"

Next, we need to add the menu items. Locate the ultralcd.cpp file, open it (by clicking the tab), and locate the MSG_AUTO_HOME label. Listing 4-7 shows how to add the new menu items. Notice I included the appropriate G-code and variable for each.

Listing 4-7. Adding New Menu Items

MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
MENU_ITEM(gcode, MSG_X_HOME, PSTR("G28 X0"));
MENU_ITEM(gcode, MSG_Y_HOME, PSTR("G28 Y0"));
MENU_ITEM(gcode, MSG_Z_HOME, PSTR("G28 Z0"));
MENU_ITEM(gcode, MSG_EJECT, PSTR("G0 Y180"));

The way the MENU_ITEM() function works with the gcode option is the menu item is added with the text described in the next parameter (e.g., MSG_X_HOME), and when the menu item is selected, the G-codes in the next parameter are sent to the printer via the serial interface. For example, when you choose the auto home X function, it executes the G28 X0 to move the X axis to its 0 position (home.)

Go ahead and compile the firmware. You should not see any compilation errors. If you do, check your code modifications to make sure they match the ones in Listing 4-7. Once it compiles, upload it to your printer. When the printer is rebooted, use the rotary wheel to select the Prepare menu and scroll down to the new menu items. You should see them appear as shown in Figure 4-13.

9781430268093_Fig04-13.jpg

Figure 4-13. Custom menu items

Go ahead and try each one out. But make sure your printer axes are clear before you do! Also, make sure you have homed the Y axis before executing the Extend Bed menu item.

Image Caution  Never move an axis without first homing it. Failure to home the axis first either by a home function, like the ones demonstrated here, or with G-code commands, can result in the axis trying to run past its maximum travel limit. Failing to home the axes before moving them can damage your printer.

There you have it—four new menu items to make using the printer without a computer a bit easier. Now you can home each axis individually, as well as extend the bed to make removing objects easier.

But wait, let’s get really nerdy and add a welcome message. The next section shows you how to do it.

Displaying a Welcome Message

Another thing you can do is to add a greeting message to the LCD panel so that when the printer is started, it will print a short message before showing the main menu. In this case, we simply want to display the message, “Welcome, <yournamehere>!”. Once again, we need to add the message text to the language.h file and edit the ultralcd.cpp file.  First, open the language.h file and add the following code. If you completed the last project, just add it after those lines.

#define MSG_WELCOME_SCREEN "Welcome, Chuck!"

Next, open the file with your Arduino IDE and scroll down to about line number 176. We will edit the lcd_status_screen() method. Listing 4-8 shows the method with the new lines of code shown in bold.

Listing 4-8. Adding a Welcome Message

boolean welcomed = false;
/* Main status screen. It's up to the implementation ... */
static void lcd_status_screen()
{
    // do a simple welcome screen.
    if (!welcomed) {
        START_MENU();
        MENU_ITEM(gcode, MSG_WELCOME_SCREEN, PSTR("M119"));
        delay(1000);
        welcomed = true;
        END_MENU();
    }
    if (lcd_status_update_delay)
        lcd_status_update_delay--;
    else

Here we add a Boolean variable and set it to false. We then add a condition to the status screen method so that if the Boolean is false, we show the message and set the Boolean to true. This way, we only show the screen once. This is important because this method is called whenever you return to the main menu on the LCD. You really don’t want to see the welcome message each time, do you?

Notice the code block after the conditional. We use a new menu as a means to display the menu.8 Thus, we initiate a new menu, display a menu item with the welcome message, and if the message is selected, simply execute the endstop status command. This is harmless because it doesn’t move any axes or affect the hot end—or anything else for that matter. Notice right after this is a delay method call. This is a timer that will do nothing for one second. Thus, the menu will disappear after one second. Cool, eh? The code block ends with the closing of the menu.

Once you type this code in, compile, and upload the firmware, your printer will reset and you should see the new welcome message appear like shown in Figure 4-14.

9781430268093_Fig04-14.jpg

Figure 4-14. Welcome message on printer

Now that we’ve compiled the firmware and uploaded it, and then modified it to include some new features, let us return to the computer software, install it, and then run the preflight tests discussed in Chapter 3. But before you do that, you need to make sure you have a printer controller program installed on your printer. The following sections describe how to prepare your computer for working with your printer.

Installing Software on Your Computer

Recall that the software needed for using a 3D printer involves a CAD program to create objects (.stl); a CAM program to convert the objects into a file that the printer can use to create the object (.gcode); and a printer control program to send the G-codes to your printer, control the axes, set the temperature of the hot end, and perform other maintenance operations. If the printer has an LCD panel, the printer controller program may not be used much, but I find the printer controller program very helpful to use when preparing the printer for printing, as well as for some maintenance procedures. This is especially true for calibration tasks.

In this section, I will demonstrate how to set up the Repetier-Host software on your computer. I will delay a discussion about CAD software and return to that topic in a later chapter. For now, we will explore using existing objects from Thingiverse.

Choosing Your Printer Controller

Chapter 1 discussed the various alternatives for printer controller software. Among the more popular choices are Printrun and Repetier-Host. Both of these permit you to integrate with CAM software. In the case of Printrun, the access to the CAM functions and printer controller features into the interface. Repetier-Host uses a series of dialog panels to arrange the features.

Despite the popularity of Printrun, I think Repetier-Host is a better choice. I base this on the fact that Repetier-Host has features that Printrun lacks, including direct editing of the .gcode file, the ability to arrange objects on the build platform, configuration files for different printers, and logging of the codes sent to the printer and its responses. Esthetically, Repetier-Host seems more complete than other alternatives.

Thus, I have chosen to use Repetier-Host to demonstrate how to use printer controller software to get the most out of your printer. For example, if you want to execute the preflight checks from Chapter 3, Repetier-Host will make those tasks easy.

Repetier-Host is available for download from www.repetier.com/download. You will find downloads for Linux, Mac OS X, and Windows. All of these are open source products and free for you to use. The documentation for installation is available at www.repetier.com/documentation/repetier-host/rh-installation-and-configuration/.

Image Note  The Linux version actually runs a special installation of the Windows version and Mono to execute the .NET Framework.

Currently, the Mac OS X version has a slightly different user interface than the Windows and Linux versions. However, despite a different layout, the features are largely the same except for the object placement features available on Windows but not Mac. For example, Figure 4-15 shows the Windows version printer control panel and Figure 4-16 shows the Mac OS X printer control panel. While the Windows version has graphical controls, the Mac OS X version has simple buttons. Neither is necessarily easier to use.

9781430268093_Fig04-15.jpg

Figure 4-15. Printer control panel (Windows)

9781430268093_Fig04-16.jpg

Figure 4-16. Printer control panel (Mac OS X)

Installing Repetier-Host

Fortunately, installing Repetier-Host is very easy. The Windows version contains an installer that is easy to use, requiring the usual install dialogs and license agreement. On Mac OS X, it is a simple matter of downloading the ZIP file, opening it, and dragging it to your Applications folder. It is a bit more work to install on Linux, but nothing a savvy Linux user would be surprised to see. That is, you may need to install a number of prerequisites depending on whether Mono and a host of other libraries are installed. I installed Repetier-Host on a fresh Ubuntu machine and the installer automatically installed the resources. It took a while, but once installed it worked correctly.

Image Tip  You may need to install a USB driver on Windows in order to connect your printer. Check your printer documentation for any required drivers. You can also try the driver located at http://pjrc.com/teensy/serial_install.exe.

Once you have your printer controller software installed (Repetier-Host), you are now ready to plug in the USB cable from your computer to your printer.

Connecting Your Printer

The next step is to connect to your printer. But before you can do this, you need to set up a profile for your printer. Click the Printer Settings button on the toolbar located to the right of the Repetier-Host window.

There are four tabs on the dialog you can use to set up your printer. The first tab allows you to set the communication parameters, as well as create the profile. To add a new printer profile, click the Add button and give the new printer configuration a name. For example, I like to name the profile after the type of printer and any information about the printer configuration. Thus, I have profiles for PrintrBot, Prusa i2 PLA, Prusa i2 ABS, and Prusa i3.  If you haven’t opened the dialog, do so now. Figure 4-17 shows the communication tab for the Printer Settings dialog.

9781430268093_Fig04-17.jpg

Figure 4-17. Communications tab for printer settings dialog

As I mentioned, click the Add button and name the profile, and then click Create. Next, modify the parameters to match the configuration of your printer and USB port. For example, choose the port, speed, stop bits, and so on. Check your printer documentation to ensure you have the right settings. Once you have those settings correct, click the Behavior tab. Figure 4-18 shows the Behavior page.

9781430268093_Fig04-18.jpg

Figure 4-18. Behavior page for printer settings dialog

On this page, you can set the defaults for a variety of printer settings. Most of the defaults are fine, just change the heat settings to match your printer. Note that you can change these values manually and set them in the G-code file when the object is sliced. Click the next tab. Figure 4-19 shows the Dimension tab.

9781430268093_Fig04-19.jpg

Figure 4-19. Dimension page for printer settings dialog

This is where you set the maximum dimensions of your build area. Be sure to verify that the values match your settings in the firmware. The example shows the settings for my PrintrBot Simple. When you have those values, click the next tab. Figure 4-20 shows the Advanced page.

9781430268093_Fig04-20.jpg

Figure 4-20. Advanced page for printer settings dialog

You can use this page to call a filter script to call after slicing. You might want to do this if you want to modify the G-codes in any way. This is really an advanced technique that you can safely ignore for all but the most unique prints.

Once you have all of the settings checked, click the Apply button and then close the dialog. You can now connect the USB cable to your printer if you haven’t already, and then use the Connect button on the toolbar to connect to your printer.

When the printer connects, you will see the connection response in the lower portion of the screen. If you do not get a connection, go back and check your settings. The most common issue is with which port you need to use. Check the following Repetier-Host documentation for platform-specific walkthroughs.

Once you get a successful connection, you can start running your preflight tests, as described in the next section.

Running the Preflight Tests

The preflight tests in Chapter 3 are ideal for checking out your printer for the first time. I summarize these as steps you can follow to execute the checks. Except for the first two steps, you can do these in any order.

  1. Move all of the axes to their center locations. For the Z axis, make sure it is at least 30mm above the print bed.
  2. Turn on the main power for your printer.
  3. Use the printer control panel in Repetier-Host to set the extruder temperature to 100 and turn it on, and then click the temperature curve tab to the left. This opens a special chart that displays the temperature of all the hot bits in your printer. You should see the heat for the extruder rising and you should feel heat radiating from the extruder nozzle after a few moments. If you do not see any temperature values increasing, turn off the printer and wait for the extruder to cool. This indicates the temperature sensor is either not set properly in the firmware or is not connected properly. Correct the problem and repeat the process.

    Image Caution  Never touch the extruder or heated print bed while it is heating. They can and do get hot enough to burn flesh. If you have a temperature probe for your multimeter, use that instead. Somewhat less reliable are infrared heat detectors. They will work for this task—to tell if the item is getting hot, but due to the reflective properties of the components, they may not give an accurate reading. A temperature probe is a better tool for measuring precise temperatures.

  4. Check the heated print bed (if installed). Set the temperature to 60 and turn it on the printer control panel, and then click the temperature curve tab. You should see the temperature increase and should be able to feel heat radiating from the print bed. If you do not see any temperature values increasing, turn off the printer and wait for the extruder to cool. This indicates the temperature sensor is either not set properly in the firmware or is not connected properly. Correct the problem and repeat the process.
  5. Move each axis 10mm in the positive direction. Verify that they all move in the correct direction; the X axis should move to the right, the Y axis toward the front, and the Z axis upward.
  6. Manually trigger each endstop and use the M119 code to check their status. All should read TRIGGERED when closed.
  7. Last, but not least, load filament into your extruder and heat your extruder to 180 for PLA or 210 for ABS. Wait for the extruder to reach the desired temperature (as shown in the temperature curve display) and use the printer control panel to extrude a small amount of filament.

Congratulations! Your printer is moving its axis in the right directions and the hot end is heating. Let us take a brief detour and talk about one feature that is becoming standard on newer printers: printing over the network.

Project: Building a 3D Printer Print Server

If you have looked at the latest printers from MakerBot and some other professional-class printer vendors, you may have noticed they are starting to outfit the printers with networking and wireless connectivity. This is really cool, but does it mean you need to upgrade to the new printers to get these features?

Fortunately, for RepRap printers the answer is no, you do not have to buy a new printer! The OctoPrint software (http://octoprint.org) is a 3D printer network print server that allows you to control your printer remotely. OctoPrint is also available for the Raspberry Pi (https://github.com/guysoft/OctoPi), which allows you to use a lightweight computer as a network print server to control your printer. In fact, you can set it up to be wireless!

Image Note  OctoPrint works only with printers that use G-codes. MakerBot printers can accept G-codes, but as of this writing, OctoPrint did not officially support MakerBot printers. Look for this to be added in future versions (or send the developer lots of fan e-mails asking for it).

This section will explain how to use a Raspberry Pi computer to run a special version of the OctoPrint software that will enable you to print and control your printer over the network. As an added bonus, if you also add the Raspberry Pi camera (or equivalent), you can monitor your printer by watching a streaming video of the print process. You can also set up time-lapse photos so that you can make a short time-lapse video of your build. How cool is that?

WHAT IS A RASPBERRY PI?

The Raspberry Pi is a small, inexpensive personal computer. Although it lacks the capacity for memory expansion and can’t accommodate onboard devices such as CD, DVD, and hard drives, it has everything a simple personal computer requires. That is, it has two USB ports, an Ethernet port, HDMI (and composite) video, and even an audio connector for sound.

The Raspberry Pi has an SD drive9 that you can use to boot the computer into any of several Linux operating systems. All you need is an HDMI monitor (or DVI with an HDMI-to-DVI adapter), a USB keyboard and mouse, and a 5V power supply—and you’re off and running.

Image Tip  You can also power your Raspberry Pi using a USB port on your computer, provided it can provide at least 700mA (raspberrypi.org/wp-content/uploads/2012/04/quick-start-guide-v2_1.pdf). In this case, you need a USB type A male to micro-USB type B male cable. Plug the type A side into a USB port on your computer and the micro-USB type B side into the Raspberry Pi power port.

The board is available in several versions and comes as a bare board costing as little as $35.00 (for the version with Ethernet). It can be purchased online from electronics vendors such as SparkFun and Adafruit. Most vendors have a host of accessories that have been tested and verified to work with the Raspberry Pi. These include small monitors, miniature keyboards, and even cases for mounting the board.

Raspberry Pi Tutorial

The Raspberry Pi is a personal computer with a surprising amount of power and versatility. You may be tempted to consider it a toy or a severely limited platform, but that is far from the truth. With the addition of onboard peripherals like USB, Ethernet, and HDMI video, the Raspberry Pi has everything you need for a lightweight desktop computer. If you consider the addition of the GPIO header, the Raspberry Pi becomes more than a simple desktop computer, and fulfills its role as a computing system designed to promote hardware experimentation.

The following sections present a short tutorial on getting started with your new Raspberry Pi, from a bare board to a fully operational platform. A number of excellent works cover this topic in much greater detail. If you find yourself stuck or wanting to know more about beginning to use the Raspberry Pi and more about the Raspbian operating system, see Learn Raspberry Pi with Linux by Peter Membrey and David Hows (Apress, 2012). If you want to know more about using the Raspberry Pi in hardware projects, an excellent resource is Practical Raspberry Pi by Brendan Horan (Apress, 2013).

Getting Started

As mentioned in the “Required Accessories” section, you need an SD card (or a microSD with the microSD adapter), a USB power supply rated at 700mA or better with a male micro-USB connector, a keyboard, a mouse (optional), and an HDMI monitor or a DVI monitor with an HDMI adapter. However, before you can plug these things into your Raspberry Pi and bask in its brilliance, you need to create a boot image for your SD card.

Installing a Boot Image

The process of installing a boot image involves choosing an image, downloading it, and then copying it to your SD card. The following sections detail the steps involved.

Once you select an image and download it, you first unzip the file and then copy it to your SD card. There are a variety of ways to do this. The following sections describe some simplified methods for a variety of platforms. You must have an SD card reader/writer connected to your computer. Some systems have SD card drives built in (Lenovo laptops, Apple laptops and desktops, and so on).

Windows

To create the SD card image on Windows, you can use the Win32 Disk Imager software from Launchpad (https://launchpad.net/win32-image-writer). Download this file, and install it on your system. Unzip the image if you haven’t already, and then insert your SD card into your SD card reader/writer. Launch the Win32 Disk Imager application, select the image in the top box, and then click WRITE to copy the image to the SD.

Image Caution  The copy process overwrites anything already on the SD card, so be sure to copy those photos to your hard drive first!

Mac OS X

To create the SD card image on the Mac, download the image and unzip it. Insert your SD card into your SD card reader/writer. Be sure the card is formatted with FAT32. Next, open the System report (hint: use the Apple menuimageAbout this Mac).

Click the card reader if you have a built-in card reader, or navigate through the USB menu and find the SD card. Take note of the disk number; for example, it could be disk4.

Next, open the Disk Utility and unmount the SD card. You need to do this to allow the Disk Utility to mount and connect to the card. Now things get a bit messy. Open a terminal and run the following command, substituting the disk number for n and the path and name of the image file for <image_file>:

sudo dd if=<image_file> of=/dev/diskn bs=1m

At this point, you should see the disk-drive indicator flash (if there is one), and you need to be patient. This step can run for some time with no user feedback. You will know it is complete when the command prompt is displayed again.

Linux

To create the SD card image using Linux, you need to know the device name for the SD card reader. Execute the following command to see the devices currently mounted:

df -h

Next, insert the SD card or connect a card reader, and wait for the system to recognize it. Run the command again:

df -h

Take a moment to examine the list and compare it to the first execution. The “extra” device is your SD card reader. Take note of the device name; for example, /dev/sdc1. The number is the partition number. So, /dev/sdc1 is partition 1, and the device is /dev/sdc. Next, unmount the device (I will use the previous example):

umount /dev/sdc1

Use the following command to write the image, substituting the device name for <device> and path and name of the image file for <image_file> (for example, /dev/sdc and my_image.img). Set the size of the image to match the size of your SD card; for example, I use 4M for my 4MB card.

sudo dd bs=4M if=<image_file> of=<device>.

At this point, you should see the disk-drive indicator flash (if there is one), and you may need to be patient. This step can run for some time with no user feedback. You will know it is complete when the command prompt is displayed again.

Setting up the Raspberry Pi Hardware

The hardware you need includes a Raspberry Pi (type B with 512Mb RAM), a Raspberry Pi camera, and a case for each. You can find the Raspberry Pi and case, as well as a Raspberry Pi camera from SparkFun (sparkfun.com/categories/233), Adafruit (adafruit.com/category/105), or Maker Shed (makershed.com/Raspberry_Pi_Boards_and_Accessories_s/227.htm). You may also be able to purchase these on online auction sites. Figure 4-21 shows a Raspberry Pi assembled in a case.

9781430268093_Fig04-21.jpg

Figure 4-21. Raspberry Pi hardware setup

Notice that I placed the Raspberry Pi near the printer and mounted the camera on an impromptu mount. If you were mounting this permanently, you may want to consider making a fixed mount for the Raspberry Pi and camera. Notice also that I have a light illuminating the build area. I recommend using the brightest light you can find, like an LED light on a flexible shaft.

Image Note  I normally use my Raspberry Pi on my Prusa i3. I moved it to my Printrbot Simple to give you an idea of the versatility of the Octopi server.

The case for the camera is also available on one of these sites, but you may want to consider getting an inexpensive one to start with and make a better one sourced from Thingiverse once your printer is fully operational. I will show you one such example next.

The figure shows a Raspberry Pi mounted in a clear case and the camera mounted in a special case I printed on another printer. The camera case is a customized version (called a Remix) of a case by alexspeller (thingiverse.com/thing:192364); I added a bolt to the clamp for a more secure mount. The clear Raspberry Pi case was purchased from Adafruit (adafruit.com/products/1140).

Notice how the camera is oriented. Since the printer used in the example is a Printrbot Simple, the print build is small enough that I can mount the camera fairly close to the print area. If you are adding the OctoPi to a printer with a larger print volume, you may need to position the camera in a location out of the way of the print bed so that printed objects don’t run into it.10

Go ahead and assemble your Raspberry Pi and camera in whatever case you decided on (there are so many to choose). Mount it near your printer and point the camera at the middle of the print bed. Be sure to leave some room for the axis movement. If you are using a simple camera case that doesn’t have a mounting mechanism, you can use good old gray camera tape to secure it in place (or the ever-ready zip tie).

Once the unit is positioned and the camera pointed correctly, plug in your network and power supply but don’t plug it into your home power. We need to get the software ready to go first.

Setting up the Raspberry Pi Software

To set up the software, first download and unzip the boot image from https://github.com/guysoft/OctoPi/archive/devel.zip. Alternatively, you can navigate to http://octoprint.org/download and follow the instructions and links there.

OK, now the file is unzipped. Use the procedures for loading a boot image onto the SD card to expand the image to your SD card. Once you’ve done that, you’re ready to boot up the Raspberry Pi. Go ahead and insert the SD card and power everything on. We’ve got a few more steps to do, but these require connecting to the OctoPi server. Make sure your Raspberry Pi is connected to your network.

Image Note  If you are using a Raspberry Pi and camera, the OctoPi boot image is already set up and ready to go. If you are using a different camera or want to set up OctoPi on a different boot image, see the https://github.com/foosel/OctoPrint/wiki/Setup-on-a-Raspberry-Pi-running-Raspbian page for detailed instructions on setting up OctoPi manually. You can connect to the server via a terminal with the ssh [email protected]l command using the default password of raspberry (unless you changed it).

Connecting and Using OctoPi

To connect to the OctoPi server, you should first ensure that the network cable is plugged in, and then wait for the Raspberry Pi to boot. This can take about 3–5 minutes. If you have access to the Raspberry Pi LEDs, wait until all of the LEDs for networking illuminate or begin blinking. Once fully booted, open your browser on your laptop and use the URL octopi.local to connect.

Image Note  The octopi.local address will work on Mac and Windows, however, not all Linux distributions come with the tools needed to make this work. If you use Linux, check to ensure the Avahi software is loaded.

The first thing you need to do is click the Connection link and connect to the printer. Figure 4-22 shows the OctoPi connection area. You should be able to leave the defaults and click Connect. Once you connect, the connection area will close. Now, take a look at the main window, as shown in Figure 4-23.

9781430268093_Fig04-22.jpg

Figure 4-22. Connection area

9781430268093_Fig04-23.jpg

Figure 4-23. OctoPi main window

Before you can print, you need to upload one or more G-code files to the server. I have uploaded a test cube to the server. Notice in Figure 4-23 that I’ve hovered over the file and the server has given me a few statistics on the file.

I have also activated the printer’s extruder heater, which is depicted in the Temperature tab, also shown in the figure. To do this, you click the Control tab to reveal the printer control functions. Figure 4-24 shows the Control tab view. As you can see, there are controls for moving the axes, homing, and setting the temperature of the extruder and print bed. Notice the coolest part of this—the camera view! When you use this tab, you will see a streaming, live video feed from the Raspberry Pi. You can use this page to watch your printer over the network.

9781430268093_Fig04-24.jpg

Figure 4-24. Control tab

The GCode Viewer tab lets you view the layers of the file you are printing. You can also get a bunch of statistics about the print from the links on that page. Figure 4-25 shows the GCode Viewer tab.

9781430268093_Fig04-25.jpg

Figure 4-25. GCode Viewer tab

The next tab is a terminal viewer that you can use to watch the G-Codes being sent to the printer, as well as any messages being received from the printer. This is the same sort of information you see at the bottom of the Repetier-Host application. Figure 4-26 shows the Terminal tab.

9781430268093_Fig04-26.jpg

Figure 4-26. Terminal tab

The next tab is the Timelapse tab. Here you can set up a time-lapse capture and manage existing time-lapse movies. Figure 4-27 shows the Timelapse tab with a time-lapse movie that was created earlier.

9781430268093_Fig04-27.jpg

Figure 4-27. Timelapse tab

The use of this tab and its controls are not very clear in the documentation. You cannot change the time-lapse settings if there is a print in progress or if a printer is not connected. You must therefore wait until after you have connected to a printer and before you start to print to turn on the time-lapse feature. Notice in the figure that I have it set to record a snapshot in a frame of the movie on each Z-axis change. This creates a small, fast movie of your print.

To see a time-lapse movie, wait until the print is done and visit this tab. If the movie isn’t ready yet, you may have to refresh the page after a couple of minutes. OctoPi names the movie using the name of the object you printed. To view the movie, click the tiny icon to the right of the file name. The first one deletes the movie. Figure 4-28 shows the movie in progress.

9781430268093_Fig04-28.jpg

Figure 4-28. Time-lapse movie

Notice how the movie has the OctoPrint icon branded. If you’d like, you can turn this off in the Settings dialog (see the link in the upper-right corner of the dialog).

Well, that’s it! When you complete this project, you will have a fully functional network-enabled printer. What we’ve done is move the printer controller software from our computer to the small Raspberry Pi (which is clearly up to the task), letting us control our printer without tying up a USB connection on our laptop. Oh, and we get some really cool video capabilities in the bargain!

If you have not tried this project, I encourage you to do so at your first opportunity. You may want to wait until your printer is fully calibrated, but as you can see, the OctoPi has all of the controls you need to run the preflight tests—even over the network! How cool is that?

Summary

This chapter has covered a lot of ground. Not only did I present the Marlin firmware and how to configure it for a new printer (or to replace the firmware on an existing printer), I also showed you some cool ways to modify Marlin to add new menus. This is the most important part of building a 3D printer. Getting the values in Marlin set correctly, or at least close, will make calibration a lot easier.

I also showed you how to install a printer controller program on your computer. I took a minor detour (still related to printer control software) and showed you how to make almost any Marlin- (or similar variant) enabled printer into a network printer (or wireless if you prefer). The best part was the camera action. Way cool trick there!11

In the next chapter, I will show you how to check and calibrate your printer for accuracy. If you have the correct geometry and calculations in your firmware—or at least are very close—the calibration steps should be a matter of fine-tuning your settings.

___________________

1Check out the features of the average high school and college-level graphing calculator. Those things can solve complex calculus problems with a few simple entries. Now, that’s cheating!

2Note the repeating decimals. This indicates a slight rounding error in the calculations. This is usually not a big deal, but may be the source of very minute differences.

3Granted, this is a very small difference. Interestingly, since it is not an accumulated error, a 100mm object with a 0.3mm layer height would be 99.9mm tall.

4To me, they are named strangely.

5Can you guess how I know how this feels? It only took me a day to discover my blunder. Do as I say, not as a I do (have done).

6Interestingly, this feature can be found on the fifth-generation MakerBot Replicator Desktop 3D printer.

7You don’t strictly have to do this because you can hard-code the text string, as you will see in the next project, but it is convention to use #define statements to locate all of the text strings in a single file. It makes for easier maintenance, especially if the strings are reused in several places.

8OK, so it is a hack. It works!

9Secure Digital (SD): A small removable memory drive the size of a postage stamp (see http://en.wikipedia.org/wiki/Secure_Digital).

10Talk about your extreme close-ups! Sadly, this will likely reposition your camera so that it is taking pictures of the wall or your own mug staring at the print (we all do it) or depending on how firm your camera mount is, it can knock parts off the print bed.

11It is a rare and precious gem of a gadget indeed that doesn’t require us to spend thousands of dollars replacing a perfectly good and functional printer for the swanky new model (not that there is anything wrong with that).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset