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

<<Revamped M565 Z Offset. Set it and forget it!>>

Discussion in 'Mods and Upgrades' started by Austin, Mar 5, 2015.

?

Interested in an offset that is stored in the printer instead of declared in the gcode?

  1. YES!

    41 vote(s)
    89.1%
  2. nahh lame

    5 vote(s)
    10.9%
  1. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Would anyone be interested in a firmware where your Z offset is stored in the legitimate EEPROM? And i'm not talking in Marlin's weak "ConfigurationStore" eeprom setup if you're familiar with it. I'll explain.

    I have multiple R1's and they each have a different Z offset.

    I'm sure most of you are familiar with our M565 Z-; commands in the start gcode. It is an M code that is unique. It was custom made for the R1's auto level system and no other 3D printer has this command available. While I admire the functionality I believe it could have been coded a little more "efficiently".

    Having multiple R1's, I run into the problem of having to slice a different .gcode for every Z offset in my arsenal. While most R1's have a Z offset of 1mm I have seen variances from .6mm to 1.4mm. So I devised a way to have one .gcode work on every single one of my machines. Theoretically if every printer was flashed with this "fixed firmware" the same .gcode would work on every R1 with autolevel ever produced... BOOM!

    Basically instead of declaring the Z offset in your "start gcode", the gcode will actually call on a variable from the EEPROM to use as your offset. The true EEPROM. This means even if you disconnect and power down your printer and hit the reset button a hundred times and then re-flashed the firmware the Z offset will still be stored! I've tested it many times.

    So how would you set this z-offset in this new firmware one asks? Well actually, the same way you always had just a little easier.

    Just send this simple command one time (this does not have to be in start .gcode):
    Once your printer has seen that command your offset will be stored.You can always change the stored offset by repeating that command (just in case your offset changed). You would then include this in your start gcode from now on instead of the previous command:

    This will read the stored offset from the EEPROM and use it for the print.

    Now I never have to worry about Z offset when slicing my .gcode! So stoked! Anyone else interested? I'll post the firmware tomorrow regardless...

    [edit]
    Just realized i posted this in "General Discussion". Oops. If someone can move this to "Mods and Upgrades" that would be great. If not oh well.
    [/edit]
     
    #1 Austin, Mar 5, 2015
    Last edited: Mar 5, 2015
  2. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    I am not sure if you are aware the Z Offset can be set via the LCD Controller commands or more permanently via a setting in configuration.h?
     
  3. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    I'm actually totally aware of this. The LCD controller doesn't save anything. Your offset will be forgotten after you power down and you will have to re enter your offset everytime.

    And if you set an offset in configuration.h how will you change that variable? You have to reflash it everytime you wanna change that offset.

    Trust me I know exactly what I'm talking about.
     
  4. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,960
    Likes Received:
    7,344
    Cool that someone else is digging into the firmware though--what if @Ziggy gets hit by a bus ;)
     
  5. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    I'm guessing @Ziggy must be the code junkie around these parts haha

    Well I'll post up a lil demo later and hopefully someone could see some value in it.
     
  6. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,960
    Likes Received:
    7,344
    Cool, on the plus side the offset (once you get it tuned) doesn't need to change unless you do something structural to the bed or rails or the like.

    But making it easier to set more permanently is not a bad thing. Too many people seem to hit road blocks flashing the firmware (although it is not super hard).
     
  7. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Yea I run into the issue multiple times a day where I have to decide what offset to throw in the gcode. I've had offsets change on me out of nowhere sometimes. I have to deal with many R1's its hard to keep track of every offset unless I write them down on a sticky notes.

    Now I never have to delete old gcodes off my SD card. And I could use the same gcode on all my printers.
     
  8. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    Austin

    There is a standard function in the Marlin firmware to do what you need to do. In configuration.h uncomment the #define EEPROM_SETTINGS and reflash. All (well most anyway) of the printer settings can then be saved in EEPROM.

    To use this function
    - set the Z probe offset using M565 Z??.??
    - then issue the M gcode M500 (save settings)

    You only have to do this once. After that the Z Probe Offset will be reloaded from EEPROM at reset of the firmware. You don't even need to include an M565 in your start up gcode.

    Also once you have EEPROM_SETTINGS defined most of the printer settings can be modified and saved to EEPROM using Repetier Host "config" tab alt +E.

    The printer settings (including the Z Offset) can also be changed via LCD and saved in the EEPROM using the LCD Controller "Store Memory" menu item.


    << configuration.h>>
    // EEPROM
    // The microcontroller can store settings in the EEPROM, e.g. max velocity...
    // M500 - stores parameters in EEPROM
    // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
    // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
    //define this to enable EEPROM support
    #define EEPROM_SETTINGS
    //to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
    // please keep turned on if you can.
    //#define EEPROM_CHITCHAT

    Beats me why #define EEPROM_SETTINGS is not set in the Stock Robo Firmware???

    You can define EEPROM_CHITCHAT as well if you want all the saved settings printed via USB to the host at reset - personally I haven't found that very useful as I can get the same info any time via Repetier Host or gcode M501
     
  9. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Yea that EEPROM_SETTING fix is actually included in my firmware. I didn't see anyone mention it maybe someone did but I haven't seen it. I also wondered why it was not included in the stock firmware.

    I don't think you can use M565 Z??.?? then M500 to store your offset. The variables they refer too are not the same. I could be wrong but I will test this later.

    Also, with my firmware you don't NEED to include M565; in the start gcode. You can leave it blank and it will work just as well as the normal Marlin EEPROM.

    I like being able to use a single command to change and store the offset. You can't do that with just the marlin EEPROM and you always need some sort of interface (ie. a computer or some LCD you have to pay for).

    Plus, my LCD (ultra LCD config) does not store the Z Offset correctly in the EEPROM. I've also fixed that in my firmware.

    And in my firmware reverting to 'factory settings' won't reset your offset.

    I don't care if I'm not the first one to fix all this I just wanted to share my own discovery.
     
  10. Ben R

    Ben R Active Member

    Joined:
    Nov 21, 2014
    Messages:
    651
    Likes Received:
    89
    Turn off printer? But then it wouldn't be printing.... I don't understand this ... turn off printer? Irregardlessnessly (TM but feel free to use it to irritate grammar correcting coworkers) I like it in my start code, as I have had my z offset change (well it seems to have settled) as the switches wore in.
     
  11. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    Austin

    The M500 after the M565 definitely works - but test for yourself.

    The "Z Probe Offset" value is stored in EEPROM. There is another "Z Offset" value which is also stored in EEPROM.
     
  12. Ben R

    Ben R Active Member

    Joined:
    Nov 21, 2014
    Messages:
    651
    Likes Received:
    89
    neat, so i can bypass updating my firmware for a new extruder cold end by just adding a little G code into the starting script. well.. I could.
     
  13. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Exactly my point. There are two different values in the EEPROM for z offset. Saving your "Z probe offset" doesn't change your "Z offset". That's why those commands won't work. I just tried this and I had two different offset values stored. Which value will it use when it starts printing? Try it for yourself.

    You'll notice that even after you do the M565 Z??.?? And M500 commands your "z offset" value in your EPROM window on your computer (alt+e in RepitierHost) will be unchanged. My firmware fixes this and includes the EEPROM store function in the m565 z-??.?? command so the offset gets permanently stored instantly and you don't need to enter two different commands ;)

    It really isn't too complicated of a code change. I'm sure you could figure it out if you wanted too.
     
  14. cosber

    cosber Active Member

    Joined:
    Jun 20, 2013
    Messages:
    300
    Likes Received:
    87
    I'm constantly changing my offset. Everything works fine for a while, then it needs tweaking. Since no one else seems to find that to be a problem, shall I assume my printer has a problem?
     
  15. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    Austin

    I was trying to avoid adding any more complication but unfortunately this issue of Z Offset is very complicated.

    If you look in configuration.h around the settings dealing with Auto Bed Leveling you will see this comment

    //
    // This allows for servo actuated endstops, primary usage is for the Z Axis to eliminate calibration or bed height changes.
    // Use M206 command to correct for switch height offset to actual nozzle height. Store that setting with M500.
    //

    The M206 command in the gcode wiki is defined as
    http://reprap.org/wiki/G-code#M206_Marlin_-_Set_home_offset

    <<>>
    M206 Marlin - Set home offset
    Example: M206 X10.0 Y10.0 Z-0.4

    The values specified are added to the endstop position when the axes are referenced. The same can be achieved with a G92 right after homing (G28, G161).

    With Marlin firmware, this value can be saved to EEPROM using the M500 command.

    A similar command is G10, aligning these two is subject to discussion.

    With Marlin 1.0.0 RC2 a negative value for z lifts(!) your printhead.
    <<>>



    So you can change the Z homing offset ( or X and Y homing offsets for that matter) using M206 and store it using M500.

    Note this Z homing offset is also the value changed/stored via Repetier configuration gui. This value CANNOT be changed via the LCD screen.


    HOWEVER


    This Z homing offset set via M206 is actually not being used in bed leveling on the Robo. A different command

    M565 Z???.? is used to set the Z Probe Offset

    the gcode wiki defines M565 to be

    <<>>
    M565: Set Z probe offset

    Example: M565 X3 Y4.5 Z-2.37

    Set the offset from the extruder tip to the probe position. The X, Y and Z values are the delta between the extruder and the actual trigger position of the probe. If the probe trigger point is below the extruder (typical) the Z offset will be negative. This just records the point offset; it does not actually do the probing.
    <<>>


    So the usual practice on the Robo is set the Z Probe Offset value using M565 Z??.?

    The Z Probe value can be stored in EEPROM using M500. The Z Probe Offset can also be changed (and stored) via the LCD screen (just to confuse things more the menu item on the LCD screen is called Z Offset even though it is actually Z Probe offset.)


    Bottom Line

    - #define EEPROM_SETTINGS in configuration.h
    - set the Z probe offset using M565 Z??.??
    - then issue the M gcode M500 (save settings)

    The Robo will then remember the M565 value after resetting.
     
    mark tomlinson likes this.
  16. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Exactly my point again. Having multiple values for essentially the same function is redundant. Especially if they are conflicting. Why all this complication? Why shouldn't you be able to change the Z homing offset with the LCD screen?

    My firmware fixes all that by eliminating the 'zprobe_zoffset' value and using the "add_homeing[2]" in its place. As well as tying in an automatic store so you don't need to enter M500 every time.

    Like I said in my first post, the current config setup in R1's stock firmware is "weak". I don't understand why you insist on trying to put this down as nothing while you keep proving my point. @Ziggy
     
  17. Quest

    Quest Member

    Joined:
    Jan 7, 2015
    Messages:
    59
    Likes Received:
    9
    I would like to know more about this and play around with it a bit.
     
  18. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    Austin

    Of course the Z Offset and Z Probe offset are overlapping functions. But there are subtle differences too. They are not redundant functions in Marlin.

    But since you didn't get my point, I suggest you post an issue and your proposed mod on the GITHUB Marlin development forum. That will give you the opportunity to explain the mod to the developers. But before you do that I would also suggest you check whether M500 saves the Z Probe Offset value in EEPROM.

    Personally I don't see any reason to add a function which is already there in standard Marlin.
     
  19. Austin

    Austin Team ROBO 3D
    Staff Member

    Joined:
    Aug 8, 2013
    Messages:
    20
    Likes Received:
    7
    Okay what are the subtle differences? Why must there be two variables? Please explain because I don't believe you need to have both. Maybe there is something I am overlooking. @Ziggy
     
  20. Ziggy

    Ziggy Moderator
    Staff Member

    Joined:
    Feb 20, 2013
    Messages:
    707
    Likes Received:
    530
    Austin,

    Do some exploring in Marlin.

    M206 stores the Z Homing Offset in an X,Y,Z array variable "add_homeing[]"

    M565 Stores the Z Probe Offset value in a variable "zprobe_zoffset"

    Search and see where these variables are handled in the firmware - there are many differences.

    It is clear from the coding that the Marlin developers have decided to use "zprobe_offset" when handling auto bed leveling functions. "add_homeing[]" is used only for adjusting the Z home offset (or X or Y home offsets) when determining min/max position and in some cases current position.

    And looking at the latest Marlin development firmware the developers have obviously decided to continue using "zprobe_offset" in the auto levelling functions and have also added a configuration parameter

    CUSTOM_M_CODE_SET_Z_PROBE_OFFSET

    in configuration.h to allow any custom M code to be used to set the Z probe offset. The developers are using M851 as the default M code. Robo and the gcode wiki define M565 as the code to be used.

    Again if you feel this handling in Marlin is not correct, then raise an issue with the GITHUB development team.
     

Share This Page