Author Topic: Limit Switches  (Read 7599 times)

Lob0426

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1622
  • Let the Magic Blue Smoke out!
    • View Profile
    • Richards RasPi Web Server
Re: Limit Switches
« Reply #30 on: October 13, 2016, 09:32:06 AM »
Appologies if this is not the "main thread" for limit switches, was the closest I could find.

I added limit switches to my L7 board. Recompiled Grbl 1.0c (after replacing bootloader on my Nano, and and telling Arduino IDE to treat it as an Uno. Arduino IDE sets max 30kB for the Nano due to old bootloader).

I just checked if the default Grbl pins were connected to anything else on the PCB, and solder on wires which I ran to a breadboard next to the L7. So I added probe, coolant, x,y,z limits and also step/dir for Z axis to my breadboard. Only wired up hardware for two limit switches for homing for now though, more will follow.

So the before mentioned limited capacity in the Nano I think could be an artifiact from outdated boards.txt in the Arduino Ide imposing a 30kB instead of 31.5kB firmware limit on a Nano. Instead of changing my boards.txt I just flashed the optiboot bootloader to the Nano with the settigns for a Uno as it solves the "problem" across all versions of the IDE.

I see most are talking about using a single pin for both axis, but this requires homing to be sequential instead of simultaneous. Using two pins makes much faster homing as both axes travel at the same time.

So I used (note i changed the optional HOMING_CYCLE_1 to HOMING_CYCLE_0, and left the other cycles commented out.
Code: [Select]
#define HOMING_CYCLE_0 ((1<<X_AXIS)|(1<<Y_AXIS))  // OPTIONAL: Then move X,Y at the same time.instead of
Code: [Select]
#define HOMING_CYCLE_0 ((1<<X_AXIS))
#define HOMING_CYCLE_1 ((1<<Y_AXIS))

We talk about using a single pin as the L6/L8 boards have all the limits connected at D9. And most people move to those rather than solder into their board. I also am running a modified L7, mine is single pin.

Grbl's default is a separate pin for each axis. So you either have to modify firmware or modify hardware. Most choose to use the single pin setup as we have compiled firmware available for single pin use. Even homing a single axis at a time is a step up from no homing at all! LOL

Really no wrong way to do it, as long as it works. If you want a bit faster homing then going multi pin was the best.
I keep homing seek down to 3500 as any fast crashes the switches and they fail to operate properly. Homing feed I use 250. And I set homing Beyoncé to 75. This gives quick and accurate homing every time.
Richard
A5 2.5W w/homing switches on L7
A5 2W diode self upgraded from stock 500mw
Printrbot Play. Ext bed, integrated tablet control.
Printrbot Simple Metal
USA

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Limit Switches
« Reply #31 on: October 13, 2016, 10:20:29 AM »
Appologies if this is not the "main thread" for limit switches, was the closest I could find.

I added limit switches to my L7 board. Recompiled Grbl 1.0c (after replacing bootloader on my Nano, and and telling Arduino IDE to treat it as an Uno. Arduino IDE sets max 30kB for the Nano due to old bootloader).

I just checked if the default Grbl pins were connected to anything else on the PCB, and solder on wires which I ran to a breadboard next to the L7. So I added probe, coolant, x,y,z limits and also step/dir for Z axis to my breadboard. Only wired up hardware for two limit switches for homing for now though, more will follow.

So the before mentioned limited capacity in the Nano I think could be an artifiact from outdated boards.txt in the Arduino Ide imposing a 30kB instead of 31.5kB firmware limit on a Nano. Instead of changing my boards.txt I just flashed the optiboot bootloader to the Nano with the settigns for a Uno as it solves the "problem" across all versions of the IDE.

I see most are talking about using a single pin for both axis, but this requires homing to be sequential instead of simultaneous. Using two pins makes much faster homing as both axes travel at the same time.

So I used (note i changed the optional HOMING_CYCLE_1 to HOMING_CYCLE_0, and left the other cycles commented out.
Code: [Select]
#define HOMING_CYCLE_0 ((1<<X_AXIS)|(1<<Y_AXIS))  // OPTIONAL: Then move X,Y at the same time.instead of
Code: [Select]
#define HOMING_CYCLE_0 ((1<<X_AXIS))
#define HOMING_CYCLE_1 ((1<<Y_AXIS))

And did that work?

beikeland

  • Guest
Re: Limit Switches
« Reply #32 on: October 13, 2016, 10:30:54 AM »
And did that work?
Yeah. If we ignore the fact that it stops seeking for home after a few mm. Between jobs i seem to need to do G0 X0 Y0 and then $H, but I see the same with separate homing cycles for each axis. So thats another problem for another time.

Really no wrong way to do it, as long as it works. If you want a bit faster homing then going multi pin was the best.
Oh, my bad, I wasn't trying to say this or that is better, merely that the other posts reads that this is the only way, and also I read that the Uno had more flash or ram than the Nano, which isn't trure - both have the same CPU, but different entries in the Arduino IDE boards.txt, and different bootloaders. No reason a nano cannot be updated to the same as a Uno. Just offering different points of view.

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Limit Switches
« Reply #33 on: October 13, 2016, 10:40:21 AM »
Cool! I like your approach. And yes, they both have the Atmel ATMEGA328P chip. That reminds me, I still have some virgin 328Ps in my parts box that need a good home on a PCB somewhere :)

Lob0426

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1622
  • Let the Magic Blue Smoke out!
    • View Profile
    • Richards RasPi Web Server
Re: Limit Switches
« Reply #34 on: October 13, 2016, 11:19:45 AM »
The Difference between the Uno and Nano is not the physical amount of memory. It is the available amount of memory. This is due to the bootloader. On the Nano there is 2K installed into storage for the bootloader. On the Uno the majority of boot is handled by the 16U2 chip (USB to serial). So the Uno only has .5K in storage. That makes a 1.5K advantage to the Nano!

Quote
Yeah. If we ignore the fact that it stops seeking for home after a few mm. Between jobs i seem to need to do G0 X0 Y0 and then $H, but I see the same with separate homing cycles for each axis. So thats another problem for another time.

You should not have to do that. Check your EEPROM settings
$130=225.000 (x max travel, mm)
$131=125.000 (y max travel, mm)
$132=170.000 (z max travel, mm)
The distance that grbl will seek home is a multiplier of these settings

// Adjusts homing cycle search and locate scalars. These are the multipliers used by Grbl's
// homing cycle to ensure the limit switches are engaged and cleared through each phase of
// the cycle. The search phase uses the axes max-travel setting times the SEARCH_SCALAR to
// determine distance to look for the limit switch. Once found, the locate phase begins and
// uses the homing pull-off distance setting times the LOCATE_SCALAR to pull-off and re-engage
// the limit switch.
// NOTE: Both of these values must be greater than 1.0 to ensure proper function.
// #define HOMING_AXIS_SEARCH_SCALAR  1.5 // Uncomment to override defaults in limits.c.
// #define HOMING_AXIS_LOCATE_SCALAR  10.0 // Uncomment to override defaults in limits.c.

Are your switches NO (Normally Open) or NC (Normally closed). You might see this if your switches are NC. There is a setting in config.h to cure this!

// Inverts select limit pin states based on the following mask. This effects all limit pin functions,
// such as hard limits and homing. However, this is different from overall invert limits setting.
// This build option will invert only the limit pins defined here, and then the invert limits setting
// will be applied to all of them. This is useful when a user has a mixed set of limit pins with both
// normally-open(NO) and normally-closed(NC) switches installed on their machine.
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
// #define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable.

Hope this helps

I did not take it that way! we get stuck talking about "stock" hardware because that is all that is available for now. That is going to change!
Richard
A5 2.5W w/homing switches on L7
A5 2W diode self upgraded from stock 500mw
Printrbot Play. Ext bed, integrated tablet control.
Printrbot Simple Metal
USA

beikeland

  • Guest
Re: Limit Switches
« Reply #35 on: October 13, 2016, 03:29:43 PM »
The Difference between the Uno and Nano is not the physical amount of memory. It is the available amount of memory. This is due to the bootloader. On the Nano there is 2K installed into storage for the bootloader. On the Uno the majority of boot is handled by the 16U2 chip (USB to serial). So the Uno only has .5K in storage. That makes a 1.5K advantage to the Nano!
Partly true, my Nano had 2kB bootloader and could not fit Grbl 1.0c until I installed the same bootloader as on the Uno (optiboot, works on most ATMega chips and uses 0.5kB on all of them). So if you have a ICP or a spare Arduino to  act as an ICP you can turn 'any' Arduino board into one that can use 31.5kB regardless of what serial converter it has. One of the other users here reported his Nano already had Optiboot installed, but the Arduino IDE will still think the Nano is limited to 30kB if the entry on boards.txt is not updated, or a different board than Nano is selected in the IDE. Using another uploader than the Arduino IDE removes that "sanity" check, so its only a problem if you have an old Nano, and compile/upload through the IDE, but replacing the bootloader fixes it in any case.

Are your switches NO (Normally Open) or NC (Normally closed). You might see this if your switches are NC. There is a setting in config.h to cure this!
They are NPN with leads for both NC and NO, the plan was to wire them up NC so I probably did that. Which I thought should fit with the active low description in Grbl. But since homing kinda works its been pushed a bit down on the list. But thanks, I'll look into those settings!:)

Lob0426

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1622
  • Let the Magic Blue Smoke out!
    • View Profile
    • Richards RasPi Web Server
Re: Limit Switches
« Reply #36 on: October 13, 2016, 03:58:48 PM »
Default settings are for NO. So all you should have to do is change;
// #define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable
#define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable

That should get you running. My switches also can be NC or NO.

I get the low memory warning on the Nano but grbl1.1c2 seems to be working just fine. I opened the buffers back up to their default on advice from the Grbl Developer @Chamnit (Sonny Jeon) in the Open Builds Forum. This release is behind just a bit from yesterday. But it is really smooth in operation. I have the newest but waiting until tomorrow to build it as I just built this version today!

Very happy with it!
If you run across @Chamnit be sure to thank him and the others for their work!
Richard
A5 2.5W w/homing switches on L7
A5 2W diode self upgraded from stock 500mw
Printrbot Play. Ext bed, integrated tablet control.
Printrbot Simple Metal
USA

beikeland

  • Guest
Re: Limit Switches
« Reply #37 on: October 13, 2016, 05:45:04 PM »
I get the low memory warning on the Nano but grbl1.1c2 seems to be working just fine.
Not refering to the low memory warning.

This is the result of the modified Nano (with 0,5kB optiboot bootloader) and unmodified Arduino IDE:
Code: [Select]
Sketch uses 30,984 bytes (100%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,495 bytes (72%) of dynamic memory, leaving 553 bytes for local variables. Maximum is 2,048 bytes.
processing.app.debug.RunnerException: Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
at cc.arduino.Compiler.size(Compiler.java:335)
at cc.arduino.Compiler.build(Compiler.java:159)
at processing.app.SketchController.build(SketchController.java:641)
at processing.app.SketchController.exportApplet(SketchController.java:666)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2176)
at java.lang.Thread.run(Thread.java:745)
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.

This is because the original Nano has the 2kB bootloader, and in boards.txt it has .upload.maximum_size=30720, so it cannot accept sketches over 30kB even if you replace the bootloader the IDE will give the same message. So after uploading the new 0.5kB bootloader and setting the new fuses (in lazynes I just chose Uno as the board and selected burn bootloader, this works except the bootloader now has the wrong baud rate for a "Nano" board, but I just let the IDE think its a Uno and its all fine. Alternatively I could add a new boards.txt file to my Arduino with an entry for a Optiboot Nano with 115200 baud, but thats still only something that works on one computer. Pretending its a Uno works on all computers).

So doing nothing but selecting Uno as my board (after burning the new bootloader) the above error changes to upload successful:
Code: [Select]
Sketch uses 30,984 bytes (96%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,495 bytes (72%) of dynamic memory, leaving 553 bytes for local variables. Maximum is 2,048 bytes.
C:\Arduino\hardware\tools\avr/bin/avrdude -CC:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM4 -b115200 -D -Uflash:w:C:\.....\arduino_build_567046/grblUpload.ino.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
...
avrdude: verifying ...
avrdude: 30984 bytes of flash verified

avrdude done.  Thank you.

beikeland

  • Guest
Re: Limit Switches
« Reply #38 on: October 14, 2016, 04:26:18 AM »
Default settings are for NO. So all you should have to do is change;
// #define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable
#define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable

That should get you running. My switches also can be NC or NO.
Thanks man! I assumed that setting had the same effect as $23, but defining the invert mask, made the axis seek for home in the reverse direction, and for the length of the max travel defined (multiplied by the scalar). Then setting $23=3 got me moving in the correct direction, and across the whole travel area.

Then adding #define HOMING_FORCE_SET_ORIGIN gave me 0,0 as coordinates after homing. Now its all good!

I used LJ12A3-2-Z/CX Inductive sensors with M12 threads. Drilled and tapped for the X axis, placed a piece of aluminium tape on the X axis carriage. Y axis I took the sample wood and drilled out two 6mm holes to match the scres holding the acrylic to the frame, and a 12mm hole for the sensor to just clear the wire and connect with the gantry. Again a piece of alumunium tape on the gantry to the inductive sensor has metal to detect. The M12 treaded body of the sensors makes adjusting distances really easy, but they are longer than their rectangular siblings.
(The LJ12A3-2-Z/AX sensors are a bit cheaper, as they are only NC, while /CX has both NC & NO outputs.)

The Z part in LJ12A3-2-Z/CX indicates 6-30V, but I find it works with 5V as well. Although it should be okay to supply sensors with 12V and stll connect the signal out directly to the arduino as the NPN output is floating, and pulled up to 5V when inactive, and pulled down when active.

Lob0426

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1622
  • Let the Magic Blue Smoke out!
    • View Profile
    • Richards RasPi Web Server
Re: Limit Switches
« Reply #39 on: October 14, 2016, 09:41:27 AM »
Thanks man! I assumed that setting had the same effect as $23.

Your welcome.
I knew it was different as I have read about every single comment in grbl trying to get a handle on it. I have some similar to this;
http://www.ebay.com/itm/LJ12A3-4-Z-BY-Inductive-Proximity-Sensor-Switch-PNP-DC-6V-36V-NEW/281813759464?_trksid=p2045573.c100505.m3226&_trkparms=aid%3D555014%26algo%3DPL.DEFAULT%26ao%3D1%26asc%3D38530%26meid%3D2d2d10172adb48d18ebcb82959db5f11%26pid%3D100505%26rk%3D1%26rkt%3D1%26
For my Printrbot 3D Printers. A bit on the large size for my A5 sized printer!
Richard
A5 2.5W w/homing switches on L7
A5 2W diode self upgraded from stock 500mw
Printrbot Play. Ext bed, integrated tablet control.
Printrbot Simple Metal
USA