# script to make gcode file for the 3D printer with a laser # that burns paint off a coated PCB before etching. # by Lawrence Glaister VE7IT 5 Dec 2018 # # note: requires modifications to /opt/flatcam/camlib.py # to convert G00 and G01 cmds to G0 and G1 (required by marlin) # add M106 and M107 laser on off commands # clean up some feed rate commands that arent recognized by marlin # # run this file with: # python2 /opt/flatcam/FlatCAM.py --shellfile=/home/lg/Desktop/make_gcode.flatcam # 3 input gerbers needed to etch bottom side set bottom_traces_gbr "/home/lg/Desktop/loop-amp-B.Cu.gbr" set cutout_gbr "/home/lg/Desktop/loop-amp-Edge.Cuts.gbr" set drill_drl "/home/lg/Desktop/loop-amp-PTH.drl" # filename for output gcode for 3D printer (laser etching machine) set laser_etch_fn "/home/lg/Desktop/laser_etch.gcode" set project_fn "/home/lg/Desktop/loop-amp.fcp" # variables you may need to adjust to get good results # parameters used in laser isolation stage # laser spot diameter (mm) set laser_d 0.125 # passes used for etch edge isolatiom set laser_passes 4 # how much the laser moves over between passes (mm) set laser_overlap 0.062 # the z height for the laser (adjust focus to top of PCB) (mm) set laser_z 50.0 # how fast we move while burning (need to go slow enough to remove paint) (mm/min) # 1/2w 405nm laser burns paper nicely at 750mm/min at 500mm/min it just burns through set laser_feed 750.0 # adjust these offsets (in mm) to position laser scans onto the 3D printer bed # note where the gerber is displayed on the flatcam screen... # we need to move it up into the proper position on the printer table. #try to land about the middle of the 3d printer table... # remember that laser is offset from extrusion nozzle by approx -50,-20mm set offset_x 2 set offset_y 190 # you should not need to change anything below this line #======================================================================= # proc to build a string that contains a list of the tool numbers defined in the # excellon drill file proc count_tools {} { global drill_drl set fptr [open $drill_drl r] set retstr "" set first 1 while {[gets $fptr line] > -1} { # process lines looking for tools > T0 if {[regexp {^T(\d$)} $line -> num]} { if { $num > 0 } { if { $first == 1 } { set first 0 } else { append retstr "," } append retstr $num } } } close $fptr return $retstr } # create a new project new #set_sys set_sys units MM #set_sys cncjob_coordinate_format "X%.4f Y%.4f" #set_sys coordinate_format "X%.4f Y%.4f" # the following params define the laser spot size #set_sys geometry_cnctooldia $laser_d #set_sys gerber_isotooldia $laser_d #set_sys cncjob_tooldia $laser_d #set_sys gerber_cutouttooldia $laser_d #set_sys excellon_tooldia $laser_d # following is about 1/2 the laser spot size #set_sys gerber_isooverlap 0.065 # the following defines the height off the board for the laser focus point # and where the laser moves around in Z #set_sys excellon_travelz $laser_z #set_sys excellon_drillz $laser_z #set_sys geometry_travelz $laser_z #custom gcode needed for marlin 3D printer setup #set_sys cncjob_prepend "(Generated by flatcam and make_gcode.sh)\nG21 (metric)\nG28 (home)\nM107 S0 (laser off)\nG1 Z50.0 F500.0\n" #set_sys cncjob_append "M107 S0 (laser off)\nG1 X0.000 Y250.0 Z50.0 F500.0 (go park)\n" #set_sys geometry_feedrate $laser_feed #set_sys excellon_feedrate $laser_feed #set_sys gerber_isopasses 4 #set_sys gerber_gaps 4 #set_sys gerber_cutoutgapsize 1.0 #set_sys gerber_combine_passes true #set_sys cncjob_dwelltime 0 #set_sys geometry_cutz $laser_z # open_gerber [-follow ] [-outname ] open_gerber $bottom_traces_gbr -outname bottom_traces_grb open_gerber $cutout_gbr -outname cutout_grb # open_excellon [-outname ] open_excellon $drill_drl -outname drill_drl # flip the gerbers so we are looking the bottom of the board mirror bottom_traces_grb -axis Y -box cutout_grb mirror drill_drl -axis Y -box cutout_grb offset bottom_traces_grb $offset_x $offset_y offset cutout_grb $offset_x $offset_y offset drill_drl $offset_x $offset_y plot # isolate [-dia ] [-passes ] [-overlap ] [-combine ] [-outname ] isolate bottom_traces_grb -dia $laser_d -passes $laser_passes -overlap $laser_overlap -combine 1 -outname trace_iso_geo # millholes -tools -tooldia -outname millholes drill_drl -tools [count_tools] -tooldia $laser_d -outname holes_geo # cutout [-dia <3.0 (float)>] [-margin <0.0 (float)>] [-gapsize <0.5 (float)>] [-gaps ] cutout cutout_grb -dia $laser_d -margin 0.1 -gapsize 1.0 -gaps 4 # join_geometries .... join_geometries laser_etch_geo trace_iso_geo holes_geo cutout_grb_cutout # cncjob [-z_cut ] [-z_move ] [-feedrate ] [-tooldia ] [-spindlespeed ] [-multidepth ] [-depthperpass ] [-outname ] cncjob laser_etch_geo -z_cut $laser_z -z_move $laser_z -feedrate $laser_feed -tooldia $laser_d -outname laser_etch_cnc # write_gcode write_gcode laser_etch_cnc $laser_etch_fn # save_project #in case we want to redo something save_project $project_fn puts "Your board should be displayed at about (100,70) on the screen\r\n" puts "Thats all folks\r\n"