How to connect klipper to Makerbot Replicator 2X?

i’m back from vacation too but sandly to me this means less free time but i’m still looking at it.

that’s my source for the reverse pin

this could be some random doc and even talk about a different version of the board but still to consider.

!!!UPDATE: probably the chinglish transation is just stating that the motor driver circuit board have to be mounted with a different phisycal orientation, and have nothing to do with the direction pin !!!

hope to be able to test something in the next days. meanwhile here is the config file i’m preparing so far, still lot to fix so please don’t consider it final in any way

# This file contains common pin mappings for the Makerbot
# Mightyboard. To use this config, the firmware should be compiled for
# the Atmel atmega1280.

# See docs/Config_Reference.md for a description of parameters.

[stepper_x]
step_pin: PD6
dir_pin: !PD7
enable_pin: !PD4
microsteps: 16
rotation_distance: 32
endstop_pin: ^!PC7
position_endstop: 152
position_max: 153
position_min: -120
homing_speed: 50

[stepper_y]
step_pin: PL5
dir_pin: !PL7
enable_pin: !PL4
microsteps: 16
rotation_distance: 32
endstop_pin: ^!PC6
position_endstop: 77
position_max: 78
position_min: -84
homing_speed: 50

[stepper_z]
step_pin: PL1
dir_pin: PL2
enable_pin: !PL0
microsteps: 16
rotation_distance: 8
endstop_pin: !PC5
position_endstop: 0
position_max: 230
position_min: 0

[extruder]
step_pin: PA3
dir_pin: PA2
enable_pin: !PA5
microsteps: 16
rotation_distance: 33.238
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PE5
sensor_type: ADS1118
sensor_pin: PE6
spi_software_miso_pin: PH2
spi_software_sclk_pin: PE2
spi_software_mosi_pin: PE7 
control: pid
pid_Kp: 26.414
pid_Ki: 1.115
pid_Kd: 156.5054
min_temp: 0
max_temp: 280


[extruder1]
step_pin: PA0
dir_pin: PK7
enable_pin: !PA1
microsteps: 16
rotation_distance: 33.238
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PE3
sensor_type: MAX6675
sensor_pin: PE6
spi_software_miso_pin: PH2
spi_software_sclk_pin: PE2
spi_software_mosi_pin: PE7 
control: pid
pid_Kp: 26.414
pid_Ki: 1.115
pid_Kd: 156.5054
min_temp: 0
max_temp: 280


[heater_fan extruder_fan]
pin: PH4

[heater_fan extruder1_fan]
pin: PE4

[fan]
pin: PG5

[heater_bed]
heater_pin: PH5
sensor_type: ATC Semitec 104GT-2
sensor_pin: PF3
control: pid
pid_Kp: 70.037
pid_Ki: 1.710
pid_Kd: 717.000
min_temp: 0
max_temp: 130

[mcu]
serial: /dev/serial/by-id/usb-MakerBot_Industries_The_Replicator_741373637373518160F0-if00
restart_method: stk500v1


[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

Makerbot firmware sets x, y, a and b to 118 and z to 40 via eeprom defaults. Their software
sets x, y, a and b to 20 while preheating and then to 127 for printing (via G130). This
apparently was done to reduce power when preheating and may be a concern for Replicator2X
with heated bed and dual extruders? Need to see if this functionality is needed and implement
a command to set the digipots (currently can only be set via printer.cfg)
[mcp4018 x_axis_pot]
scl_pin: PA6
sda_pin: PD5
wiper: 1.0
scale: 1.0

[mcp4018 y_axis_pot]
scl_pin: PA6
sda_pin: PL6
wiper: 1.0
scale: 1.0

[mcp4018 z_axis_pot]
scl_pin: PA6
sda_pin: PL3
wiper: 0.315
scale: 1.0

[mcp4018 a_axis_pot]
scl_pin: PA6
sda_pin: PA4
wiper: 1.0
scale: 1.0

[mcp4018 b_axis_pot]
scl_pin: PA6
sda_pin: PJ7
wiper: 1.0
scale: 1.0

[display]
lcd_type: hd44780_spi
spi_software_mosi_pin: PC0
spi_software_sclk_pin: PC1
#miso not used, dummy pin.
spi_software_miso_pin: PJ3
latch_pin: PC3

click_pin: PG2
back_pin: PJ6
up_pin: PJ5
down_pin: PJ4

[output_pin lcd_power]
#has to be low for Rep2 low=5v, high=3.3v?
pin: PA7
static_value: 0

[output_pin lcd_led1]
pin: PC2
static_value: 1

[pca9632 led]
color_order: BGR
initial_BLUE: 1.0
initial_GREEN: 0.0
initial_RED: 0.0

[output_pin BEEPER_pin]
pin: PH3
pwm: True
value: 0
shutdown_value: 0
cycle_time: 0.001
scale: 1000

[gcode_macro M300]
gcode:
{% set S = params.S|default(1000)|int %}
{% set P = params.P|default(100)|int %}
SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
G4 P{P}
SET_PIN PIN=BEEPER_pin VALUE=0

[gcode_macro START_PRINT]
gcode:
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
# Start bed heating
M140 S{BED_TEMP}
# Use absolute coordinates
G90
# Reset the G-Code Z offset (adjust Z offset if needed)
SET_GCODE_OFFSET Z=0.0
# Home the printer
G28
# Move the nozzle near the bed
G1 Z5 F3000
# Move the nozzle very close to the bed
G1 Z0.15 F300
# Wait for bed to reach temperature
#M190 S{BED_TEMP}
# Set and wait for nozzle to reach temperature
M109 S{EXTRUDER_TEMP}

[gcode_macro END_PRINT]
gcode:
# Turn off bed, extruder, and fan
#M140 S0
M104 S0
M106 S0
# Move nozzle away from print while retracting
G91
G1 X-2 Y-2 E-3 F300
# Raise nozzle by 10mm
G1 Z10 F3000
G90
# Disable steppers
M84

## <---------------------- SAVE_CONFIG ---------------------->
## DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
##
## [extruder]
## control = pid
## pid_kp = 27.746
## pid_ki = 1.666
## pid_kd = 115.493


I just received a 2X that I’d like to try kipper on. Any help you can give me on getting the firmware installed? I’ve followed the klipper instructions to compile it but not sure how to install it via USB.

Hi @dockterj, I had been wanting to update my MakerBot Replicator 2 to klipper ever since I started using it on my MakerGear M2 a few weeks ago. The official klipper repo has an example config for a MightyBoard, but I found it didn’t match up with mine, so I’m not sure what that is targeted at. I have a MightyBoard Rev G. I also ran into problems when I tried to flash it.

I was going to give up, until I found this thread, and your repo. First off, let me say thank you for your work on getting this working. I ran into a few troubles setting it up, but I was able to get it working, so I wanted to give some feedback here (maybe to help others), and ask a few questions as well.

I initially installed klipper using a pre-made mainsailos raspberry pi image, so I was still a little confused by the instructions telling me to “Clone this repo and do the normal installation steps”, since I had not done any of that originally. I tried deleting the old repo, and cloning yours. I then ran the install-octopi.sh (from klipper’s install instructions), and it seemed to configure some things, but it didn’t seem to set everything up completely, and I still couldn’t get moonraker to connect to the klipper service.

What I ended up doing was installing the kiauh installation helper (GitHub - th33xitus/kiauh: Klipper Installation And Update Helper), which I had used a couple times before on my other printer. I used it to uninstall klipper (again), and then went into the settings and pointed it to your repo instead of the original klipper repo, and ran the installation again from there (I believe I had to create a file with a list of repos to select from and added yours there). After that everything was happy. kiauh also automates flashing the firmware from its interface. This time it flashed the first time I tried it.

In the config file I had to change the USB device. Your example used:
serial: /dev/serial/by-id/usb/MakerBot_Industries_The_Replicator_A413936383135181D010-if00
My printer instead shows up as:
serial: /dev/serial/by-id/usb-MakerBot_Industries_The_Replicator_A4139373530351A0F031-if00
Also this worked for me:
serial: /dev/ttyACM0
This is what most other examples use. Is there a reason not to use this (seems more generic)

I also tweaked my axes limits/homing positions, and bumped some speeds and accelerations. I have my x/y accel running reliably at 5000mm/s2 and my z axis speed at 25mm/s. I also updated the START_PRINT macro to detect if the the heated bed is configured, and only run the preheat codes on it if it is present. I also disabled the SET_GCODE_OFFSET, because I want to modify this in the more general klipper way (in the stepper_z section, with overrides from the Z-Offset options). I also added a filament purge at the front left corner of the bed. Here is my START_PRINT macro for anyone interested.

[gcode_macro START_PRINT]
gcode:
  {% set has_heated_bed = True if ('heater_bed' in printer.configfile.config) else False %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
  # Set nozzle temperature
  M104 S{EXTRUDER_TEMP}
  {% if has_heated_bed %}
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
    # Start bed heating
    M140 S{BED_TEMP}
  {% endif %}
  # Use absolute coordinates
  G90
  # # Reset the G-Code Z offset (adjust Z offset if needed)
  # SET_GCODE_OFFSET Z=-0.01
  # Home the printer
  G28
  # Move the nozzle up a little
  G1 Z5 F{10*60}
  # Go to purge location
  G0 X-1 Y0 F{200*60}
  # Move the nozzle very close to the bed
  G1 Z0.15 F{5*60}
  # Wait for nozzle to reach temperature
  M109 S{EXTRUDER_TEMP}
  {% if has_heated_bed %}
    # Wait for bed to reach temperature
    M190 S{BED_TEMP}
  {% endif %}
  G92 E0 ; zero extruder
  G1 E25 F{5*60} ; purge nozzle
  G1 X2 Y0 Z0.15 F{10*60} ; slow wipe
  G1 X5 Z0.5 F{10*60} ; lift
  G92 E0 ; zero extruder

With all of this I was able to delete all of my start gcode from my slicer (which included some now unsupported gcodes), and replace it all with the START_PRINT macro. It still does not do anything about lowering stepper currents during preheat, but since I don’t have a heated bed, and I am not using the stock power supply, so it isn’t an issue. I also had to change my machine defenition (in the slicer) to put the origin at the front left corner, instead of the center of the build plate. This could easily have been kept it in the center by changing the position_endstop, position_min, and position_max in the config, but I am fine with the origin moving.

I also found that my LEDs were flickering when the nozzle is heating, so I modified the cycle rate by adding this to the [extruder] section:

pwm_cycle_time: 0.001

The temperature oscillated a bit too, so I ran a PID auto-calibration, and my values were:

control: pid
pid_kp: 20.421
pid_ki: 0.959
pid_kd: 108.740

Lastly, a few questions…

  1. What still needs to be done, or what doesn’t this support?
  2. What does it take to get this merged back into klipper? From my testing I would say this is fairly complete and functional (at least for my Replicator 2 printer).
  3. The update manager tells me that klipper has an update. I assume I don’t want to do this update, because it will probably overwrite this custom code with stock klipper (hence the question about getting it merged back in)?
  4. What else can I do to help move this forward?

Thanks!

Kebes,

Your notes about installation are great. I used a Mainsail OS image so glossed over a couple of steps. I’ll add to my list to create better install instructions until this is in upstream.

I’m not sure why your serial device is different. Perhaps it is a rev h vs rev g change. The only reason to use the by-id device instead of the tty in /dev is that the by-id device won’t ever change. Depening on how many devices you plug in and the order they are plugged in your makerbot may be a different tty.

What are you running for max_velocity and max_z_accel?

I like the changes you made to the START_PRINT macro. In general I am trying to have a simple upgrade path for these printers and having one start print macro that works if you have a hbp or not is great!

I’m not sure which LEDs were flickering? The PCA9632 handles pwm in hardware. Where did you add the pwm_cycle_time line?

With regards to your questions:
1 - Apart from testing and fixing bugs, the only things left that I have on my list are:
a - In the ADS1118 code, track errors for each channel separately.
b - Track down an issue with the LDC buttons which are forcing a double click instead of a singld click.
c - Finalize the sample config file (better start/end script, set motor hold currents correctly, led color should track the temperature while heating)
2 - I’d like to start getting pieces of this merged into upstream but we may need to wait for a few more people to be actively using it. Until then I’ll maintain this fork.
3 - Are you using octopi or mainsail? I’m using mainsail and it doesn’t have an option to upgrade from custom repos.
4 - I appreciate the feedback! Can you let me know if there are any other printer features that I’ve missed, either in config or that would require more code to support?

-Jake

Thanks for the info.

I have been diving deep into macros, and have become pretty good at them. I can help out there. I have been working on the LED color control, and have something that is almost complete. I will post here when that is done, unless there is somewhere else you want me to do that.

For the LED color stuff, I don’t remember the exact behavior of the colors, but I think it started out blue while heating and still cold, and as it approached the target temp it transitioned to red, then went white once at the target temp. I think it also booted up as white, and only turned blue once the target was set. Then a normal cooldown (like end of print, or manually changed) just stayed white, but if it was shut off due to an idle timeout then it went blue. Does that sound right? Is there some other behavior that we want, or that would be cool, or more useful? I started playing with having it pulse full red briefly while actively heating (so mostly blue, but pulsing red occasionally), and I kind of like that because then you can tell the difference between heating, and idle cooldown. But I want feedback on what people would want it to do.

I will also continue making improvements to the start/end gcode. I only have a Replicator 2, with no heated bed and only a single extruder, so I can’t fully test those things, but I should be able to make the macros conditional on whether those exist. I can also look into the motor hold current stuff a little.

As for the LED flickering, I have added some extra white LEDs to the inside of the printer, that are powered directly off of the main power supply. I think when the nozzle is heating it draws enough current to droop the voltage a little, and I see that as flickering on those LEDs. What I changed was the cycle rate of the extruder heater to be much faster, so that difference is no longer visible. I added pwm_cycle_time: 0.001 to the [extruder] section in printer.cfg. The default for this is 100ms, which is very visible. I am not sure if this is a common problem, or if it is related to my power supply (which is not stock, because the stock one died).

I am using mainsail, and in the update manager in that was showing an upgrade for klipper, but I’m assuming that was looking at the main repo and not yours. Now it is showing an error there, and giving me options to “recover” (I’m assuming that means reinstall from the official repo). Anyway, I’m just ignoring that for now, but it would be nice if it had a way of pointing to a custom repo (not your fault though, I know).

Thanks,
Kevin

[printer]
kinematics: cartesian
max_velocity: 500
max_accel: 5000
max_z_velocity: 25
max_z_accel: 100

Thanks Kevin - that is the same behavior that I have with updates in Mainsail - just ignore it and don’t upgrade. If I push more changes to the repo there is an easy way to update via the command line. I’m working through tuning from beginning to end this weekend and will let you know what else I find.

I’m going to start creating PRs for some of this to push upstream. I’ll start with a small change in the SPI module that eliminates the need for dummy pins for write or read only devices.

Jake

Hi, Ive had a Rep2 for about 10 years. Its great to give her an update.
Thanks for the great work.

Currently running this on a Makerbot Replicator 2 with HBP.

I was getting M127 Unknown Command errors and the extruder fan wasnt working.
Changing G Code flavour in Cura from Makerbot to Marlin fixed this. Is this the correct setting?

Aso had to add the following to the “Start G-code” in Cura

START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0}

Apart from that the only issues I have are no progress on LCD which I believe can be fixed with the Octoprint M73 Progress plug in (currently in middle of a long print so cant test yet)

And getting the double press on the LCD buttons so cant adjust any on the Tune settings.

Overall really happy, huge improvement in print quality.

Soldering up an ADXL345 to a Pico to try out the resonance tuning…

Cheers

Thanks for the feedback. You definitely want to change the g code flavor to marlin.

My impression is that people have moved on from LCDs to touchscreens, so you are probably correct on the adding the m73 plug in. I haven’t looked into what that would take for a more generic solution. Let me know how it works out for you.

I’ll work on the button issue next and will post here when completed.

Did you tune the extruder rotation distance? Was my example pretty close? Have you tuned your printer for faster speeds?

I have an accel hooked up to an arduino but haven’t gotten to the point of tuning that yet. Still chasing down some extruder issues.

What upgrades have you made to your Rep2? If you added a HBP did you upgrade the power supply as well?

Cheers,
Jake

Hi Jake,

I haven’t done any calibration yet other than by eye. I had to reduce flow to .92 which is pretty standard for the brand of filament i use, so I think youre spot on.

My first resonance tests were pretty bad (loose belts). My X axis idler is rooted.
Im installing new ali x ends this weekend, will tighten belts and try again.

Only upgrades are the Carls HBP and arms. PSU is upgraded to 24v 800w

The new x ends take lm8uu not the smaller stock lm8suu bearings.
Im going to try turning some solid PTFE bushings tomorrow instead of ordering/waiting for new ones.

Will post before and after results when its done

Cheers
Matt

Thanks for putting this post together. I am in the same boat but very new to Klipper but tottally hooked. I am having trouble changing the repository for Klipper in KIUAH.

Like you had done the mainsail OS didn’t want to flash over usb to the mighty board

Thanks again
Tim

In order to use a different repo from kiauh you must create/edit a custom file for kiauh to get the repo list from. From the ssh terminal, create/edit the kiauh repos file:

sudo nano kiauh/klipper_repos.txt

Add the following lines to the file, then save and close:

https://github.com/Klipper3d/klipper,master
https://github.com/dockterj/klipper,master

Run the script:

./kiauh/kiauh.sh

Choose option 6 [Settings], then option 1 [Set custom Klipper repository], the option 1 [dockterj/klipper → master]

Follow the prompts to switch to the repo, then uninstall/install as needed.

After the custom repo is installed, then you can go back into kiauh and build/program the firmware (menu option 4 [Advanced]), and it should connect now to the MakerBot.

@kebes22 Good news! I got Klipper to flash and connect to my Rep2x. For some odd reason the Make and Flash Advanced in KIAUH option only worked when I set the baud rate to 57600 (It previously had Sailfish installed on this Rev G board). After that I could disable the extra low level option and it flashed just fine.

It threw out an ADC out of temp range and shutdown Klipper right away (My thermocouple was wired but not connected to the heater block at the time). It seemed like it did not turn off my extruder heater though…

I was initially having serial connection issues but it is talking to the MCU now. Here is the log file below.

I will run some more tests tomorrow. My kids are sleeping and there apparently was a blob of PLA stuck to the heater block and causing it to smoke. No fire alarms tonight or Dad will be in big trouble!
Thanks for the help.

klippy (1-30-23).log (788.6 KB)

Ducky - I’m not sure why the extruder heater would have stayed on but if you are running a makerbot replicator2 you have the wrong config. I think the config file you have now is pulled from upstream and is for original makerbots and clones, not rep2 and rep2x units. You need to pull the code and example config file from my repo (GitHub - dockterj/klipper: Adding support for MakerBot Replicator 2). Let me know if you need some help in the steps needed to do that.

You will need to reflash the mcu as well. I don’t know anything about using KIAUH to flash mcus - I’ll look into that but in general for the mightyboard rev g and h you have to flash at 57600. You may be able to flash it by powering down and up the board at just the right time but I haven’t looked into that.

@Ducky4546 I agree with @dockterj that it looks like you are using the wrong config file.

Edit: I’m not sure what is going on with the MCU type. I see multiple places where it uses different settings, one uses atmega2560, the others use atmega1280, so not sure which one is actually selected.

  • Also, can you check the MCU on your Rev G board. My Rev G board has an atmega1280, but your MCU build config has the atmega2560 selected. I have heard that some boards have that though, so that could still be correct, but worth double checking.

Also as far as I understand, the baudrate you select in the MCU build isn’t the baudrate that the bootloader communicates at, that is separate. That buad rate is the rate that Klipper will talk to it during normal operation, so 57600 is pretty slow, and may be a bottleneck for Klipper. So in the MCU config (both for flashing, and in printer.cfg) I set it to 250000 and it still flashed fine, I think you should try the same. If needed I think the flash command has an option to set the programming baudrate separate from the MCU config.

The connection issues you had may also be related to the low baudrate, or the fact that you have restart_method: command in the (wrong) config file, instead of restart_method: mightyboard (which was added by @dockterj).

Edit: Also the restart method in the config may be why you were having trouble flashing it in the first place. So definitely try the new config file and the higher baudrate, and flash again.

Anyway, Good luck!

Kevin, How are you flashing? What is the specific avrdude command line you are using and are you powering down/powering up in a special timing? I was unable to flash without changing the baud rate in avrdude to 57600.

The baud rate specified for the mcu in the example config file is 250000 and should be left as is. If you are using my repo there are changes in the call to avrdude to force the baud rate to 57600 for flashing only. You shouldn’t need to change these.

@dockterj Yes, what you are saying about the baudrate is what I was trying to say also. It sounded like @Ducky4546 was changing the 250000 to 57600 in the printer config (and/or the MCU build config), which is wrong.

As far as flashing it, I didn’t need to do anything special to set the baudrate, since your repo had the modifications to communicate at the correct baudrate in avrdude, and presumably used the restart_method: mightyboard that you added. When I tried flashing from the official klipper repo installation it failed. As soon as I had your custom repo installed it worked.

KIAUH is simply a more interactive “GUI” (an easier to navigate text based menu) with scripts for installation/uninstallation/flashing/etc. So doing the flashing from there is not really different than what gets executed if you run the command line code from the klipper installation documentation.

Are you using an ADXL 345 for resonance testing? If so would you mind dropping the stl or maybe even step files for the mount? I’ve got a spare ADXL but haven’t had the time to design a mount, if you shared yours that would be greatly appreciated

So I got the LED color control working well using delayed gcode during manual preheat of the nozzle, only to realize that it doesn’t work during the preheat of a print. The problem is that the M109/M190 (wait for temperature) codes block gcode while heating. This includes delayed gcode. So basically it doesn’t execute the LED check code until after the preheat is done (which defeats the purpose).

I can set it up to set the color before heating, then change it once heated, but this isn’t the same as the original control where it changes color as the temperature changes.

Anyone have any ideas on how to get around this?