diff --git a/nixos/lavender/configuration.nix b/nixos/lavender/configuration.nix index 5b76741..c8fbe3f 100644 --- a/nixos/lavender/configuration.nix +++ b/nixos/lavender/configuration.nix @@ -11,14 +11,17 @@ # inputs.hardware.nixosModules.common-cpu-amd # inputs.hardware.nixosModules.common-ssd - # You can also split up your configuration and import pieces of it here: - ./containers - # Import common configurations ../common/system-tools.nix # Import your generated (nixos-generate-config) hardware configuration ./hardware-configuration.nix + + # Setup our 3D printer + ./printer + + # Import our docker containers + ./containers ]; nixpkgs = { @@ -129,6 +132,12 @@ }; environment = { + # Install packages, prefix with 'unstable' to use overlay. + systemPackages = with pkgs; [ + libraspberrypi + raspberrypi-eeprom + ]; + # Completions for system packages pathsToLink = [ "/share/zsh" ]; }; diff --git a/nixos/lavender/printer/default.nix b/nixos/lavender/printer/default.nix new file mode 100644 index 0000000..5501b4b --- /dev/null +++ b/nixos/lavender/printer/default.nix @@ -0,0 +1,50 @@ +{ ... }: + +{ + # Klipper is a 3d-Printer firmware. + # It combines the power of a general purpose computer with one or more micro-controllers. + services.klipper = { + enable = true; + # Setup User:Group + user = "root"; + group = "root"; + # Klipper configuration + configFile = ./printer.cfg; + }; + + # Moonraker is a Python 3 based web server + # Exposes APIs with which client applications may use to interact with the 3D printing firmware Klipper. + services.moonraker = { + enable = true; + # Setup User:Group + user = "root"; + group = "root"; + # Listen address and port + address = "0.0.0.0"; + port = 7125; + # Moonraker configuration + settings.authorization = { + force_logins = false; + cors_domains = [ + "https://fluidd.kanto.dev" + ]; + trusted_clients = [ + "10.0.0.0/8" + "127.0.0.0/8" + "192.168.1.0/24" + ]; + }; + # Moonraker exposes APIs to perform system-level operations, such as reboot, shutdown, and management of systemd units. + allowSystemControl = true; + }; + + # Fluidd is a free and open-source Klipper web interface for managing your 3d printer. + services.fluidd = { + enable = true; + # Listen address and port + nginx.listen = [{ + addr = "192.168.1.100"; + port = 4624; + }]; + }; +} diff --git a/nixos/lavender/printer/printer.cfg b/nixos/lavender/printer/printer.cfg new file mode 100644 index 0000000..453294c --- /dev/null +++ b/nixos/lavender/printer/printer.cfg @@ -0,0 +1,233 @@ +# This file contains pin mappings for the stock 2022 Creality Ender 3 +# V2 Neo. To use this config, during "make menuconfig" select the +# STM32F103 with a "28KiB bootloader" and serial (on USART1 PA10/PA9) +# communication. + +# If you prefer a direct serial connection, in "make menuconfig" +# select "Enable extra low-level configuration options" and select +# serial (on USART3 PB11/PB10), which is broken out on the 10 pin IDC +# cable used for the LCD module as follows: +# 3: Tx, 4: Rx, 9: GND, 10: VCC + +# Flash this firmware by copying "out/klipper.bin" to a SD card and +# turning on the printer with the card inserted. The firmware +# filename must end in ".bin" and must not match the last filename +# that was flashed. + +# This also works for the GD32F303 based Creality 4.2.2 board. + +# See docs/Config_Reference.md for a description of parameters. + +[stepper_x] +step_pin: PC2 +dir_pin: PB9 +enable_pin: !PC3 +microsteps: 16 +rotation_distance: 40 +endstop_pin: ^PA5 +position_endstop: 0 +position_max: 235 +homing_speed: 80 + +[stepper_y] +step_pin: PB8 +dir_pin: PB7 +enable_pin: !PC3 +microsteps: 16 +rotation_distance: 40 +endstop_pin: ^PA6 +position_endstop: 0 +position_max: 235 +homing_speed: 80 + +[stepper_z] +step_pin: PB6 +dir_pin: !PB5 +enable_pin: !PC3 +microsteps: 16 +rotation_distance: 8 +endstop_pin: probe:z_virtual_endstop +position_max: 250 +homing_speed: 4 +second_homing_speed: 1 +homing_retract_dist: 2.0 + +[extruder] +max_extrude_only_distance: 100.0 +step_pin: PB4 +dir_pin: PB3 +enable_pin: !PC3 +microsteps: 16 +rotation_distance: 34.406 +nozzle_diameter: 0.400 +filament_diameter: 1.750 +heater_pin: PA1 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: PC5 +control: pid +# tuned for stock hardware with 200 degree Celsius target +pid_Kp: 21.527 +pid_Ki: 1.063 +pid_Kd: 108.982 +min_temp: 0 +max_temp: 250 + +[heater_bed] +heater_pin: PA2 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: PC4 +control: pid +# tuned for stock hardware with 70 degree Celsius target +pid_kp: 70.405 +pid_ki: 1.229 +pid_kd: 1008.553 +min_temp: 0 +max_temp: 130 + +[fan] +pin: PA0 + +[mcu] +serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 +restart_method: command + +[printer] +kinematics: cartesian +max_velocity: 300 +max_accel: 5000 +max_z_velocity: 5 +square_corner_velocity: 5.0 +max_z_accel: 100 + +[bltouch] +sensor_pin: ^PB1 +control_pin: PB0 +x_offset: -45.0 +y_offset: -10.0 +z_offset: 0 +speed: 20 +samples: 1 +sample_retract_dist: 8.0 + +[safe_z_home] +home_xy_position: 160,120 +speed: 150 +z_hop: 10 +z_hop_speed: 10 + +[bed_mesh] +speed: 120 +mesh_min: 30,30 # Need to handle head distance with cr-touch (bl_touch) +mesh_max: 189,189 # Max probe range +probe_count: 5,5 +fade_start: 1 +fade_end: 10 +fade_target: 0 +algorithm: bicubic + +[bed_screws] +screw1:30,25 +screw1_name:1 +screw2:200,25 +screw2_name:2 +screw3:200,195 +screw3_name:3 +screw4:30,195 +screw4_name:4 + +[screws_tilt_adjust] +screw1: 67, 42 +screw1_name: front left screw +screw2: 237.60, 42 +screw2_name: front right screw +screw3: 237.60, 212 +screw3_name: rear right screw +screw4: 67.60, 212 +screw4_name: rear left screw +horizontal_move_z: 10 +speed: 200 +screw_thread: CW-M4 # Use CW for Clockwise and CCW for Counter Clockwise + +# [display] +# The Ender 3 v2 Neo's 4.3" LCD display is not supported by klipper + +[output_pin beeper] +pin: PB13 + +# Fluidd initial setup + +# Allows file uploads to work correctly. +[virtual_sdcard] +path: /var/lib/moonraker/gcodes + +# Required to properly support display updates in fluidd +[display_status] + +# Enables Pause / Resume functionality within klipper. +[pause_resume] + +# These can be assumed sane defaults, but should be checked and modified to your own needs. +[gcode_macro PAUSE] +description: Pause the actual running print +rename_existing: PAUSE_BASE +# change this if you need more or less extrusion +variable_extrude: 1.0 +gcode: + ##### read E from pause macro ##### + {% set E = printer["gcode_macro PAUSE"].extrude|float %} + ##### set park positon for x and y ##### + # default is your max posion from your printer.cfg + {% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %} + {% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %} + ##### calculate save lift position ##### + {% set max_z = printer.toolhead.axis_maximum.z|float %} + {% set act_z = printer.toolhead.position.z|float %} + {% if act_z < (max_z - 2.0) %} + {% set z_safe = 2.0 %} + {% else %} + {% set z_safe = max_z - act_z %} + {% endif %} + ##### end of definitions ##### + PAUSE_BASE + G91 + {% if printer.extruder.can_extrude|lower == 'true' %} + G1 E-{E} F2100 + {% else %} + {action_respond_info("Extruder not hot enough")} + {% endif %} + {% if "xyz" in printer.toolhead.homed_axes %} + G1 Z{z_safe} F900 + G90 + G1 X{x_park} Y{y_park} F6000 + {% else %} + {action_respond_info("Printer not homed")} + {% endif %} + +[gcode_macro RESUME] +description: Resume the actual running print +rename_existing: RESUME_BASE +gcode: + ##### read E from pause macro ##### + {% set E = printer["gcode_macro PAUSE"].extrude|float %} + #### get VELOCITY parameter if specified #### + {% if 'VELOCITY' in params|upper %} + {% set get_params = ('VELOCITY=' + params.VELOCITY) %} + {%else %} + {% set get_params = "" %} + {% endif %} + ##### end of definitions ##### + {% if printer.extruder.can_extrude|lower == 'true' %} + G91 + G1 E{E} F2100 + {% else %} + {action_respond_info("Extruder not hot enough")} + {% endif %} + RESUME_BASE {get_params} + +[gcode_macro CANCEL_PRINT] +description: Cancel the actual running print +rename_existing: CANCEL_PRINT_BASE +gcode: + TURN_OFF_HEATERS + CANCEL_PRINT_BASE +