How to Install Klipper on PandaPi
by ni_mark in Circuits > Raspberry Pi
2184 Views, 8 Favorites, 0 Comments
How to Install Klipper on PandaPi
Only for PandaPI board(>=V2.8),Schematic
Based on the official installation of Klipper:
Prepping an OS image
Start by installing OctoPi on the Raspberry Pi computer. Use OctoPi v0.17.0 or later - see the octopi releases for release information. One should verify that OctoPi boots and that the OctoPrint web server works. After connecting to the OctoPrint web page, follow the prompt to upgrade OctoPrint to v1.4.2 or later.
After installing OctoPi and upgrading OctoPrint, it will be necessary to ssh into the target machine to run a handful of system commands. If using a Linux or MacOS desktop, then the “ssh” software should already be installed on the desktop. There are free ssh clients available for other desktops (eg,secureCRT, PuTTY). Use the ssh utility to connect to the Raspberry Pi (ssh pi@octopi – password is “raspberry”) and run the following commands:
git clone https://github.com/KevinOConnor/klipper ./klipper/scripts/install-octopi.sh
The above will download Klipper, install some system dependencies, setup Klipper to run at system startup, and start the Klipper host software. It will require an internet connection and it may take a few minutes to complete.
- Building and flashing the micro-controller
To compile the micro-controller code, start by running these commands on the Raspberry Pi:
cd ~/klipper/ make menuconfig
Select the appropriate micro-controller and review any other options provided.
Disable the sleep mode
the stlinkv2 debug port will be disabled while in sleep mode,that will cause you hard to flash firmware next time.
nano ~/klipper/src/sched.c
comment the code like following
// Main task dispatch loop
static void run_tasks(void) { uint32_t start = timer_read_time(); for (;;) { // Check if can sleep /* by mark,pandapi,disable the sleep mode if (tasks_status != TS_REQUESTED) { start -= timer_read_time(); irq_disable(); if (tasks_status != TS_REQUESTED) { // Sleep processor (only run timers) until tasks woken tasks_status = TS_IDLE; do { irq_wait(); } while (tasks_status != TS_REQUESTED); } irq_enable(); start += timer_read_time(); } */ tasks_status = TS_RUNNING; // Run all tasks extern void ctr_run_taskfuncs(void); ctr_run_taskfuncs(); // Update statistics uint32_t cur = timer_read_time(); stats_update(start, cur); start = cur; } }
Once configured, run:
make
after running "make", copy the generated "out/klipper.bin" file to your PC. there are many ways to copy files out,for example with secureCRT zmode,
sudo apt-get install lrzsz sz out/klipper.bin
then you can see the klipper.bin in your computer, find the path from:Options-->Session Options-->X/Y/Zmodem-->Download:
Flashing the Micro-controller Connect to Board With StlinkV2($5) .
Install flash tool STM32 ST-LINK Utility
Connect STLinkV2 to PC,Start to flash klipper.bin to the MCU.
Configuring OctoPrint to Use Klipper
The OctoPrint web server needs to be configured to communicate with the Klipper host software. Using a web browser, login to the OctoPrint web page and then configure the following items:
Navigate to the Settings tab (the wrench icon at the top of the page). Under “Serial Connection” in “Additional serial ports” add “/tmp/printer”. Then click “Save”.
Enter the Settings tab again and under “Serial Connection” change the “Serial Port” setting to “/tmp/printer”.
In the Settings tab, navigate to the “Behavior” sub-tab and select the “Cancel any ongoing prints but stay connected to the printer” option. Click “Save”.
From the main page, under the “Connection” section (at the top left of the page) make sure the “Serial Port” is set to “/tmp/printer” and click “Connect”. (If “/tmp/printer” is not an available selection then try reloading the page.)
Once connected, navigate to the “Terminal” tab and type “status” (without the quotes) into the command entry box and click “Send”. The terminal window will likely report there is an error opening the config file - that means OctoPrint is successfully communicating with Klipper. Proceed to the next section.
Init the Raspberry PI GPIO As Float and Input
pi@octopi:~$ nano /home/pi/gpio_pullup.py
1)paste the following python code in the gpio_pullup.py
#import libraries import RPi.GPIO as GPIO import time #GPIO Basic initialization GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) #Initialize your pin GPIO.setup(1,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(2,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(4,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(5,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(6,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(7,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(8,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(9,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(10,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(11,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(12,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(13,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(16,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(18,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(20,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(22,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(24,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(25,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(26,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(27,GPIO.IN,pull_up_down=GPIO.PUD_UP) print "GPIO init"
2)add to boot up shell file
pi@octopi:~$ sudo nano /etc/rc.local
paste this line in the rc.local before the exit 0
python /home/pi/gpio_pullup.py
Enable the UART of RaspberryPI
1)remove all the console options in cmdline.txt
sudo nano /boot/cmdline.txt
2)add this line dtoverlay=pi3-disable-bt in the end of config.txt
sudo nano /boot/config.txt
Configuring Klipper
nano ~/printer.cfg
copy the following to the printer.cfg.
[stepper_x] step_pin: PB8 dir_pin: PB6 enable_pin: !PB9 microsteps: 16 rotation_distance: 40 endstop_pin: ^PA3 position_endstop: 0 position_max: 235 homing_speed: 50 [stepper_y] step_pin: PB5 dir_pin: PB4 enable_pin: !PB9 microsteps: 16 rotation_distance: 40 endstop_pin: ^PA4 position_endstop: 0 position_max: 235 homing_speed: 50[stepper_z] step_pin: PB3 dir_pin: !PA15 enable_pin: !PB9 microsteps: 16 rotation_distance: 4 endstop_pin: ^PA1 position_endstop: 0.0 position_max: 250 [extruder] step_pin: PB15 dir_pin: !PB14 enable_pin: !PB9 microsteps: 16 rotation_distance: 33.683 nozzle_diameter: 0.400 filament_diameter: 1.750 heater_pin: PB12 sensor_type: EPCOS 100K B57560G104F sensor_pin: PB0 control: pid pid_Kp: 21.527 pid_Ki: 1.063 pid_Kd: 108.982 min_temp: 0 max_temp: 250 [heater_bed] heater_pin: PB13 sensor_type: ATC Semitec 104GT-2 sensor_pin: PB1 control: pid pid_Kp: 54.027 pid_Ki: 0.770 pid_Kd: 948.182 min_temp: 0 max_temp: 130 [fan] pin: PA9 [heater_fan hotend_fan] pin :PA8 [mcu] serial:/dev/serial0 baud = 115200 #serial: /dev/serial/by-id/usb-Klipper_Klipper_firmware_12345-if00 [printer] kinematics: cartesian max_velocity: 300 max_accel: 3000 max_z_velocity: 5 max_z_accel: 100
After creating and editing the file it will be necessary to issue a “restart” command in the OctoPrint web terminal to load the config. A “status” command will report the printer is ready if the Klipper config file is successfully read and the micro-controller is successfully found and configured. It is not unusual to have configuration errors during the initial setup - update the printer config file and issue “restart” until “status” reports the printer is ready.
“restart” command:
sudo service klipper stop
sudo service klipper start
Klipper reports error messages via the OctoPrint terminal tab. The “status” command can be used to re-report error messages. The default Klipper startup script also places a log in /tmp/klippy.log which provides more detailed information.
In addition to common g-code commands, Klipper supports a few extended commands - “status” and “restart” are examples of these commands. Use the “help” command to get a list of other extended commands.
After Klipper reports that the printer is ready go on to the config check document to perform some basic checks on the pin definitions in the config file.
note: do not forgot put the jumpers on the H4 to Klipper printing mode.