element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NanoRama
  • Challenges & Projects
  • Project14
  • NanoRama
  • More
  • Cancel
NanoRama
Blog Adding Z Align (Laser Focus) Button to LaserGRBL
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NanoRama to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 30 Apr 2020 5:03 AM Date Created
  • Views 7213 views
  • Likes 5 likes
  • Comments 2 comments
  • lasergrbl
  • nanoramach
  • vl6180x
  • microview
Related
Recommended

Adding Z Align (Laser Focus) Button to LaserGRBL

ralphjy
ralphjy
30 Apr 2020
image

NanoRama

Enter Your Project for a chance to win a Nano Grand Prize bundle for the most innovative use of Arduino plus a $400 shopping cart!

Submit an EntrySubmit an Entry  Back to homepage image
Project14 Home
Monthly Themes
Monthly Theme Poll

 

I'm jumping ahead a little to make sure I can add the required focusing functionality to the LaserGRBL program.  I'm used to the method that 3D printers use to home their axes which is to move into the limit switches.  After reading through the GRBL documentation I realized that moving into the hard limit switches actually causes an alarm condition which requires a reset.  Since GRBL 0.9, a "probe" function has been added that is commonly used to set the Z-axis position, so I'm going to use that input rather the Zend input to signal that I've reached the focus position.

 

Here is a picture of the top of my controller board with the interface connector highlighted and the schematic that shows the Probe input.

image

 

I'll need to wire a digital output from the MicroView to the Probe input and program that output to switch high when the VL6180X measured distance is 39 mm.

 

Then I'll need to create a custom button within LaserGRBL to execute the alignment code.  It turns out creating the custom button is straightforward.  You right click in the button bar at the bottom and it brings up a dialog to create/edit the custom button.

 

Here is a screenshot of the LaserGRBL Control Panel:

image

 

You can see the custom "Z Focus" button that I created at the left.

image

 

And here is the custom button edit panel:

image

 

The gcode for testing is very simple.

G92 Z0 sets the current Z position to 0

G38.2 Z-10 F100 is the probe command that moves Z down -10 mm at a speed of 100 mm/min.  The travel will stop when the "Probe" input is pulled low or Z-10 is reached - whichever comes first.  An alarm will occur if the "Probe" input does not switch before the endpoint is reached.

G92 Z0 sets the new position to be Z0

 

The procedure will be to set the laser head so that the distance measurement is >= 45 mm and then hit the Z Focus button.  The Z position should now be aligned when the head stops.

 

There's probably some tweaking that I need to do relative to the speed (feed rate) that the head moves down.  Maybe do an initial align at higher speed and back off and align again at a slower speed.

 

Modified MicroView Code

 

MicroView_V6180X_InterleavedContinuous.ino

/* This example demonstrates how to use interleaved mode to
take continuous range and ambient light measurements. The
datasheet recommends using interleaved mode instead of
running "range and ALS continuous modes simultaneously (i.e.
asynchronously)".

In order to attain a faster update rate (10 Hz), the max
convergence time for ranging and integration time for
ambient light measurement are reduced from the normally
recommended defaults. See section 2.4.4 ("Continuous mode
limits") and Table 6 ("Interleaved mode limits (10 Hz
operation)") in the VL6180X datasheet for more details.

Raw ambient light readings can be converted to units of lux
using the equation in datasheet section 2.13.4 ("ALS count
to lux conversion").

Example: A VL6180X gives an ambient light reading of 613
with the default gain of 1 and an integration period of
50 ms as configured in this sketch (reduced from 100 ms as
set by configureDefault()). With the factory calibrated
resolution of 0.32 lux/count, the light level is therefore
(0.32 * 613 * 100) / (1 * 50) or 392 lux.

The range readings are in units of mm. */

#include <MicroView.h>
#include <Wire.h>
#include <VL6180X.h>

VL6180X sensor;

float dist, sens, csens, offset = 5.0;

int count;
int probe_out;  // probe output pin

void setup()
{
  probe_out = A0;  // MicroView pin 7
  pinMode(probe_out, OUTPUT);  // set to output pin
  digitalWrite(probe_out, HIGH);  // initialize high
  
  Wire.begin();

  sensor.init();
  sensor.configureDefault();

  // Reduce range max convergence time and ALS integration
  // time to 30 ms and 50 ms, respectively, to allow 10 Hz
  // operation (as suggested by Table 6 ("Interleaved mode
  // limits (10 Hz operation)") in the datasheet).
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 05);
  //sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 10);

  sensor.setTimeout(500);

   // stop continuous mode if already active
  sensor.stopContinuous();
  // in case stopContinuous() triggered a single-shot
  // measurement, wait for it to complete
  delay(300);

 //READOUT__AVERAGING_SAMPLE_PERIOD
  sensor.writeReg(0x10A, 0x08);
  
  // start interleaved continuous mode with period of 100 ms
  //sensor.startInterleavedContinuous(100);
  sensor.startRangeContinuous(10);

  Serial.begin(57600);
  uView.begin();
  uView.clear(PAGE);
  uView.setFontType(0);
  uView.display();

//ideas
// Look at docs to see how to improve accuracy
// only use samples that converged
// look into whether samples are used twice or other issues with the uncontrolled loop
// allow more variability in the output of the sensor and average in the mcu
// measure drift by connecting to the CNC machine to get precise moves

count=100;
}

void loop()
{
  //Serial.print("Ambient: ");
  //Serial.print(sensor.readAmbientContinuous());
  //if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  sens=sensor.readRangeContinuous();

  csens =sens + offset;
//  uView.clear(PAGE);
//  uView.display();
//  uView.setCursor(0,0);
//  uView.println("Distance:");

 if(sens<255)
 {
  if( abs(csens-dist)>10.0) {dist=csens;}
  dist = .995* dist + .005 * csens;
 }

 count=count-1;
 if (count ==0)
 {
  count=100;
  //Serial.print("\t Range: ");
  Serial.print(dist);
  Serial.println();
  uView.clear(PAGE);
  uView.setCursor(0,0);
  uView.println("Distance:");
  uView.print(dist);
  uView.println(" (mm)");
  uView.display();
  if (dist <= 39.0)
  {
    digitalWrite(probe_out, LOW);
  } else {
    digitalWrite(probe_out, HIGH);
  }
 }
  
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

}

 

Testing

I updated the MicroView program and mounted the assembly on the laser head.  I am using the A0 pin as my "probe" signal so I wired that to the Probe input of the GRBL controller.

 

The first couple of tries failed with no probe detection so I thought that I had mis-wired the probe signal, but it turned out that I had set the feed rate so that it was too fast for the response time of the probe detection in the GRBL program.  The setting that I was using was 100 mm/min.  I saw that for mechanical probes examples they were using 10 mm/min but I thought that was because they were worried about over travel into a hard surface.  I played with the speed a bit and determined that 20 mm/min worked reliably but because of the heavy averaging that I would overshoot the 39 mm target.  I decided to do the initial align at 20 mm/min and then back off 2 mm and realign at at 2 mm/min.

 

Here is the updated button program:

image

 

Here's a quick video of the focus alignment.  I apologize that the webcam doesn't focus well on the display.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

So, I'm close but I still need to do the VL6180X sensor characterization and then tweak the program and the alignment control to get repeatable values.  Before I do that I'm going to clean up the mounting and the wiring.

  • Sign in to reply
Parents
  • DAB
    DAB over 5 years ago

    Good progress.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 5 years ago

    Good progress.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube