Klipper pt6: Gcode / console commands

An overview over the already supported G-Codes / Klipper specific console commands.

A full list can be found here:

Commands

G-Codes

McodesGcodesKlipper specific console commands
M82
M83
M18
M105
M104
M109
M112
M114
M115
M119
M303
M140
M190
M106 Sxxx
M107
M206
M400
G1
G4
G20
G28
G90
G91
G92
IGNORE
QUERY_ENDSTOPS
PID_TUNE
SET_SERVO
RESTART ( Restarts host software on the pi, do this after every config.txt change to reload it )
FIRMWARE_RESTART
ECHO
STATUS
HELP
SET_PIN PIN=my_pin VALUE=0 ( Replaces M43 )

Klipper pt5: Features

Pressure Advance:

Is enabled by setting pressure_advance:  in the [extruder] section of the config.cfg to more than 0.

For a E3D titan i found values around 0.04 – 0.05 giving great results.

Klippers tuning guide for Pressure advance.

Toolpath prediction / Lookahead:

Can be dialed in by setting junction_deviation:  in the [printer] section of the config.cfg

Basically lower values slow down cornering, higher values speed it up, i found 0.01 to be a good compromise.

Klippers in depth explanation how movement is created.

PID Tuning:

M303 is supported in Klipper, after finishing an auto PID tune cycle like M303 E0 S215 C8 Klipper will report the correct PID values to Octopies GCode console and you can update your printer.cfg accordingly.

Additional hotend temperature controlled Fans:

Add any number of aditional fans for cooling stepsticks or the coldend by adding

[heater_fan example_fan]
pin: arX
heater: extruder
heater_temp: 50.0
fan_speed: 1

Sections to your config.cfg

Theyll switch on once your hotend is set to 50c and switch of once its cooled below 50c.

Additional static PWM Pins:

Add any number of static pwm pins for controlling case lights f.e. by adding

[static_pwm_output my_case_light]
pin: arX
value: 1

where value sets the PWm cycle from 0 – 1 / 0 – 100%

Run-time configurable digital output pins ( “M42”)

Set pin in printer.cfg:

[digital_output my_pin]

pin:
The pin to configure as a digital output. This parameter must be
provided.

value:
The value to initially set the pin to during MCU configuration
(either 0 or 1). The default is 0 (for low voltage).

shutdown_value:
The value to set the pin to on an MCU shutdown event. The default
is 0 (for low voltage).

Afterwards you can control the pin via octoprints terminal like this:

SET_PIN PIN=my_pin VALUE=0

Klipper pt4: Configuration

 

Configuring Klipper

The easiest way is to use one of the provided config examples if you have a board that fits, otherwise just use the example.cfg and work from there.

Again the easiest way is to manipulate the config file with your pc, log into the pi using WinSCP navigate to  /home/pi, download the printer.cfg from there, edit it using notepad++ and after finishing reupload it to the pi overwriting the existing file.

If you got a preexisting Marlin / Repetier configuration just locate the pins in configuration.h / pins.h file for your breakout board you need.

To get an idea of how Klipper is configured, read through Kevins annotations in both example.cfg and example-extras.cfg

Ill just mention a few important sections here:

Pins:

Pins are configured a bit different from the common Marlin / Repetier scheme:

ar6 f.e. is pin d6

^ar6 is pin6 with pullup if available

!ar6 is active low / high ( can be used to reverse steppers f.e. if you change the dir pin )

Steps per mm:

Klipper uses the distance per step value to set steps per mm, just calculate your steps per mm with reprap calculator like you usually do and divide 1 by them to get the step distance.

Example: 80 steps per mm has been calculated from a typical 200 steps 1.8° Stepper with a 20 tooth gt2 pulley, now we divide 1 by 80 to get a step distance of 0,0125.

Nozzle homing offsets:

If your printer has a bed that offsets from your endstop positions ( Like an Anet A8 f.e. ) configure it as following:

[stepper_x]

position_endstop: -20

position_max: 220

position_min: -20

[stepper_y]

position_endstop: -8

position_max: 208

position_min: -8

This offsets the print area to -20 / -8 and brings the nozzle right to the front edge of the bed at 0 / 0

Bed heat control:

The bed heater can either be PID or bang bang controlled, i found that PID works a lot better, especially on bigger build surfaces.

In my case it looks like this:

[heater_bed]
heater_pin: ar6
sensor_type: NTC 100K beta 3950
sensor_pin: analog11
control: pid
pid_Kp: 65.952
pid_Ki: 1.432
pid_Kd: 759.276
min_temp: 0
max_temp: 110

Klipper pt3: Installation / Update

First install all of the mentioned windows software ( Or their Linux / Osx alternatives ) in pt2 on your host pc, ittl be required from hereon.

Step 1:

Installing Octoprint

Install Octoprint by downloading the latest zip and flashing it with Etcher

After a successful flash dont forget to reinsert the micro sd into the pc and edit the network.txt in the root of the newly created “Boot” partition.

( specifics can be found here )

Pay attention that your wifi channel is neiter 12 nor 13 raspis dont like them.

Boot the pi and make sure it gets recognized in the network.

Log on to the Octoprint web interface and configure everything to your liking, let it search for updates and let it update ( If the update fails for some reason reflash and try again )

Step 2:

Installing Klipper

Install Klipper by following the steps outlined by Kevin here:

https://github.com/KevinOConnor/klipper/blob/master/docs/Installation.md

Issue the necessary commands with putty ( Username: pi / Pw: raspberry )

 

Updating Klipper:

 

SSH into your Pi and issue the following commands:

A simple Host Software Update is done by:

cd ~/klipper
git pull
sudo service klipper restart

If both host and microcontroller need an update go this way:

cd ~/klipper
git pull
~/klipper/scripts/install-octopi.sh

to update the micro controller:

( Octopies console will inform you if a micro controller update is necessary )

sudo service klipper stop
make flash FLASH_DEVICE=/dev/ttyACM0
sudo service klipper start

 

Klipper pt2: Requirements

Hardware
  • Reasonably fast Raspberry Pi ( 2 / 3 )
  • Arduino Mega2560
  • A breakout or combo board like the Ramps 1.4 / Rumba / Rambo / etc is helpful and makes wiring a lot easier.
  • A PC running either Windows or Linux or Osx for the initial Octoprint / Klipper configuration, afterwards an android client can be sufficient.
Windows Software
Raspberry Pi Software

 

Klipper pt1: Why ?

One key factor that differentiates Klipper from many other firmwares is how it generates actual machine movement from given G-Code.

Instead of implementing cornering speed by using the bresenham algorithm ( basically slapping the extruder around corners ) it analyses upcoming corners on a given toolpath and adjusts acceleration and deceleration via trapezoidal calculations, making machine movement very smooth, allowing for higher print speeds while hugely reducing artefacts like ringing.

A great writeup on how exactly its implemented can be found here ( Klipper is based on the same approach first explored by Chamnit for grbl )

As of now we have three groups of motion planners available to my knowledge:

Bresenham

Unsuitable for machine movement imo.

  • Marlin
  • Repetier
  • Duet

Constant Acceleration via trapezoidal calculations

Great middleground, this type of toolpath prediction can easily deal with shitty tiny segments most slicers put out for arcs and at least somewhat respects the mechanical abilities of a given movement system.

  • Klipper
  • Smoothieware
  • Replicape
  • Grbl ( CNC centric )

Jerk controlled Motion

Closest estimation to mechanical reality

To be able to do trapezoidal calculations at the speed needed the second key factor comes into play, instead of shoehorning calculations into an already overburdened 8bit arduino envelope Klipper relies solely on a Raspberry pi to do kinematic calculations, the typical 8bit Arduino becomes a “Stupid” client for the raspberry.

Host – Client based motion enables 8bit Arduinos / Raspberry combos to perform similar to more expensive 32bit boards like Smoothieboard or outright better than Duet f.e. as Duet has the processing power to do proper toolpath prediction but its not implemented in firmware.

This approach has multiple groundbreaking advantages:

  • Pulsing up to 150khz becomes possible on 8Bit arduinos
  • Artefacts like ringing, largely caused by the bresenham algorithm can be completely avoided once Klipper is dialed in
  • High pulsing speeds can lead to higher accels and top speed
  • Dialing in steppers becomes easy and precise, the bresenham algorithm doesnt slam them around causing random stalls anymore, so it becomes possible to fine tune motion systems close to their absolute maximum.

https://github.com/KevinOConnor/klipper/

Limitations:

  • No graphic LCD support, as the firmware on the arduino is “stupid” theres no lcd support implemented and its unlikely that itll be implemented at all. Imo not a big loss if you look at alternatives like Printoid
  • As of now no mesh compensation and only experimental support for bed leveling probes, so one might be forced to actually fix the underlying issue instead of compensating for it in software.