Ender 3 - Installing a bootloader with a Raspberry Pi

If you have a Raspberry Pi, you're probably already using it for OctoPrint and likely using the OctoPi SD card image. This is good - because it already has most of what we need.

  1. Log into your OctoPi running on your Pi, then become the root user:
    sudo su -
  2. Install avrdude if it is not already installed:
    apt-get install -y avrdude
  3. Copy the avrdude config file to the root home directory:
    cp /etc/avrdude.conf ~/avrdude.conf
  4. Edit ~/avrdude.conf and find the 'linuxspi' programmer. Change the baud rate in the block to 115200. The block should look like the following:
    
    programmer
      id = "linuxspi";
      desc = "Use Linux SPI device in /dev/spidev*";
      type = "linuxspi";
      reset = 25;
      baudrate=115200;
    ;
    	
  5. At the bottom of the same file, add the following:
    
    programmer
      id = "pi_1";
      desc = "Use the Linux sysfs interface to bitbang GPIO lines";
      type = "linuxgpio";
      reset = 17;
      sck = 24;
      mosi = 23;
      miso = 18;
    ;
    
  6. Disconnect the Ender 3 from the power supply. This is important! It is sufficient to unplug the main XT60 connector.
  7. The pins on the Ender 3 board are laid out as:
    
    RST | SCK  | MISO
    GND | MOSI | VCC
    
    Ground and VCC are closest to the edge of the board, GND at the display connector side, VCC at the USB connector side.
  8. Connect the dupont cables to the following pins. You can use this guide to locate the correct pins on the Raspberry Pi
    
    Raspi    => Ender 3
    3v3      => VCC
    GND      => GND
    GPIO 17  => RST
    GPIO 18  => MISO
    GPIO 23  => MOSI
    GPIO 24  => SCK
    
  9. Attempt to talk to the Ender 3 chip over this connection:
    avrdude -p atmega1284p -C ~/avrdude.conf -c pi_1 -v
    If this fails, check the connection of your dupont cables and try again.
  10. Download the bootloader onto the Pi:
    wget https://marlin.crc.id.au/bootloader/optiboot_atmega1284p.hex
  11. Flash the bootloader:
    avrdude -p atmega1284p -C avrdude.conf -c pi_1 -U flash:w:optiboot_atmega1284p.hex:i
  12. You can now connect your Pi via USB to the Ender 3, download a firmware file from this site and flash via:
    avrdude -p atmega1284p -c arduino -P /dev/ttyUSB0 -b 115200 -U flash:w:firmware.hex:i
    Just remember to change firmware.hex to match the file you have downloaded.
  13. I would suggest installing the Firmware Updater plugin for OctoPrint to update your firmware easily in the future.