External laser modulator with Arduino Nano

Here is where you can drop off Examples of WORKING macros,plugins,Gcode programs , macro Wizards etc.
Please give a brief description of what it is and how it works.

External laser modulator with Arduino Nano

Postby muxer » Mon Feb 05, 2024 9:59 pm

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 170 times

M301.txt
Macro loop
(602 Bytes) Downloaded 150 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.
muxer
 
Posts: 8
Joined: Thu Nov 23, 2023 8:11 pm

Re: External laser modulator with Arduino Nano

Postby cncdrive » Tue Feb 06, 2024 3:04 pm

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?
cncdrive
Site Admin
 
Posts: 4756
Joined: Tue Aug 12, 2014 11:17 pm

Re: External laser modulator with Arduino Nano

Postby muxer » Tue Feb 06, 2024 4:43 pm

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.
muxer
 
Posts: 8
Joined: Thu Nov 23, 2023 8:11 pm

Re: External laser modulator with Arduino Nano

Postby muxer » Fri Feb 09, 2024 10:29 am

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!
Attachments
laser_modulator.txt
Rename to *.ino
(4.65 KiB) Downloaded 154 times
muxer
 
Posts: 8
Joined: Thu Nov 23, 2023 8:11 pm

Re: External laser modulator with Arduino Nano

Postby Battwell » Sat May 11, 2024 11:19 am

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.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 833
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: External laser modulator with Arduino Nano

Postby muxer » Sun May 12, 2024 11:27 am

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 :)
muxer
 
Posts: 8
Joined: Thu Nov 23, 2023 8:11 pm


Return to UCCNC TOOL BOX

Who is online

Users browsing this forum: No registered users and 5 guests

cron