1. Got a question or need help troubleshooting? Post to the troubleshooting forum or Search the forums!

How to Edit your Marlin Code and where everything exists

Discussion in 'Software' started by Lance Weston, Jan 10, 2022.

  1. Lance Weston

    Lance Weston Active Member

    Joined:
    Jun 2, 2018
    Messages:
    515
    Likes Received:
    171
    I intend to explain how to edit your Marlin Code so that you can modify all of the parameters like: thermistor tables, number of samples in auto level, improving PID tuning and what changes with the Partsbuilt.com system board.

    First: Here is the Marlin Code that I use. It compiles properly and works for everything I will post.
    https://drive.google.com/file/d/1VJbKnYBNBaj2MGi5N9iI_ZXe1eGTvC6w/view?usp=sharing

    Second: This is the last version of the code released for the R2:
    https://drive.google.com/file/d/1-9G3DqEJBj6Ij6g693GBRFivEWTn7be-/view?usp=sharing

    Third: This is my modified version of rhe R2 code using the Parts built board, a E3D J6 wade
    extruder and 8825 drivers with a 32 count microstep, 3950 themistors, better PID tuning.

    https://drive.google.com/file/d/1-9G3DqEJBj6Ij6g693GBRFivEWTn7be-/view?usp=sharing

    I will keep adding to this info but it will take time to explain how to program each option.

    After installing the Marlin program form the "First" Create a folder from "Second" the last R2 code release. Go into the folder and find Marlin->Marlin.ino and double click on it. You are now able to edit the code. Go to Sketch->Export Compiled Binary and compile the code. Go into the folder Marlin and sort by :"Date Modified" the compiled code is the latest hex code. Put the hex code on a jump drive and plug it into your R2. Now got to USB on the R2 LCD and click on the hex code you just compiled. You should see a message that your code is loading. Now go to Octoprint->Terminal and type in M501 "read what goes to the eeprom" next type in M500 "save the settings to eeprom" Now go to LCD "system" and restart. You have now reprogrammed the Robo but you have to setup again the offset etc. If your program changes did not effect the eeprom you may ignore the Terminal commands.

    Mods in the order below:
    1: modify the number of test points in auto level
    2. add and use a thermistor table
    3. How to modify the code for use in the Partsbuilt.com system board
    4.. How to modify the temps used for PID auto tuning the Bed and Hotend

    I use micro porous glass on top of the flexplate system. Eventually all glass fails and I get bad spots. I print in the upper left corner because it has the least bed flop and when glass fails I just rotate 90 degrees. The problem is the auto level (command G36) will sometimes look at a bad spot in the glass. The solution is to have more points in the auto level.

    How to increase the number of auto level test points. Here I changed from the current 3x3 to 5x5 test points The command in gcode is G36 so search for G36, in Marlin go to EDIT-->FIND (picture of search window below) check the box for all tabs and do a search. When you get to G36 scroll down (you are in Configuration.h) to the lines:

    #if RBV(R2)
    // Set the number of grid points per dimension.
    #define GRID_MAX_POINTS_X 5 //LW 3
    #define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X

    has been modified from 3 points on axis to 5 points on axis for 25 test points. The original number 3 was saved as a comment which starts with //. the old value 3 is saved for future reference. I use LW before my comments for later searching of all the mods I have made. Go to Sketch->Export Compiled Binary and compile the code. Go into the folder Marlin and sort by :"Date Modified" the compiled code is the latest hex code. Put the hex code on a jump drive and plug it into your R2. Now got to USB on the R2 LCD and click on the hex code you just compiled. Since this makes no changes to the eeprom , your setting, you are done and may run the R2 with 25 test points.


    Add and use a thermistor table:
    First you must generate a table. The board has a 4.7k pullup resistor and the board has a 1024 count ADC. Using the data from a 3950 thermistor, which is used in the bed and all cheap hotends, I generated the following table:
    // Lance Adjustment 3950 thermistor
    const short temptable_14[][2] PROGMEM = {
    { 22 * OVERSAMPLENR, 300 },
    { 24 * OVERSAMPLENR, 295 },
    { 25 * OVERSAMPLENR, 290 },
    { 27 * OVERSAMPLENR, 285 },
    { 29 * OVERSAMPLENR, 280 },
    { 32 * OVERSAMPLENR, 275 },
    { 34 * OVERSAMPLENR, 270 },
    { 37 * OVERSAMPLENR, 265 },
    { 40 * OVERSAMPLENR, 260 },
    { 44 * OVERSAMPLENR, 255 },
    { 47 * OVERSAMPLENR, 250 },
    { 51 * OVERSAMPLENR, 245 },
    { 56 * OVERSAMPLENR, 240 },
    { 61 * OVERSAMPLENR, 235 },
    { 66 * OVERSAMPLENR, 230 },
    { 72 * OVERSAMPLENR, 225 },
    { 79 * OVERSAMPLENR, 220 },
    { 87 * OVERSAMPLENR, 215 },
    { 95 * OVERSAMPLENR, 210 },
    { 104 * OVERSAMPLENR, 205 },
    { 112 * OVERSAMPLENR, 200 },
    { 123 * OVERSAMPLENR, 195 },
    { 135 * OVERSAMPLENR, 190 },
    { 148 * OVERSAMPLENR, 185 },
    { 162 * OVERSAMPLENR, 180 },
    { 179 * OVERSAMPLENR, 175 },
    { 197 * OVERSAMPLENR, 170 },
    { 216 * OVERSAMPLENR, 165 },
    { 236 * OVERSAMPLENR, 160 },
    { 258 * OVERSAMPLENR, 155 },
    { 279 * OVERSAMPLENR, 150 },
    { 305 * OVERSAMPLENR, 145 },
    { 333 * OVERSAMPLENR, 140 },
    { 362 * OVERSAMPLENR, 135 },
    { 393 * OVERSAMPLENR, 130 },
    { 424 * OVERSAMPLENR, 125 },
    { 460 * OVERSAMPLENR, 120 },
    { 495 * OVERSAMPLENR, 115 },
    { 530 * OVERSAMPLENR, 110 },
    { 567 * OVERSAMPLENR, 105 },
    { 601 * OVERSAMPLENR, 100 },
    { 637 * OVERSAMPLENR, 95 },
    { 674 * OVERSAMPLENR, 90 },
    { 709 * OVERSAMPLENR, 85 },
    { 744 * OVERSAMPLENR, 80 },
    { 775 * OVERSAMPLENR, 75 },
    { 806 * OVERSAMPLENR, 70 },
    { 835 * OVERSAMPLENR, 65 },
    { 861 * OVERSAMPLENR, 60 },
    { 884 * OVERSAMPLENR, 55 },
    { 904 * OVERSAMPLENR, 50 },
    { 923 * OVERSAMPLENR, 45 },
    { 940 * OVERSAMPLENR, 40 },
    { 954 * OVERSAMPLENR, 35 },
    { 966 * OVERSAMPLENR, 30 },
    { 977 * OVERSAMPLENR, 25 },
    { 985 * OVERSAMPLENR, 20 },
    { 993 * OVERSAMPLENR, 15 },
    { 999 * OVERSAMPLENR, 10 },
    { 1004 * OVERSAMPLENR, 05 },
    { 1008 * OVERSAMPLENR, 00 },
    { 1011 * OVERSAMPLENR, -5 },
    { 1014 * OVERSAMPLENR, -10 }
    };
    I saved it in a file "thermistortable_14.h" and saved it in the folder Marlin. Now tell Marlin the file exists. In the file "thermistortables.h" you can see below how I added the table.

    if ANY_THERMISTOR_IS(13) // Hisens thermistor B25/50 =3950 +/-1%
    #include "thermistortable_13.h"
    #endif
    #if ANY_THERMISTOR_IS(14) // LW Lance Adjusted 3950 thermistor
    #include "thermistortable_14.h"
    #endif
    #if ANY_THERMISTOR_IS(20) // PT100 with INA826 amp on Ultimaker v2.0 electronics
    #include "thermistortable_20.h"

    Now that the table is active we can use in. In configuration.h the modified code to use the table for both the bed and the hotend is below.

    #if RBV(R2)
    #define TEMP_SENSOR_0 14 //1 for original 14 for LW 3950 extruder
    #define TEMP_SENSOR_1 0
    #define TEMP_SENSOR_2 0
    #define TEMP_SENSOR_3 0
    #define TEMP_SENSOR_4 0
    #define TEMP_SENSOR_BED 14 //12
    #endif

    Now compile the code and install via jump drive. It does not effect the eeprom so you can run and the new table will be active.


    How to modify the code for use in the Partsbuilt.com system board

    The Partsbuilt uses the standard Arduino board and Ramps 1.4 board. These Arduino boards do not tolerate 24v being sent to the power supply. So D1 on the Ramps 1.4 board is removed ( it is the diode supplying power to the Arduino board) and power to the Arduino is supplied via a 4 pin DuPont cable. Two of the Ramps 1.4 outputs are tied to one power input and one output is tied to the other. We use one 12v output (fans) and two 24v outputs (bed, hotend) The pins do not match the pins on the Robo R2/C2 boards so we must redefine the pins in "ROBOmb.h" Below shows the changes, my convention is to put the original pin in the comment.

    #define CASE_LIGHT_PIN 5 // Override the default pin if needed
    #define FAN1_PIN 6 // Pin used for the fan to cool controller
    #define FAN_PIN 8 // LW 7 PWM Fans for print cooling
    //#define E0_AUTO_FAN_PIN 11 // Ext0 and Ext1 fan as defined in Configuration_adv.h

    #define HEATER_0_PIN 10 // EXTRUDER 1
    #define HEATER_1_PIN -1 // EXTRUDER 2 (FAN On Sprinter)

    #define TEMP_0_PIN 13 // ANALOG NUMBERING default 13
    #define TEMP_1_PIN 15 // ANALOG NUMBERING default 15

    #define HEATER_BED_PIN 9 // LW 8 BED

    After you compile the code, copy hex code to jump drive, insert in Robo, go to LCD->files->usb and load the hex. This does not change the eeprom data so you are good to go.


    How to modify the temps used for PID auto tuning the Bed and Hotend:

    The temps used are on the wrong spot on the curves so I lowered them from Hotend 240C to 210C and Bed from 80C to 70C. . I also broke out the smoothing factor seperatly for the Bed and the Hotend. The combination always gives better values for PID auto tuning. Nex is how to change the temps.. Go to Marlin_main.cpp.and make the following edits:
    c
     

    Attached Files:

    #1 Lance Weston, Jan 10, 2022
    Last edited: Jan 13, 2022 at 9:38 AM
    mark tomlinson likes this.
  2. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,518
    Likes Received:
    7,304
    Edits posted for @Lance Weston [trouble editing previous post above]

    inline void gcode_M303() {
    #if HAS_PID_HEATING
    const int e = parser.intval('E'), c = parser.intval('C', 5);
    const bool u = parser.boolval('U');

    int16_t temp = parser.celsiusval('S', e < 0 ? 50 : 150); //('S', e < 0 ? 70 : 150)

    if (WITHIN(e, 0, HOTENDS - 1))
    target_extruder = e;

    target_extruder = e;

    if(e<0){ //Bed
    if( temp==80) // R2 Bed PID test value
    temp=60; //LW test
    }
    if(e==0){ // extruder o
    if( temp==240) // R2 extruder 0 PID test value
    temp=210; //LW test
    }
     
    #2 mark tomlinson, Jan 13, 2022 at 10:48 AM
    Last edited: Jan 13, 2022 at 2:10 PM

Share This Page