Flash Marlin 3DP Firmware from Octopi / Raspberry Pi

I thought this would be useful to document here, as it’s something that I can refer back to, and hopefully will help others!

I have an Anet A8 3D Printer for numerous home projects, and I have got so much use out of it since getting it – love the versatility, and have even designed some parts to help around the house!
Anet A8

The printer is managed through the very popular Octoprint. I actually have the dedicated Octopi image running on a Raspberry Pi Zero W which works great and is a very cheap way to get your printer Wi-Fi enabled! It’s pretty much a case of just flashing the image to an SD card, then connecting your printer via a USB cable.
Octoprint Image

With my printer connected to my Pi, whenever I wanted to update the printers firmware (which is flashed with Marlin) I would have to disconnect from the Pi, and connect to a Windows 10 tablet (as my Mac does not play nice with the serial chip on the printer), so I went in search of a better solution, and I came across some tips on how I could flash the firmware using a Raspberry Pi (or my Octopi!). Details on this below:

1. Compile your firmware

I’m not going to go into details on how to download or install the firmware – There is plenty of documentation out there on how to do this normally. But I will touch on how to get that firmware ready to install from your Octopi / Raspberry Pi.

The CPU on Raspberry Pis is rather slow, and doing the full compile on the Pi would take a very long time! Also as most the documentation is aimed at how to configure Arduino to flash your 3DP firmware, with the Octopi not having a GUI installed that’s an additional complexity.

So – We can get around this by using your much more powerful PC to compile the firmware. Then it’s just a case of uploading to the Pi and flashing. To compile the firmware into a HEX file:
– Click Sketch -> Export Compiled Binary

This will save the HEX file into the same directory as your ino file. Make a note of where that file is, or have your file explorer open ready for the next step.

2. Upload HEX file to your Octopi / Octoprint

There are plenty of ways you can do this, and you may have a preferred method, however I am getting the file into my Octopi using SCP from my mac. If you are a windows user you can use WinSCP.
I uploaded the file into the /home/pi folder ready for the next step.

Note: The default password for octopi is the same as Raspbian. User: pi / Password: raspberry

SCP example:
scp pi@octopi:/home/pi

3. SSH into Octopi and flash firmware

Next you will need to SSH into your Octopi / Raspberry Pi so we can carry out the steps to install and flash. On Windows you can use PuTTY.

Once logged in:

This will install avrdude – the application which runs in the background to Arduino to upload your compiled code. This is what we will use to upload the HEX file to the mainboard.
apt-get update
apt-get install avrdude

Now we need to determine what the (Linux) name of the USB Serial port is that the printer is connected to. The best place to see this is in your connection tab of Octoprint:

As above – in my case it’s /dev/ttyUSB0

Whilst you are in Octoprint, make sure you Disconnect from the printer – that way it will release the Serial port for you to flash the board.

And finally – we can now flash the firmware:

avrdude -p m1284p -c arduino -P [USB Port from Octoprint] -b 57600 -D -U flash:w:[file you uploaded earlier]:I
In my case:
avrdude -p m1284p -c arduino -P /dev/ttyUSB0 -b 57600 -D -U flash:w:Marlin.ino.sanguino.hex:I

NOTE: The above code is specific to the Anet A8 v1.0 board. If you are using a different setup such as RAMPS, you will need to check which processor is being used and adjust accordingly.

The board will automatically reset when complete, and all being well you should be running the new firmware!

Please note – I do not take any responsibility for any damage / bricking / in-operation of your board. Usually these are not terminal if something does go wrong, but it’s too much to explain here if something does.

Happy Printing!

3 thoughts on “Flash Marlin 3DP Firmware from Octopi / Raspberry Pi

  1. Great manual, but take into account, that latest Marlin versions support platformio. I used platformio command line interface through ssh in order to build and upload the firmware directly from the source code. In my opinion this approach is much simpler

Leave a Reply

Your email address will not be published. Required fields are marked *