Page 1 of 1

External laser modulator with Arduino Nano

PostPosted: Mon Feb 05, 2024 9:59 pm
by muxer
So I've made workaround solution to the old problem of adjusting laser output by realtime speed of the head to make uniform engraving/cutting of varying size elements.

To make this set-up you will only need Arduino Nano, a few wires and USB cable.

Nano reads data in short timeframes of about 4ms, counting pulses from X and Y outputs of the controller and reads PWM from the laser output. Nano is also receiving Fset value though the serial port from macro loop on startup and upon any change.
Based on calculated head speed and predefined Fset it modifies PWM signal to match speed of laser head travel.

How to make it work:
  • Edit Arduino code and set your IO pin numbers and your actual pulse per mm. Note that X and Y pins need to support interrupts and output pin needs to support PWM. Compile and upload.
  • Make sure you have USB-Serial drivers on the machine where UCCNC is running.
  • Connect inputs/outputs, check that you have common ground. Connect Arduino to USB port.
  • Add macro file, edit COM port number to match your set-up. Set-up macro loop to run automatically.

laser_modulator.txt
Arduino code, change extension to .ino
(3.44 KiB) Downloaded 322 times

M301.txt
Macro loop
(602 Bytes) Downloaded 317 times


Results for my application are very good, I'm now able to cut vector text and graphics with same parameters and 2x-3x faster as I'm now using most of the power of my laser. Before I hade to use low Fset with low laser power to get quality results.
I did not test it with raster engraving yet, there may be issues with higher speeds and 4ms approximation cycle though, but this may be adjusted to as low as PWM cycle allows, however short cycles result in higher errors on XY counters as well.

Re: External laser modulator with Arduino Nano

PostPosted: Tue Feb 06, 2024 3:04 pm
by cncdrive
Thank you for sharing.
And how does it exactly connecting to the laser controller?
It modifies the laser PWM depending on the Fset and measured step/dir defined feedrates?

Re: External laser modulator with Arduino Nano

PostPosted: Tue Feb 06, 2024 4:43 pm
by muxer
Yes, it measures actual speed (no need to measure dir, only pulse for this purpose), divides it by Fset and multiplies PWM that it measured on laser output pin of UCCNC by this coefficient, then writes PWM on its own output pin, which goes directly to the laser input (my laser accepts any PWM signal in 3.3-12V range).

BTW what is the laser PWM frequency? With 500us maximum read time seems near correct value, but I'm not sure.

Re: External laser modulator with Arduino Nano

PostPosted: Fri Feb 09, 2024 10:29 am
by muxer
Updated version, now it adjusts estimation window size dynamically based on amount of pulses received and desired accuracy, lowering estimation errors when movements are slow and reducing delay when movements are fast. Also some math overflow bugs fixed.

Also make sure you don't feed anything above 5V to arduino inputs, add voltage dividers if you have higher pull-up voltage on your motor drivers!

Re: External laser modulator with Arduino Nano

PostPosted: Sat May 11, 2024 11:19 am
by Battwell
i like this.
some nice coding :-)
it says only certain boards accept the Serial.Readstring()
is this only arduino nano?

i have not played with arduino for good few years now since i did my modbus control panel.

Re: External laser modulator with Arduino Nano

PostPosted: Sun May 12, 2024 11:27 am
by muxer
I've read that on some boards serial.readString() may not work, don't remember the list so better to check. Obviously this can be rewritten with just Serial.read and avoid String class completely, I was a bit lazy :)