1

Topic: Automatic bed leveling and z offset howto (Level 2/3)

This is a guide to setup the automatic bed leveling feature on a Solidoodle. You will need to replace your extruder, solder some headers on your motherboard and recompile the firmware. If you this is outside your comfort zone, I am afraid this guide is not for you. Moreover, it will only work with a Printrboard or a Sanguinololu with an ATMega1284p (or a RAMPS). If you have an original solidoodle motherboard with an ATMega644, you will need to replace the chip (it's 10$ on ebay).

The idea behind automatic bed leveling is that the Z-endstop is mounted on the extruder carriage, so that the distance between the extruder and the bed can be probed in multiple points. If the bed is not leveled, the firmware automatically adds a Z component to your X and Y moves to keep your nozzle always at a constant distance from the bed. So no more leveling nor fiddling with the Z offset! Example:

The feature is available in the newest Marlin firmware.

Part 1: hardware
As you see in the video, the Z probe is attached to a small servo motor that can move it up and down. To achieve this, I used a micro servo like this: http://www.adafruit.com/products/169 and modified Lawsy's Mk4 extruder by adding a small bracket on the lower side.

http://www.francescosantini.com/public/PC010007.JPG

The Z-stop endswitch is then mounted on the arm attached to the servo motor.

http://www.francescosantini.com/public/PC010004.JPG

The modified extruder and the arm are on thingiverse: http://www.thingiverse.com/thing:193786

The servo motor needs to be wired to the motherboard. Specifically, it requires 5V power, Ground and a signal pin. In the Sanguinololu motherboard, there are a few possibilities in the extension headers. You can take 5V from any source, and for the signal I used pin 27, shown in the following picture and indicated as A4 on the board (it is the pin below the one used traditionally for the fan):

http://www.francescosantini.com/public/servo_wiring.png

Part 2: firmware
The firmware needs to be configured for the auto bed leveling feature. Grab the latest snapshot from Adrian's github as described here: http://www.soliforum.com/topic/4236/bet … ll-boards/

NOTE: I don't have experience with Printrboard, so the following instructions are for the Sanguinololu

Assuming that you know how to modify the firmware, open it in your Arduino environment and look for the file pins.h

Navigate to the Sanguinololu section (search for "Sanguinololu pin assignment") and add the following:

#ifdef NUM_SERVOS
   #define SERVO0_PIN 27
#endif

In the Configuration.h file, enable the servo motor by uncommenting the appropriate lines at the end of the file:

#define NUM_SERVOS 1 // Servo index starts with 0 for M280 command
#define SERVO_ENDSTOPS {-1, -1, 0} // Servo index for X, Y, Z. Disable with -1
#define SERVO_ENDSTOP_ANGLES {0,0, 0,0, 165,60} // X,Y,Z Axis Extend and Retract angles

The SERVO_ENDSTOP_ANGLES need to be determined for your setup, so upload the firmware and connect your printer to repetier or pronterface.

Part 3: servo configuration
You will need to determine at which servo angles your Z probe will be extended or retracted. Use the command M280 P0 S{angle} (example: M280 P0 S60 moves the servo to 60º) to test various positions. Write down the angle at which the probe is extended (pointing down) and the angle at which it is out of the way. You might need to rotate the arm with respect to the pivot in order to optimize the travelling range.

Don't worry about the jitter, it will go away in the next step.

Part 4: Second firmware configuration
Change the SERVO_ENDSTOP_ANGLES by writing the two angles that you found in the previous steps as the last pair of values in the curly braces.

Upload the firmware and reconnect the printer.

Part 5: Configuring the bed leveling probe
This is copy-pasted from the Marlin readme:

Next you need to define the Z endstop (probe) offset from hotend. My preferred method:

    a) Make a small mark in the bed with a marker/felt-tip pen.
    b) Place the hotend tip as exactly as possible on the mark, touching the bed. Raise the hotend 0.1mm (a regular paper thickness) and zero all axis (G92 X0 Y0 Z0);
    d) Raise the hotend 10mm (or more) for probe clearance, lower the Z probe (Z-Endstop) with M401 and place it just on that mark by moving X, Y and Z;
    e) Lower the Z in 0.1mm steps, with the probe always touching the mark (it may be necessary to adjust X and Y as well) until you hear the "click" meaning the mechanical endstop was trigged. You can confirm with M119;
    f) Now you have the probe in the same place as your hotend tip was before. Perform a M114 and write down the values, for example: X:24.3 Y:-31.4 Z:5.1;
    g) You can raise the z probe with M402 command;

    h) Fill the defines bellow multiplying the values by "-1" (just change the signal)

    #define X_PROBE_OFFSET_FROM_EXTRUDER -24.3
    #define Y_PROBE_OFFSET_FROM_EXTRUDER 31.4
    #define Z_PROBE_OFFSET_FROM_EXTRUDER -5.1

The following options define the probing positions. These are good starting values. I recommend to keep a better clearance from borders in the first run and then make the probes as close as possible to borders:

    #define LEFT_PROBE_BED_POSITION 20
    #define RIGHT_PROBE_BED_POSITION 100
    #define BACK_PROBE_BED_POSITION 130
    #define FRONT_PROBE_BED_POSITION 20

Part 6: Start GCode
You will need to modify your start gcode. Instead of homing the axes, you will now need to probe the bed with the G29 command. This is my code that replaces the first homing commands:

M104 S[first_layer_temperature_0] ;set extruder temp and start heating
G28 X0 Y0 ;home X and Y
G29 ;probe bed
G90; set absolute coordinates
G92 E0; reset extruder distance
G1 Z5 F300 ;move platform down 5mm
G1 X145 Y145 F3000 ; move to back right corner

The probing settings seem to be reset once you home the axes, so be careful with the homing button.

Note
Backlash is not your friend. Try to minimize it as much as possible. I succesfully used the Hysteresis fix to remove a bit of residual backlash in the Z direction.

I know this is a long guide, but I assure you it's worth it! If you have any question just ask. And I would be grateful if someone with a Printrboard could give some insight on its configuration.

2 (edited by ysb 2013-12-01 12:54:53)

Re: Automatic bed leveling and z offset howto (Level 2/3)

i think i love you ... tongue

3

Re: Automatic bed leveling and z offset howto (Level 2/3)

Welcome back rincewind. :-)

This all looks great and I can't wait to see it in action on a Solidoodle.  Word of warning to anyone with a printed threadless balls crew. This will not work because the movement upward isn't the same as the movement downward.

SD3 w/ mods:
Glass bed with QU-BD heat pad upgrade, threadless ballscrew w/ 8mm smooth rod, spectra line belt replacement, lawsy MK5 extruder, Lawsy replacement carriage, E3D hotend, Ramps 1.4 w/ reprap discount controller, DRV8825 drivers, 12v 30A PS, Acrylic case, Overkill Y-idlers, Filament alarm, Extruder fan + more.

4

Re: Automatic bed leveling and z offset howto (Level 2/3)

2n2r5 wrote:

Welcome back rincewind. :-)

This all looks great and I can't wait to see it in action on a Solidoodle.  Word of warning to anyone with a printed threadless balls crew. This will not work because the movement upward isn't the same as the movement downward.

Thanks 2n2r5, it's good to be tinkering again smile. That's an interesting fact for the threadless ball screw (of "threadless balls crew" as you said, lol). Maybe we can find a way of compensating for that in the firmware?

5

Re: Automatic bed leveling and z offset howto (Level 2/3)

another to I need to add to my printer smile Thanks

SD2 - Glass Bed, Fans on PCB and Y motor, Custom enclosure
Slicer - Simplify3D

6

Re: Automatic bed leveling and z offset howto (Level 2/3)

A word of warning: be very careful with Z homing with this mod, as if you are already below the Z endstop and you try to home Z, the bed will crash into the extruder. I am working on a firmware mod to overcome this danger, but in the meantime just try to avoid homing Z, or move at least 1cm down before homing.

7

Re: Automatic bed leveling and z offset howto (Level 2/3)

This is impressive. Can you film a top/side view showing a few layers of printing?

SD2 with E3D, SD Press, Form 1+
Filastruder
NYLON (taulman): http://www.soliforum.com/topic/466/nylon/

8

Re: Automatic bed leveling and z offset howto (Level 2/3)

DePartedPrinter wrote:

This is impressive. Can you film a top/side view showing a few layers of printing?

Sure, I will do that tomorrow though, today it's family evening smile

9

Re: Automatic bed leveling and z offset howto (Level 2/3)

I am not having any luck getting a servo to work on the printrboard. Has anyone else been able to do so? If anyone has been able to get the servo part working, I can troubleshoot from there.

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition

10

Re: Automatic bed leveling and z offset howto (Level 2/3)

Hazer wrote:

I am not having any luck getting a servo to work on the printrboard. Has anyone else been able to do so? If anyone has been able to get the servo part working, I can troubleshoot from there.

How exactly is it not working? Not moving at all? What pin are you using for the servo?

11

Re: Automatic bed leveling and z offset howto (Level 2/3)

I have it on the E-endstop pin, but have tried 3 others as well. The servo will goto mid position on power-up, and then just start to creep to one end. No gcode commands work. I have put an o-scope on the pin. For less than a second, I see the 1.5ms pulses but then it changes to a 33ms repeating pulse and does not change for anything.

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition

12

Re: Automatic bed leveling and z offset howto (Level 2/3)

DePartedPrinter wrote:

This is impressive. Can you film a top/side view showing a few layers of printing?

I've made a small video from a different angle:

I'm also attaching a picture of a single-wall cube printed with the uneven bed, to give you an idea of the accuracy.

Post's attachments

PC050005.JPG 697.81 kb, 1 downloads since 2013-12-05 

You don't have the permssions to download the attachments of this post.

13

Re: Automatic bed leveling and z offset howto (Level 2/3)

Hey Rince,

Been trying to work on the servo with Sanguino but not having any luck. I've tried 3 different Sang boards and can not get the servo to move with the M280 command.  If work fine with the ramps board no problem.

Here is my questions.  They might be stupid but my brain is fried at this point wink
1. Does the Sang have to be fully connected to get the servo working?  right now I only have steppers and E-temp probe connected for testing outside the machine?
2. Does it matter where the #ifdef NUM_SERVOS is in the pins.h section for the sang? right now I have it after the fan pin define
3. Do I need the 12V connected to Board or can it run off USB power alone?

14

Re: Automatic bed leveling and z offset howto (Level 2/3)

rjp350z wrote:

Hey Rince,

Been trying to work on the servo with Sanguino but not having any luck. I've tried 3 different Sang boards and can not get the servo to move with the M280 command.  If work fine with the ramps board no problem.

Here is my questions.  They might be stupid but my brain is fried at this point wink
1. Does the Sang have to be fully connected to get the servo working?  right now I only have steppers and E-temp probe connected for testing outside the machine?
2. Does it matter where the #ifdef NUM_SERVOS is in the pins.h section for the sang? right now I have it after the fan pin define
3. Do I need the 12V connected to Board or can it run off USB power alone?

From what you are describing, it seems that you are doing everything correctly... AFAIK it should run with just 5V and nothing else attached, but I can't be sure because my USB 5V line is cut and without external power nothing works for me.

Are you using the very latest firmware from Adrian? Or have you at least added the ATMega1284P option in the servo.h file (you do have a 1284P and not a 644 right?)?

I also have the #ifdef exactly at the same place. If you are on IRC we can try troubleshooting it together

15

Re: Automatic bed leveling and z offset howto (Level 2/3)

Thanks I do have the latest marlin and a 1284P in all my spares. and I did update the servo.h.  I think I'm gonna pull he firmware again and start from scratch then try connecting the 12V line to if that changes anything.

I'm only getting 4.7v across the 5v line with just the USB might be under powered for the servo

16

Re: Automatic bed leveling and z offset howto (Level 2/3)

rjp350z wrote:

Thanks I do have the latest marlin and a 1284P in all my spares. and I did update the servo.h.  I think I'm gonna pull he firmware again and start from scratch then try connecting the 12V line to if that changes anything.

I'm only getting 4.7v across the 5v line with just the USB might be under powered for the servo

Uhm servos should work at that voltage, they are usually rated at least 4.6V.

17

Re: Automatic bed leveling and z offset howto (Level 2/3)

Now I feel like a complete idiot wink

Downloaded the latest and it works just fine.  Noticed a discrepancy between the original instructions and Adrians latest update.

In the Servo.h the original post we changed per below

-#elif defined(__AVR_ATmega32U4__)
+#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1284P__)

but adrians latest build had the 1284 as

elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) ||defined(__AVR_ATmega2561__)
#define _useTimer3
//#define _useTimer1
//typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;

Thanks for your help I can move forward  big_smile

18

Re: Automatic bed leveling and z offset howto (Level 2/3)

rjp350z wrote:

Now I feel like a complete idiot wink

Downloaded the latest and it works just fine.  Noticed a discrepancy between the original instructions and Adrians latest update.

In the Servo.h the original post we changed per below

-#elif defined(__AVR_ATmega32U4__)
+#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1284P__)

but adrians latest build had the 1284 as

elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) ||defined(__AVR_ATmega2561__)
#define _useTimer3
//#define _useTimer1
//typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;

Thanks for your help I can move forward  big_smile

I also don't understand why, but I'm happy that it works now smile

19

Re: Automatic bed leveling and z offset howto (Level 2/3)

rjp350z: what are you seeing happen? I am having problems with the printrboard. What I see is the servo goes to a certain position really quickly, then it just creeps.

Reading through the firmware, the setup routine enables the interupts (including the servo control) and other things, then jsut after the LCD update it pauses for 1 second. Then the firmware starts the main loop where it controls the steppers and heaters. I have a feeling that somewhere the servo interupt is getting hosed once the main loop starts (it matches what I see which is the servo is getting commanded for one second then gets messed up). I am trying to discover if this is a printrboard only problem, or anything non-RAMPS/non-MEGA related.

So what are you seeing?

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition

20

Re: Automatic bed leveling and z offset howto (Level 2/3)

I was getting no responses at all from the Servo when I issued the M280 command.  The command would take and the log showed it but the servo never responded.

When I was testing on the ramps I had no issues at all and it all worked 1st try.  Only reason I was testing on the Sanguino board is I am almost ready to do the full conversion to ramps and wanted to test on both boards 1st.

All seems to be working now on both Sang + Ramps boards.  I do not have a printerboard so can not do any testing from myside but I think I should get one to try and assist everyone else.

Quick question....
Are you testing on a live machine or is the printerboard removed from the machine? 

Reason I ask when I was testing the VIKI LCD and I had it's define enabled in firmware everything worked fine but when I started testing the bed auto level I disconnected the VIKI but never disabled in firmware.  When I tried to connect with repetier it would just sit with 1 command in que.  Once I figured out I had to disable the VIKI in firmware if it was not physically connected all things got better.

21

Re: Automatic bed leveling and z offset howto (Level 2/3)

rjp350z wrote:

I was getting no responses at all from the Servo when I issued the M280 command.  The command would take and the log showed it but the servo never responded.

When I was testing on the ramps I had no issues at all and it all worked 1st try.  Only reason I was testing on the Sanguino board is I am almost ready to do the full conversion to ramps and wanted to test on both boards 1st.

All seems to be working now on both Sang + Ramps boards.  I do not have a printerboard so can not do any testing from myside but I think I should get one to try and assist everyone else.

Quick question....
Are you testing on a live machine or is the printerboard removed from the machine? 

Reason I ask when I was testing the VIKI LCD and I had it's define enabled in firmware everything worked fine but when I started testing the bed auto level I disconnected the VIKI but never disabled in firmware.  When I tried to connect with repetier it would just sit with 1 command in que.  Once I figured out I had to disable the VIKI in firmware if it was not physically connected all things got better.

Thats unique to the Viki (the I2C requires it to be connected, or it freezes the firmware). Ive tested both in the machine and out. I have put an oscilloscope on the output I assigned, and I am seeing a regular servo pulse for only 1 second every time I power the board up, then it switches to a 30Hz 50% duty cycle PWM (which is 33ms pulse width, servo dont like that). If I change the servo pin, the problem follows the pin. I have tried 4 different outputs to confirm.

I have crawled through each part of the firmware, paying close attention to any areas that are masked with at90usb defines and whatnot. I am about to give up on this printrboard.

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition

22

Re: Automatic bed leveling and z offset howto (Level 2/3)

Hazer wrote:
rjp350z wrote:

I was getting no responses at all from the Servo when I issued the M280 command.  The command would take and the log showed it but the servo never responded.

When I was testing on the ramps I had no issues at all and it all worked 1st try.  Only reason I was testing on the Sanguino board is I am almost ready to do the full conversion to ramps and wanted to test on both boards 1st.

All seems to be working now on both Sang + Ramps boards.  I do not have a printerboard so can not do any testing from myside but I think I should get one to try and assist everyone else.

Quick question....
Are you testing on a live machine or is the printerboard removed from the machine? 

Reason I ask when I was testing the VIKI LCD and I had it's define enabled in firmware everything worked fine but when I started testing the bed auto level I disconnected the VIKI but never disabled in firmware.  When I tried to connect with repetier it would just sit with 1 command in que.  Once I figured out I had to disable the VIKI in firmware if it was not physically connected all things got better.

Thats unique to the Viki (the I2C requires it to be connected, or it freezes the firmware). Ive tested both in the machine and out. I have put an oscilloscope on the output I assigned, and I am seeing a regular servo pulse for only 1 second every time I power the board up, then it switches to a 30Hz 50% duty cycle PWM (which is 33ms pulse width, servo dont like that). If I change the servo pin, the problem follows the pin. I have tried 4 different outputs to confirm.

I have crawled through each part of the firmware, paying close attention to any areas that are masked with at90usb defines and whatnot. I am about to give up on this printrboard.

I also have no clue of what could be going wrong. I might be suggesting the obvious, but to troubleshoot, try inserting some code like

SERIAL_PROTOCOL("Checkpoint");

ore something similar in the handle_interrupts function in Servo.cpp. At least in the part where the pin is supposed to change state (for example after digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW);)

It helped me in the beginning to see that the function was not called at all. At least you can see if the timer is working or not.

23

Re: Automatic bed leveling and z offset howto (Level 2/3)

Thank you Rincewind, you got me thinking in the right direction. Since I already knew that the servo worked for one seond, I began tracing down the problem. In the main loop, I commented out the Manage_heaters, Manage_inactivity, etc and the servo worked!

Next I began uncommenting each until I narrowed down the problem. Inside Manage_inactivity, Check_axis, there is a piece of code in the planner.h that manages the FAN_PIN output. If you do not use FAN_SOFT_PWM define, then it uses an analogwrite command that apparently will mess up the servo interrupt. I am guessing that this particular routine uses different timers dependant on the board being used. Anyway, uncommenting FAN_SOFT_PWM solved the issue. I will install tomorrow and post results this weekend.

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition

24

Re: Automatic bed leveling and z offset howto (Level 2/3)

Hazer wrote:

Thank you Rincewind, you got me thinking in the right direction. Since I already knew that the servo worked for one seond, I began tracing down the problem. In the main loop, I commented out the Manage_heaters, Manage_inactivity, etc and the servo worked!

Next I began uncommenting each until I narrowed down the problem. Inside Manage_inactivity, Check_axis, there is a piece of code in the planner.h that manages the FAN_PIN output. If you do not use FAN_SOFT_PWM define, then it uses an analogwrite command that apparently will mess up the servo interrupt. I am guessing that this particular routine uses different timers dependant on the board being used. Anyway, uncommenting FAN_SOFT_PWM solved the issue. I will install tomorrow and post results this weekend.

Great to hear that! Great work!

25

Re: Automatic bed leveling and z offset howto (Level 2/3)

Some bad news.

The HID bootloader does not like the filesize with the ABL turned on. This is another case where the bootloader needs to be replaced with the CDC (which requires people to get a $11 programmer).

Second problem is the board keeps rebooting randomly when the servo is commanded to change positions. This deos not happen with RAMPS or my clone printrboard. There is a problem with the 5V from the stock board. I was able to rig a battery pack to power the servo and the problem went away.

This means there is no easy way for people with stock SD Printrboards to do this mod. It will require either A: reprogramming the board and replacing the PSU with one that provides separate 5V, or B: replacing the motherboard itself (better option).

Chuck Bittner is a quadriplegic gamer who is petitioning the major console developers to include internal button remapping in all console games. You can help.
Sign Chuck Bittners petition