Hello!
The cnc machine I build has replaceable “overlays” on the Z axis. I can install a spindle or a laser. Of course, only one type is used at a time.
I came up with the idea to connect a switch to IO27 and choose whether to use a laser or a spindle before starting.
!schematic
Based on the status on IO27, I want to choose “SPINDLE_TYPE”, so I wrote a short code in the “Custom” folder.
Should I choose “SPINDLETYPE” in the machines.h file, which will be overwritten by Customcode.cpp?
(Of course, both files have the same name)
Custom_code.cpp
“
#ifdef USEMACHINEINIT
void machine_init()
{
pinMode(LASER/SPINDLEPIN, INPUTPULLUP);
if (digitalRead(LASER/SPINDLE_PIN) == 0)
{
#define SPINDLETYPE SPINDLETYPE_LASER
}
else
{
#define SPINDLETYPE SPINDLETYPE_PWM
}
}
#endif
`
Machines.h
`
#define MACHINENAME "CNCGREENMAGIC"
#define USEMACHINEINIT
#define N_AXIS 4
#define XSTEPPIN GPIONUM2
#define XDIRECTIONPIN GPIONUM15
#define YSTEPPIN GPIONUM0
#define YDIRECTIONPIN GPIONUM4
#define ZSTEPPIN GPIONUM12
#define ZDIRECTIONPIN GPIONUM13
#define ASTEPPIN GPIONUM33
#define ADIRECTIONPIN GPIONUM21
#define STEPPERSDISABLEPIN GPIONUM22
#define LASER/SPINDLEPIN GPIONUM_27 // connected to ground= laser
//#define SPINDLETYPE SPINDLETYPE_PWM // only one spindle at a time
#define SPINDLEOUTPUTPIN GPIONUM25 //DAC 1
#define SPINDLEENABLEPIN GPIONUM26 //DAC 2
#define XLIMITPIN GPIONUM34 //needs external pullup
#define YLIMITPIN GPIONUM35 //needs external pullup
#define ZLIMITPIN GPIONUM32
#define LIMIT_MASK B111
#define CONTROLRESETPIN GPIONUM17 // labeled Reset
#define CONTROLFEEDHOLDPIN GPIONUM_39 // SVN labeled Hold, needs external pullup
#define CONTROLCYCLESTARTPIN GPIONUM_36 // SVP labeled Start, needs external pullup
#define PROBEPIN GPIONUM_14
#define COOLANTMISTPIN GPIONUM16
“
Is my idea good?
Regards, Szymon from Poland