Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are some official project to port GRBL on Arduino Mega with RAMPS #561

Closed
onekk opened this issue Dec 24, 2014 · 29 comments
Closed

There are some official project to port GRBL on Arduino Mega with RAMPS #561

onekk opened this issue Dec 24, 2014 · 29 comments

Comments

@onekk
Copy link

onekk commented Dec 24, 2014

I have found some project on internet but they are not much in sync with GRBL, it was a pity not to use/support the widespread and cheap electronics from the reprap to use with CN.
I know that there are more project to use it but the fragmentation on efforts is the hell of the opensource project.

Regards

Carlo D. (onekk)

@cri-s
Copy link

cri-s commented Dec 25, 2014

http://sourceforge.net/projects/grblforramps14/ seems to be usable

@onekk
Copy link
Author

onekk commented Dec 25, 2014

Thanks, I know it, but the source code is modified in a strange way, not very integrated with the main codebase.

Carlo D. (onekk)

@EliteEng
Copy link
Contributor

At the moment the MEGA is not offically supported by GRBL, I have been doing my best to support the MEGA and keep the MEGA code fully functional.

GRBL is written to be very efficient with its writting to the step and direction ports and to make it so efficient all the step pins are on one port and all the direction pins are on one port.

The compatibility issue with the RAMPS board is that all the step and direction pins are on almost random ports to best suit the routing of the PCB.

There was a conversation going on about rewriting the section of the code to allow step pins and direction pins to be on completely seperate ports ( which will drop some efficiency but gain compatability ) which will most likely occur in Version 1.0

At the end of the day it is not that hard to do, but the extra code needed would exceed the flash space of the UNO ( the offically supported board )

If I get some time I will look into it.

@cri-s
Copy link

cri-s commented Dec 25, 2014

Sure that it will exceed the flash? If so there is the false approach.
It would only need adding STEP_PORT ram variable (uchar8_t)
after doing something:
STEP_PORT = (STEP_PORT & ~STEP_MASK) | (step_port_invert_mask & STEP_MASK);
update_step_pins(); // update pins , this must be added after every STEP_PORT usage

On 328 branch, the update_step_pins() is no op because there should be one
#define update_step_pins()
Instead on mega2560, update_step_pins() is defined inside cpu_map.c
#ifdef CPU_MAP_ATMEGA2560 // (Arduino Mega 2560) Working @EliteEng
void
update_step_pins() {
STEP_PORT&bit(X_AXIS)?bit_true(X_STEP_PORT,bit(X_STEP_PIN)):bit_false(X_STEP_PORT,bit(X_STEP_PIN));
STEP_PORT&bit(Y_AXIS)?bit_true(Y_STEP_PORT,bit(Y_STEP_PIN)):bit_false(Y_STEP_PORT,bit(Y_STEP_PIN));
//... other AXIS
}
#endif

@cri-s
Copy link

cri-s commented Dec 25, 2014

maybe not naming it CPU_MAP_ATMEGA2560 , instead name it PU_MAP_ATMEGA260_RAMPS_1_4
in order to not break anything.

@onekk
Copy link
Author

onekk commented Dec 25, 2014

It will be a very useful improvement, altough it is very available on the market, for example for shapeoko the gshield shipped from the us will cost 50$ plus 50$ of shipping (and it lacks of the Arduino) RAMPS with Arduino MEGA 2560, plus 3 endstop, plus cabling and fan will cost 80 Euro plus 10 Euros for shipping (from Spain to Italy) (it has 5 poulu drivers on it and an Arduino MEGA).

Regards

Carlo D.

@cri-s
Copy link

cri-s commented Dec 26, 2014

Can you write me down the pin mapping, using the constants on the ramps wiki for pinout.
The format is: assuming it is PF4 or PORTF4 and no invert , PF4 is a wrong supposition, just as example
#define X_STEP_PIN F,4,0
if the pin should be inverted
#define X_STEP_PIN F,4,1

I can code it, but cannot test it.

@onekk
Copy link
Author

onekk commented Dec 27, 2014

Yes i can write you down the pinout but i can't test it as my card isn't arrived yet, let me see if this is what you want?

// For RAMPS 1.4
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2

#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
#define Y_MIN_PIN 14
#define Y_MAX_PIN 15

#define Z_STEP_PIN 46
#define Z_DIR_PIN 48
#define Z_ENABLE_PIN 62
#define Z_MIN_PIN 18
#define Z_MAX_PIN 19

#define E_STEP_PIN 26
#define E_DIR_PIN 28
#define E_ENABLE_PIN 24

#define SDPOWER -1
#define SDSS 53
#define LED_PIN 13

#define FAN_PIN 9

#define PS_ON_PIN 12
#define KILL_PIN -1

#define HEATER_0_PIN 10
#define HEATER_1_PIN 8
#define TEMP_0_PIN 13 // ANALOG NUMBERING
#define TEMP_1_PIN 14 // ANALOG NUMBERING

This is what is on the wiki.
A Little note on the wiki says "RAMPS 1.4 uses the same pin definition as RAMPS 1.3" so maybe the settings will work also on RAMPS 1.3.

TIA and Regard

Carlo D.

@cri-s
Copy link

cri-s commented Dec 27, 2014

Yes, this is what i have extracted with awk. The lines where after "//" is "NA" is wrong, because it was -1
Just a hack for getting the file. As example #define SDPOWER A,7,0 // NA -- is such one.
What is function of SDPOWER and why it's -1. ? What analog channel is TEMP_0/1
Where do you put the probe pin ?

// For ,,0 // RAMPS --
#define X_STEP_PIN F,0,0 // 54 --
#define X_DIR_PIN F,1,0 // 55 --
#define X_ENABLE_PIN D,7,0 // 38 --
#define X_MIN_PIN D,3,0 // 3 --
#define X_MAX_PIN D,2,0 // 2 --

#define Y_STEP_PIN F,6,0 // 60 --
#define Y_DIR_PIN F,7,0 // 61 --
#define Y_ENABLE_PIN F,2,0 // 56 --
#define Y_MIN_PIN C,0,0 // 14 --
#define Y_MAX_PIN C,1,0 // 15 --

#define Z_STEP_PIN L,3,0 // 46 --
#define Z_DIR_PIN L,1,0 // 48 --
#define Z_ENABLE_PIN K,0,0 // 62 --
#define Z_MIN_PIN C,4,0 // 18 --
#define Z_MAX_PIN C,5,0 // 19 --

#define E_STEP_PIN A,5,0 // 26 --
#define E_DIR_PIN A,3,0 // 28 --
#define E_ENABLE_PIN A,7,0 // 24 --

#define SDPOWER A,7,0 // NA --
#define SDSS B,0,0 // 53 --
#define LED_PIN B,5,0 // 13 --

#define FAN_PIN B,1,0 // 9 --

#define PS_ON_PIN B,4,0 // 12 --
#define KILL_PIN B,4,0 // NA --

#define HEATER_0_PIN B,2,0 // 10 --
#define HEATER_1_PIN B,0,0 // 8 --
#define TEMP_0_PIN D,5,0 // 13 -- ANALOG NUMBERING
#define TEMP_1_PIN D,6,0 // 14 -- ANALOG NUMBERING

@onekk
Copy link
Author

onekk commented Dec 27, 2014

cri-s please these settings are a base to make the foundation of the PU_MAP_ATMEGA260_RAMPS_1_4 in cpu_map.h ?

i have give a look at hte source and din't see any resemblance of the format in it, as example i have #ifdef CPU_MAP_ATMEGA2560 // (Arduino Mega 2560) Working @EliteEng

// Serial port pins
#define SERIAL_RX USART0_RX_vect
#define SERIAL_UDRE USART0_UDRE_vect

// Increase Buffers to make use of extra SRAM
//#define RX_BUFFER_SIZE 256
//#define TX_BUFFER_SIZE 128
//#define BLOCK_BUFFER_SIZE 36
//#define LINE_BUFFER_SIZE 100

// Define step pulse output pins. NOTE: All step bit pins must be on the same port.
#define STEP_DDR DDRA
#define STEP_PORT PORTA
#define STEP_PIN PINA
#define X_STEP_BIT 2 // MEGA2560 Digital Pin 24
#define Y_STEP_BIT 3 // MEGA2560 Digital Pin 25
#define Z_STEP_BIT 4 // MEGA2560 Digital Pin 26
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
...
and so on .
I'm not so skilled in C programming, (my skills are a little pyhton and i can compile from sources and writing a template for my preferred distro Void-Linux), but i can put togheter a description like this in the cpu_map.h mapping the pins on the RAMPS)

Many thanks for your kindness

Regards

Carlo D.

@onekk
Copy link
Author

onekk commented Dec 27, 2014

from a quick look at the notes on the code, and at the pins from RAMPS i noted that "NOTE: All step bit pins must be on the same port.", maybe i can use the RAMPS shield (wich has 5 driver to drive the steppers) and wire them by hand with a flat cable and two connectors according the ATMEGA 2560 pinout by @EliteEng in the code (if it is functional).
For now this seems the feasible solutions without disturbing too much the codebase of GRBL (assuming that the ATMEGA 2560 from EliteEng is working)
and a side effect is that i maybe i could drive the dual Y axis motor wiring two stepper driver to the Y pins (step dir and en) port and wiring the stepper inverting the coils.

Regards

Carlo D.

@langwadt
Copy link

if the manipulation of input/output pins were #defines it should be easy to change the underlying code for different platforms and not change anything for the main grbl

@onekk
Copy link
Author

onekk commented Dec 27, 2014

Langwalt, it seems that your statement is not true as is stated in this conversation some post up:

GRBL is written to be very efficient with its writting to the step and direction ports and to make it so efficient all the step pins are on one port and all the direction pins are on one port.

The compatibility issue with the RAMPS board is that all the step and direction pins are on almost random ports to best suit the routing of the PCB.

The only solutions i see is to accept this statement and wiring up by hand using a flat cable and some connectors the signal to the stepper motor and for the limit switch from the Mega to the RAMPS, keeping the connections short or using some shielded cable, maybe some audio shielded cable for each dir and step signal, but I'm open to other alternatives, there are some implementations for the Mega 2560 but the code is modified in a manner that maintaining it when the main code change is difficult.

Thanks
Carlo D.

@maaadbob
Copy link

Hi chaps,

Instead of going to the bother of creating some weird wire solution to connect an Arduino
Mega2560 board to a RAMPS1.4 stepper board, why not take a look at the solution currently
in use by me:
https://github.com/maaadbob/Arduino_Mega2560-RAMPS1.4

This board is sandwiched between the Arduino and the RAMPS.
Signal routing information can be found in the project's folders.
The design can be edited with the free version of Eagle, so you can modify it to suit your
needs.
Then simply send the .brd file to your preferred PCB manufacturer and source the Arduino
headers/sockets from AdaFruit.

I also have 4 axis GRBL code here: (modified for my setup)
https://github.com/maaadbob/openpnp-grbl

Again; take and modify to your requirements.

I do not have the time to support any technical queries.

Best regards,
Bob B.

@onekk
Copy link
Author

onekk commented Dec 28, 2014

Hi Bob, Your solution is very nice and will be a very quick solution for my need, the pcb manufacturer solution seem to be a viable solution but not for a single board, it is a great solution if it came pcb only or maybe in kit, maybe someone other than me is interested in it, have you done some marketing for it.

Many thanks and best regards,
Carlo D.

@cri-s
Copy link

cri-s commented Dec 28, 2014

Is there someone that can put arduino uno shield on arduino mega and tray out if it works .
No homing.
Otherwise i need just changing the defines for ramp. I have just begun with that bit
definition, just because there was a so nice table on the other issue thread.
how can i send hex file instead of publishing it on fileshare sites ?

@cri-s
Copy link

cri-s commented Dec 28, 2014

for uno shield:
http://www.datafilehost.com/d/508e96ad

for ramps:
http://www.datafilehost.com/d/40a2811b

The uno version is less modified.
If possible tray this first.

@onekk
Copy link
Author

onekk commented Dec 28, 2014

hi cri-s, i have noted the links, but for now i haven't the board yet, could you send me a link to the sources, you have modified maybe on github so i can see them, waiting for the real board to arrive?

TIA and regards.

Carlo D.

@cri-s
Copy link

cri-s commented Dec 28, 2014

Actually i have only made step, dir and enable pins.
There is further work that need to be done, but moving should be modified firstly.
It uses preprocessing, so if all pins are on the same port, processing is performanter .
Actually step and dir pins are coupled.
Here is the diff if you want look in the source.

189a190,216

static void enable(char c) {
#ifdef STEPPER_DISABLE_PORT
STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
if(c)
//if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE))
bit_true(STEPPERS_DISABLE_PORT,STEPPERS_DISABLE_BIT);
else
bit_false(STEPPERS_DISABLE_PORT,STEPPERS_DISABLE_BIT);
#else
#ifdef X_ENABLE_PIN
pin_out(X_ENABLE_PIN);
if(c) pin_hi(X_ENABLE_PIN); else pin_lo(X_ENABLE_PIN);
#endif
#ifdef Y_ENABLE_PIN
pin_out(Y_ENABLE_PIN);
if(c) pin_hi(Y_ENABLE_PIN); else pin_lo(Y_ENABLE_PIN);
#endif
#ifdef Z_ENABLE_PIN
pin_out(Z_ENABLE_PIN);
if(c) pin_hi(Z_ENABLE_PIN); else pin_lo(Z_ENABLE_PIN);
#endif
#ifdef A_ENABLE_PIN
pin_out(A_ENABLE_PIN);
if(c) pin_hi(A_ENABLE_PIN); else pin_lo(A_ENABLE_PIN);
#endif
#endif
}
196,197c223
< if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }

< else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }

enable(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE));
238,239c264
< if (pin_state) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }

< else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }

enable(pin_state);
296a322
#ifdef STEP_PORT
297a324,331
#else
if(st.dir_outbits&bit(X_AXIS)) pin_hi(X_DIR_PIN); else pin_lo(X_DIR_PIN);
if(st.dir_outbits&bit(Y_AXIS)) pin_hi(Y_DIR_PIN); else pin_lo(Y_DIR_PIN);
if(st.dir_outbits&bit(Z_AXIS)) pin_hi(Z_DIR_PIN); else pin_lo(Z_DIR_PIN);
#ifdef A_STEP_PIN
if(st.dir_outbits&bit(A_AXIS)) pin_hi(A_DIR_PIN); else pin_lo(A_DIR_PIN);
#endif
#endif
301c335

< st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits; // Store out_bits to prevent overwriting.

// moved
302a337
#ifdef STEP_PORT
303a339,346
#else
if(st.step_outbits&bit(X_AXIS)) pin_hi(X_STEP_PIN);
if(st.step_outbits&bit(Y_AXIS)) pin_hi(Y_STEP_PIN);
if(st.step_outbits&bit(Z_AXIS)) pin_hi(Z_STEP_PIN);
#ifdef A_STEP_PIN
if(st.step_outbits&bit(A_AXIS)) pin_hi(A_STEP_PIN);
#endif
#endif
430a474
#ifdef STEP_PORT
431a476,483
#else
pin_lo(X_STEP_PIN);
pin_lo(Y_STEP_PIN);
pin_lo(Z_STEP_PIN);
#ifdef A_STEP_PIN
pin_lo(A_STEP_PIN);
#endif
#endif
442c494,503

< STEP_PORT = st.step_bits; // Begin step pulse.

#ifdef STEP_PORT
STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits; // Store out_bits to prevent overwriting.
#else
if(st.step_outbits&bit(X_AXIS)) pin_hi(X_STEP_PIN);
if(st.step_outbits&bit(Y_AXIS)) pin_hi(Y_STEP_PIN);
if(st.step_outbits&bit(Z_AXIS)) pin_hi(Z_STEP_PIN);
#ifdef A_STEP_PIN
if(st.step_outbits&bit(A_AXIS)) pin_hi(A_STEP_PIN);
#endif
#endif
478a540
#ifdef STEP_PORT
480a543,562
#else
pin_lo(X_STEP_PIN);
pin_lo(Y_STEP_PIN);
pin_lo(Z_STEP_PIN);
pin_out(X_STEP_PIN);
pin_out(Y_STEP_PIN);
pin_out(Z_STEP_PIN);
#ifdef A_STEP_PIN
pin_lo(A_STEP_PIN);
pin_lo(A_DIR_PIN);
pin_out(A_STEP_PIN);
pin_out(A_DIR_PIN);
#endif
pin_lo(X_DIR_PIN);
pin_lo(Y_DIR_PIN);
pin_lo(Z_DIR_PIN);
pin_out(X_DIR_PIN);
pin_out(Y_DIR_PIN);
pin_out(Z_DIR_PIN);
#endif
487a570
#ifdef STEP_PORT
489d571
< STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
490a573,574
#endif
enable(0);
861a946

@onekk
Copy link
Author

onekk commented Dec 28, 2014

Thanks, i will see tomorrow

Carlo D.

@onekk
Copy link
Author

onekk commented Dec 28, 2014

cri-s what file are you modifing, the paste of the code in Markdown is too crappy, could you gave me maybe a gist of the files?

@onekk
Copy link
Author

onekk commented Dec 28, 2014

cri-s I have found this version on github, maybe it will be a base for future develpment?

https://github.com/LETARTARE/Grbl-xx_with_Arduino/tree/master/Grbl9fMega2560

Regards

Carlo D.

@cri-s
Copy link

cri-s commented Dec 28, 2014

this is the diff
http://www.datafilehost.com/d/d601e735

@onekk
Copy link
Author

onekk commented Dec 28, 2014

cri-s
I have seen your code and altouhg i can't figure out many things, as it is isolated form the main code (what version are you patching?) I like it very much.

Best Regards

Carlo D.

@chamnit
Copy link
Member

chamnit commented Dec 28, 2014

@cri-s and @onekk : While interesting, this thread has gotten a bit out of hand. Could you please directly communicate with each other on the details and simply update on progress? Thank you.

@onekk
Copy link
Author

onekk commented Dec 28, 2014

chamnit it's OK for me.

Regards
Carlo D.

@onekk
Copy link
Author

onekk commented Dec 29, 2014

I have just bought and Arduino Uno solution, for now the Mega2560 is a stalled project, maybe i will build a reprap with marlin on it.

Many thanks, to all, but the Mega and the ramps seemed to be a good idea, but from now i want to have a ready made solution, the machine is intended to be a work horse so to be ready without pains is the most viable solution.

Regards
Carlo D.

@onekk onekk closed this as completed Dec 30, 2014
@EliteEng
Copy link
Contributor

EliteEng commented Jan 1, 2015

Please see my repo https://github.com/EliteEng/grbl master branch.

I have added the ability to have the step and direction pins on different port which will allow the use of the RAMPS board.

I have started adding the RAMPS board to the cpu_map.h but it still needs a bit of work to get all the pins in the correct location.

@onekk
Copy link
Author

onekk commented Jan 1, 2015

Many thanks for the reply, when I receive the boards and the machine (eShapeoko didn't answer me yet and didn't know when) I will try your solution. As the moderator told me this tread is becoming too long and tend to be off-topic there is another manner to comunicate?

Regards

Carlo D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants