Saturday, February 2, 2019

Change and compile the original Prusa MK3 firmware

I was thinking of different ways to make the build of the Prusa Firmware easy for everyone. One idea was to build a virtual machine or a docker container with everything you need. But I noticed that the way Prusa describes by using the arduino IDE is the easiest, if you know what is not described in the Prusa ReadMe file.
By the way, I am using a Mac. I don't use Windows and cannot give you any platform specific help for Windows. But the tools and process should be the same.

There are different versions of the arduino IDE that you can download at https://www.arduino.cc/en/main/software .
There have been problems in the past and you might see people using the 1.6.x versions as they could not get it to work with 1.8.x. Even Prusa recommend to use "1.8.5".
But as far as I can say those problems are fixed. I could get the latest version (1.8.8) to compile the Prusa firmware without any issues.



Once you have installed the Arduino IDE, you need to install some definitions for the Prusa Einsy board. This is also described in the ReadMe from Prusa.
First you need to add the URL that should be used to fetch board definitions. Go to "Preferences" in the Menu and you get this popup window.




Under settings there is the entry "Additional Board Manager URLs". When you click on the icon right next to the text field a new popup window appears.


Add the line "https://raw.githubusercontent.com/ultimachine/ArduinoAddons/master/package_ultimachine_index.json" to the list and click ok. Then click ok on the previous window.
As you can see from my screenshot I do have another Prusa entry in my list, this is what you need for the MMU2 board, not for the Einsy Rambo.

When we navigate to Tools->Board->BoardsManager a new popup window will open.



Select the "RepRap Arduino-compatible Mother Board (RAMBo) by UltiMachine" in the latest version (1.0.1 as I am writing this guide) and install it.
Again you see the Entry from Prusa research in my list, this is for the MMU2 board, not the Einsy Rambo.

The next step from the Prusa ReadMe says you should change the compiler flags in the "platform.txt" file. Many people fail here because they don't know which file to change, then they search and find, depending on the platforms installed in the arduino IDE, many "platform.txt".

c. modify platform.txt to enable float printf support:
add "-Wl,-u,vfprintf -lprintf_flt -lm" to "compiler.c.elf.flags=" before existing flag "-Wl,--gc-sections"

First go to the arduino IDE main folder. If you don't know how to get there, go to preferences in the menu, there is a line "" click on it and the folder will open. But make sure you close the arduino IDE while you are editing those files!



But if you look at the "platform.txt" file that is in the Rambo folder, it does not contain anything like the line you should change.





Next you open the ultimachine folder and edit this "platform.txt".


You find the line and add the "-Wl,-u,vfprintf -lprintf_flt -lm" to it. That should work right?


NO, it does not!

When you compile the code will get no errors, but the firmware will not work properly. You can easily spot this problem on the Prusa start screen when you have flashed a firmware with those flags not enabled. The z height is showing a "?" instead of a value.



The only place the compiler changes worked for me are in the arduino->hardware->avr->[version] folder.


Edit the "platform.txt" in here as described in the ReadMe and it will work. I did for me at least.


Save the file and when you start the arduino IDE next time this is active.

Hint! With every arduino IDE update this will be overwritten and you have to edit it again. Or create a "platform_local.txt" for persistent changes.

Now that we have setup our environment to compile the code, we need the code itself.
As Prusa publishes everything as open source on GitHub we can get the code from there.
https://github.com/prusa3d/Prusa-Firmware

If you are not familiar with Git and have no Git or Git Desktop installed, the easiest way to get the code is to download a zip file.


In that zip file is all the code you need.


The next step is to copy the file "1_75mm_MK3-EINSy10a-E3Dv6full.h" from the sub directory "variants" to the enclosing directory "firmware" and rename it to "Configuration_prusa.h".




Now we are prepared to make modifications to the code. Please us an editor that does not change the format of the files. On Mac the TextEdit works fine, other tools might transform the files in some rich text format which makes them unusable. Be careful if you use Windows, Windows tools by default change the text format by adding a carriage return to each line. Get a tool like Notepad++ if you use Windows.
As you may see from the next screenshots I am using Eclipse, a developer IDE. You don't have to use Eclipse and if you don't know how to use it, it may be too difficult for you. I use it as I am used to it as I do other software projects.

Prusa recommends to disable multi-language support in the "config.h" file. I have no idea why they still have it enabled in the source files, if they recommend to change it. Just comment out( add "//" in front) the line the value "#define LANG_MODE 1" and uncomment (remove the "//" from the front) the line with the "#define LANG_MODE 0". You find those line pretty much at the end of the "config.h" file.




If you don't plan to make any other changes to the original Prusa firmware you are good to go now and compile the code. Maybe it is not a bad idea to give it a try now, while you have not changed anything. That could rule out any problem you could have made so far.


Ok, now we need to tweak some settings in the code. In my case I am not using the E3D V6 or a clone of it. Instead I am using a Titan Aqua Clone from China.
The nozzle from this different hot-end and mount is not at the same position as I would have used an E3D V6. The other changes we have to make are the extruder steps. Because this is a 3:1 geared extruder we have to change the steps per mm and the direction of the motor.

I am using the values that Chris Vahi posted on Thingiverse for this Titan Aqua mount. I remixed his mount for me as I wanted to have the hoses straight up from the hot-end. But I did not change any other geometry from his design. So in theory his values should work for me.

We need to modify the "Configuration_prusa.h" file that we copied and renamed before.
First we change the steps per millimeter for the extruder motor from the default 240 to 840. Look for the line "#define DEFAULT_AXIS_STEPS_PER_UNIT".

It is the last value in the line, I just commented out (//) the original and copied it to a new line with the new value.


Now we need to change the direction of the extruder motor. Find line "#define INVERT_E0_DIR".


The comment seems to be the opposite of what this line value does. So I changed it to "1".


The next step is to adjust the z axis. As the nozzle is higher as on the usual MK3 we have more z height. But as the nozzle is more towards the front of the printer, we have less space on the y axis for printing. Look for line "Travel limits after homing"



Then change the value for the z axis from 210 to 218 and for the y axis from 215.5 to 170.5. Everything else stays the same.


In my case the z calibration always failed, the motors did not move but kept humming. As Prusa does not use end stop switches, but rather the stall guard feature on the TMC2130 motor drivers I need to adjust the sensitivity for the z axis from 4 to 5. I guess the root cause is that the motor I git from bluerolls just need more current as the LDO motors that Prusa uses.



We also have to tell the firmware that the offset between the nozzle and the P.I.N.D.A probe is different now. Look for line "#define X_PROBE_OFFSET_FROM_EXTRUDER".




Then we change the value for the x axis from 23 to 30 and for the y axis from 5 to 45.



That is it for the"Configuration_prusa.h", you can now save it.

In the "Configuration.h" you find offset for the P.I.N.D.A probe as well. But they don't match with the values in the "Configuration_prusa.h". Seems like they are not used anyway. The whole section is an "ifdef" and the value "ENABLE_AUTO_BED_LEVELING" is commented out before.




For now this is all I want to change. Once I have tested the printer I want to implement some more enhancements to the code, like the 7x7 mesh bed leveling.

Now we can compile our code. Open the arduino IDE. Then go to File->Open and open the "Firmware.ino" file in the Firmware directory.


Then go to Tools->Board and select the RAMBo board.



Now you can go to Sketch-Verify/Compile to see if you can compile without any issues.


The compiler will now take a few seconds to verify and compile the code.


If that was successful you should see a message like this.


Then go to Sketch->Export compiled Binary and it will compile again and export the hex file we need.


Then a new file should appear in our firmware directory.


You may notice that the file size is smaller than the hex files you get from Prusa. The only explanation I have for this is that Josef Prusa mentioned sometime that they link the bootloader now together with the firmware.
This is why I would recommend to first install the latest Firmware from Prusa on any new board you get from Ultimachine or chinese sellers.

The next step is to flash the firmware to the printer. I used Slic3r PE for it. It is exactly the same process as with every firmware update from Prusa.
Use the USB cable to connect your printer to the computer and turn the printer on.
Go to Configuration->Flash printer firmware in Slic3r PE.


Open the file and hit rescan if you cannot see the printer detected.


Then hit Flash! and wait for the firmware to be flashed to the eeprom.


Once it is completed you printer will reboot and you can close the popup from Slic3r.


So far everything looked well. First thing to check was if there is a proper value for the z height on the start screen. This proves that the compiler flags worked. Then I moved the axis around and everything seemed to work fine.





But I still have issues with the XYZ calibration. For some reason the first calibration point is found with no issues, but the 2nd one(front right) fails every time. Sometimes I had to hit the reset button as the nozzle was scratching on the paper. 
As you can see the sensor is about + 30-40 mm off from the calibration point on the y axis. 


So I thought about the change on the Y-axis and changed the value back to 215.5 mm for the Y_MAXPOS and this is pretty much the amount that the sensor if off on the 2nd calibration point. But that did not change anything, It also would not explain why the first calibration point works.

I guess will need some time to sort out what the issue is here. But I thought I share this post anyway as I get asked a lot how to compile the Prusa Firmware.



4 comments:

  1. Thanks for your blog, I finally succeeded to flash my einsy rambo board with the prusa firmware!

    ReplyDelete
  2. Dzięki za twój blog, w końcu udało mi się flashować moją einsy rambo board z oprogramowaniem prusa!

    ReplyDelete
  3. I have an XYZ calibration solution. The probe is a problem. you can fool it by sticking aluminum foil. I used self-adhesive foil with a thickness of 0.05mm. first point 0 pieces, second 2, third 1 fourth 0. Finding this solution took me a few hours. If you stick too much it will be worse, stick as much as you need. ;)

    ReplyDelete
  4. You may be able to adjust your probe point by going into the xyz.cpp and around line 688 you'll find a set of coordinates that look like this:

    //MK3
    #if ((MOTHERBOARD == BOARD_EINSY_1_0a))
    const int16_t xyzcal_point_xcoords[4] PROGMEM = {1250, 16500, 165000, 1250};
    const int16_t xyzcal_point_ycoords[4] PROGMEM = {875, 875, 19500, 19500};

    Playing around with those values may or may not help.

    ReplyDelete

A new project "automatic cat litter box"

 I did not post any updates for a long time. I spent some time making some money with 3D printing to recover some of the costs from this hob...