Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save x45dev/f3ab201b4e4e1da1eb0aa9c7ceec52ec to your computer and use it in GitHub Desktop.

Select an option

Save x45dev/f3ab201b4e4e1da1eb0aa9c7ceec52ec to your computer and use it in GitHub Desktop.
How to run MainsailOS on a Raspberry Pi, using Klipper firmware on a Creality CR10-Mini controller board (Melzi 1.1.2 Atmega1284p)

Run MainsailOS and Klipper on a RPi for Creality CR10-Mini

About

Steps to install MainsailOS onto a Raspberry Pi, and flash the Klipper firmware onto a Creality CR10-Mini controller board (Melzi 1.1.2 Atmega1284p).
This configuration is intended to set up a Raspberry Pi 3B+ that can be connected to via WiFi and SSH; ie. no ethernet cable or monitor!

NB: Before attempting to flash Klipper firmware onto the CR-10, the board needs a bootloader. See https://gist.github.com/x45dev/edfa3985cb5c7ce3b5835f7493d62060

Hardware and software environment

  • PC with SSH client. This guide uses a Linux workstation - Ubuntu 21.04.
  • Raspberry Pi 3B+

Steps

Prepare RPi SD card

1. On your PC, download and install the Raspberry Pi Imager.
sudo apt update
sudo apt install snapd
sudo snap install rpi-imager
2. Prepare bootable RPi SD card.
  • Insert a SD card into PC or connect it using an adapter. There’s no need to format the SD card prior, but any existing contents will be wiped.
  • Open the Raspberry Pi Imager and click on “Choose OS” under “Operating Systems”.
  • Then go to “Other specific purpose OS > MainsailOS”. There should be the latest version.
  • Back on the main window, click on “Choose Storage” and select the SD card.
  • Open advanced options by using the keyboard shortcut "Ctrl" + "Shift" + "X" to configure your Wifi connection.
  • Ensure that SSH is enabled.
  • Click “Write” and the Raspberry Pi Imager will download and install the MainsailOS image.
3. Transfer the SD card to the RPi and power up.
4. From PC, connect to the RPi via SSH. (Try mainsailos.local as an address, or check your router for its DHCP-assigned IP address)
user@workstation:~ $ ssh pi@mainsailos.local  
# Defaults: 
#   username: pi 
#   password: raspberry
5. Configure MainsailOS.
# Update Mainsail
 - a. Connect to Mainsail UI from PC browser via HTTP endpoint: `http://mainsailos.local` (if exists in router hosts) or via LAN private IP.
 - b. Menu item: "Machine"  
      Update Manager: "Check for Updates"  
      Then select "Update all components" at the bottom of the list. 

# Update Raspbian
pi@mainsailos:~ $ sudo raspi-config
   Menu item: "8. Update"
   Then <Finish>

# Configure Klipper
pi@mainsailos:~ $ cp ./klipper/config/printer-creality-cr10mini-2017.cfg ~/printer_data/config/printer.cfg

# Add `[include mainsail.cfg]` to the top of printer-*.cfg
#   and then **then restart via the Mainsail UI**.
pi@mainsailos:~ $ echo "[include mainsail.cfg]" | cat - ./printer_data/config/printer.cfg > temp && mv temp ./printer_data/config/printer.cfg
6. Build and flash Klipper microcontroller

NB: The comments at the top of the printer configuration file should describe the settings that need to be set during "make menuconfig".
The following settings were used for the CR10 Mini Melzi V1.1.2 Atmega1284p board.

pi@mainsailos:~ $ cd ~/klipper/

pi@mainsailos:~ $ make menuconfig
[*] Enable extra low-level configuration options
    Micro-controller Architecture (Atmega AVR)  --->
    Processor model (atmega1284p)  --->
    Processor speed (16Mhz)  --->
    Communication interface (UART0)  --->
[ ] Compile for simulavr software emulation (NEW)
(115200) Baud rate for serial port
()  GPIO pins to set at micro-controller startup (NEW)

# Obtain USB serial UUID
# In my case, it is /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A906V745-if00-port0
# Alternatively, you could also try device '/dev/ttyUSB0'
# For additional device diagnostics, use `lsusb` and `usb-devices` commands.
pi@mainsailos:~ $ ls /dev/serial/by-id/* 

# Flash it!
pi@mainsailos:~ $ make flash FLASH_DEVICE=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A906V745-if00-port0

# Update printer.cfg
# Perform a *firmware restart* (via Mainsail UI) after editing this file.

pi@mainsailos:~ $ nano ~/printer_data/config/printer.cfg
# Add/replace under [mcu]:
serial: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A906V745-if00-port0
baud: 115200
restart_method: command
Reset your EEPROM!

Make sure to reset your EEPROM on your printer after flashing any firmware. You can do this from your printer LCD by going to Configuration -> Reset EEPROM or by sending an M502 followed by M500 with your favorite Gcode sender application.

pi@mainsailos:~ $  curl -X POST http://localhost:7125/printer/gcode/script?script=M502
pi@mainsailos:~ $ curl -X POST http://localhost:7125/printer/gcode/script?script=M500

Note: I had previously attempted to write code directly to /tmp/printer. This didn't work in the end. At first attempt, /tmp/printer didn't exist, but when I sent it a MainsailOS 'STATUS' command, it was created. Nevertheless, the syntax echo <my-gcode-command> >> /tmp/printer had no effect. (Test this with the "zero all axes" command, G28.)

Done!! :)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment