Quote Originally Posted by 109jb View Post
BrendaEM,
This post is for you. I am sorry that this thread has taken this direction. You originally asked if there was a G-code interpreter that would work on an Arduino Mega. GRBL is probably the best option out there, or one of its derivatives. You can check out GRBL at their github site https://github.com/grbl/grbl/wiki GRBL does have a limited set of supported G-codes, but many users have worked around this limitation and are happy with the results. As you can tell others aren’t so happy with GRBL’s progress. I for one am very happy with it and it performs well for me.

Since you already have the hardware it costs you nothing to try. There are a few simple tasks to perform to get it operating on a Mega. Once downloaded you will need to edit the config.h file and change the following line:

#define CPU_MAP_ATMEGA328P
To
#define CPU_MAP_ATMEGA2560

That change will allow you to upload GRBL to your Mega. The pin mapping description can be found in the cpu_map_atmega2560.h file in the cpu_map folder.
If you need any help feel free to ask and I or someone else will try to help.
I agree with 109jb, if you can live with the minimal supported gcodes GRBL is a suitable candidate for your project.

Along with the map re-assignment offered by 109jb I also recommend assigning the unused pins (some as inputs and some as outputs) for additional IO usage, the source has easy to find example uses of IO pins for things like FWD/REV, FLOOD and MIST which you can use as templates for the additional IO's since the 2560 has extras you lose nothing by assigning them for expansion use for that "just in case" you need them as your project takes on a life of it's own.

If three axis is insufficient you can add a fourth and/or fifth axis with little effort by following the current axis code with some minor code additions/modifications.

FLOOD (M7) and MIST (M8) are good easy to follow examples of mcodes and you can find a list of mcodes in linuxcnc and Mach3 that do various tasks and add the ones you think are beneficial to your project if you need/want them.

Spindle FWD/REV (M3/M4) is a good example of tasking a single pin as dual purpose for things like a tool changer carousel FWD/REV or tool changer shuttle EXTEND/RETRACT.

A digital position tool changer is very fast and requires about 8 to 10 pins for various tasks and a lathe turret or auto-tool-post requires about 4 to 8 pins, these are very simple to implement and code in GRBL if you need these features and I'm sure myself or half a dozen others can offer you assistance in tweaking the code to fit your specific needs should you run into some problems.

PIN ASSIGNMENT:
Code:
/*
********************************************************
Atmega640/1280/2560
pin numbers | assignment	D/A = 54/16
********************************************************

DIGITAL:
(RXD0/PCIINT8) D0 PE0			|02		|0
(TXD0) D1 PE1				|03		|1
(OC3B/INT4) D2 PE4		(PWM)	|06		|2
(0C3C/INT5) D3 PE5		(PWM)	|07		|3
(OC0B) D4 PG5			(PWM)	|01		|4
(OC3A/AIN1) D5 PE3		(PWM)	|05		|5
(OC4A) D6 PH3			(PWM)	|15		|6
(OC4B) D7 PH4			(PWM)	|16		|7
(OC4C) D8 PH5			(PWM)	|17		|8
(OC2B) D9 PH6			(PWM)	|18		|9
(OC2A/PCINT4) D10 PB4		(PWM)	|23		|10 (JP6)
(OC1A/PCINT5) D11 PB5		(PWM)	|24		|11 (JP6)
(OC1B/PCINT6) D12 PB6		(PWM)	|25		|12 (JP6)
(OC0A/0C1C/PCINT7) D13 PB7	(PWM)	|26		|13 (JP6)
(TXD3/PCINT10) D14 PJ1			|64		|14
(RXD3/PCINT9) D15 PJ0			|63		|15
(TXD2) D16 PH1				|13		|16
(RXD2) D17 PH0				|12		|17
(TXD1/INT3) D18 PD3			|46		|18
(RXD1/INT2) D19 PD2			|45		|19
(SDA/INT1) D20 PD1			|44		|20
(SCL/INT0) D21 PD0			|43		|21
(AD0) D22  PA0				|78		|22
(AD1) D23 PA1				|77		|23
(AD2) D24 PA2				|76		|24
(AD3) D25 PA3				|75		|25
(AD4) D26 PA4				|74		|26
(AD5) D27 PA5				|73		|27
(AD6) D28 PA6				|72		|28
(AD7) D29 PA7				|71		|29
(A15) D30 PC7				|60		|30
(A14) D31 PC6				|59		|31
(A13) D32 PC5				|58		|32
(A12) D33 PC4				|57		|33
(A11) D34 PC3				|56		|34
(A10) D35 PC2				|55		|35
(A9) D36 PC1				|54		|36 (ICSP-5)
(A8) D37 PC0				|53		|37
(T0) PD7				|50		|38
(ALE) PG2				|70		|39
(RD) PG1				|52		|40
(WR) PG0				|51		|41
PL7					|42		|42
PL6					|41		|43
(OC5C) PL5			(PWM)	|40		|44
(OC5B) PL4			(PWM)	|39		|45
(OC5A) PL3			(PWM)	|38		|46
(T5) PL2				|37		|47
(ICP5) PL1				|36		|48
(ICP4) PL0				|35		|49
(MISO/PCINT3) PB3			|22		|50 (ICSP-3)
(MOSI/PCINT2) PB2			|21		|51 (ICSP-4)
(SCK/PCINT1) PB1		(PWM)	|20		|52 (ICSP-1)
(SS/PCINT0) PB0				|19		|53

********************************************************

ANALOG:
(ADC0) A0 PF0				|97		|0
(ADC1) A1 PF1				|96		|1
(ADC2) A3 PF2				|95		|2
(ADC3) A3 PF3				|94		|3
(ADC4/TCK) A4 PF4			|93		|4
(ADC5/TMS) A5 PF5			|92		|5
(ADC6/TDO) A6 PF6			|91		|6
(ADC7/TDI) A7 PF7			|90		|7
(ADC8/PCINT16) A8 PK0			|89		|8
(ADC9/PCINT17) A9 PK1			|88		|9
(ADC10/PCINT18) A10 PK2			|87		|10
(ADC11/PCINT19) A11 PK3			|86		|11
(ADC12/PCINT20) A12 PK4			|85		|12
(ADC13/PCINT21) A13 PK5			|84		|13
(ADC14/PCINT22) A14 PK6			|83		|14
(ADC15/PCINT23) A15 PK7			|82		|15

********************************************************

WASTED_PINS: (WHAT A SHAME AS MORE IO WOULD BE NICE)
(XCK0/AIN0) D2 PE2			|04		| (NOT-USED)
(T3/INT6) D6 PE6			|08		| (NOT-USED)
(CLK0/ICP3/INT7) D7 PE7			|09		| (NOT-USED)
(XCK2) D10 PH2				|14		| (NOT-USED)
(T4) D22 PH7				|27		| (NOT-USED)
(TOSC2) D23 PG3				|28		| (NOT-USED)
(TOSC1) D24 PG4				|29		| (NOT-USED)
(ICP1)	D37 PD4				|47		| (NOT-USED)
(XCK1)	D38 PD5				|48		| (NOT-USED)
(T1)	D39 PF6				|49		| (NOT-USED)
(XCK3/PCINT11) D53 PJ2			|65		| (NOT-USED)
(PCINT12) D54 PJ3			|66		| (NOT-USED)
(PCINT13) D55 PJ4			|67		| (NOT-USED)
(PCINT14) D56 PJ5			|68		| (NOT-USED)
(PCINT15) D57 PJ6			|69		| (NOT-USED)
D59 PJ7					|79		| (NOT-USED)

********************************************************
*/