Maker Pro
Maker Pro

Arduino Mega2560 & GRBL .....

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
I am an absolute NooB with respect to the Arduino IDE and C programming, but I have been building projects using the AVR family of uControllers since the 90's.....of course, everything I have done has been in Assembler.....What I actually "need" I could have done in an afternoon writing ASM, but what I really **want** is to try and use GRBL and the Arduino IDE...so I am a week into trying to load a completely un-modified "sketch" to a mega2560 board....

What I am working with:

Brand New SainSmart Mega2560 R3 with the ATMEGA16U USB chip (as opposed to the more readily available CH340G USB Chips...there were a few posts about compatibility issues of GRBL with the CH340G USB chips, so I ordered some of the SainSmart boards in an effort to minimize potential problems...)

Arduino IDE Version 1.6.9 (fresh install)

Latest "verified" Version of GRBL9f2560 from GitHub

I have the GRBL library installed in the folder with the rest of the Arduino libraries, and it shows up in the Arduino IDE "Library List" (I don't have any other GRBL libraries installed anywhere else).

I started a "New Sketch" in the Arduino IDE, Selected the Atmega2560 and included the GRBL library (as per the GRBL wiki instructions...) I then compiled the sketch (it compiles w/o warnings) , but I have not been able to upload it to the Mega2560 board via the Arduino IDE....either via the boot loader or with a programmer.....However, I have been able to use the "Export Compiled Binary" feature in the Arduino IDE to create a hex file that flashes without a problem using extreme burner and an AVRASP....so there is that....

In theory the GRBL firmware is flashed to the ATMEGA2560 soldered on the Arduino Mega2560 board sitting in front of me and I should be able to use a terminal interface to begin setting up my parameters....I can use extreme burner to verify the hex file flashed to the 2560 matches the hex file created by the Arduino IDE....but I am getting no response from the 2560.....On ReSet, It is suppose to send:

Code:
Grbl vX.Xx ['$' for help]

but I get nothing.....Likewise when I send "$$<cr>" it is suppose to respond with a list of the various commands....but it doesn't....I have verified this with several terminal interfaces and a DSO.....the cmd makes it all the way to Rx0.....but nothing comes out of Tx0....So I have obviously failed to do something....

As proof-of-concept I have used the same compiling/exporting/flashing with extreme burner process with the "Example Program" Blink.....it works as expected. The only thing I can think of is that there is no "actual code" in the "Sketch" ....aside from comments there is only the following:

Code:
#include <main.h>

void setup(){
   main();
}

void loop(){}

In the "Blink" example there are a few actual instructions invoking the included library functions.....Am I missing something as simple as "calling" some function in the GRBL library?

Any thoughts or advice would be appreciated.

Fish
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
I guess you checked your port settings matched the virtual port setting in windows devices. Do you need any drivers for the USB device? some people have had issues with drivers. http://forum.arduino.cc/index.php?topic=134069.0
It might be worth just flashing an LED first to make sure everything works.
Thanks
Adam
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
Hey Adam!

Thanks for the reply....As stated, I can flash the "blink sketch" (compiled and exported as a binary, flashed from extreme burner) and it works fine.....I can communicate with the board just fine when flashed with other firmware....I have extensive experience with AVR chips and Arduino Boards flashed with ASM written/assembled in AVR studio....I just have near-zero experience with "C" or the Arduino IDE....Having said all of that, I am VERY certain I am doing SOMETHING wrong, LoL....I guess some of my problems with "Uploading" from the Arduino IDE could be driver related, but once flashed, the Arduino IDE is "no longer in the loop".....and at the very least I should "see" the ATR on Tx0 when the GRBL sketch is loaded and the board is powered on....Shouldn't I ????

Again, Thanks for the Response!

Fish
 

Amar Dhore

Dec 2, 2015
129
Joined
Dec 2, 2015
Messages
129
I am also new the Arduino. In my experience, if you are using serial, while programming you should disconnect RX and TX pins.
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
Hey Amar Dhore!

Thanks for the reply! Good advice, wish it were my problem; sadly it is not.

Thanks!

Fish
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Fish can you post all of your Arduino code so we can see it. Also FYI the boot loader takes a few seconds from boot-up to work as it checks for comms on it's USB port. So looks like you have two issues, possibly a coding issue and a programming issue. I have used many Arduino Nano boards but not any of the larger ones. But I still have quite a bit of experience with Arduino, I might be able to help.
Thanks
Adam
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
Hey Adam, Thanks for the Response!

There is no "My Code" other than the default Arduino IDE comments and this:

Code:
#include <main.h>

void setup(){
   main();
}

void loop(){}


.....I can post the various headers and C files in the libraries (would be A LOT of text), or you can simply download them from here:

https://github.com/grbl/grbl

From the download, I have selected and installed the: Grbl9fMega2560 Library.....

If you have the time, and wouldn't mind.....if you could download the source from github and simply attempt to load it onto a Mega2560 (if you have one) and let me know if you get ANY terminal communication from it I would sure appreciate it....

if you don't have a Mega2560 board, the GRBL is designed for ATMega328 based Arduinos and has been specifically modified for use on the 2560....I don't have any of the legacy "Uno"s on hand, I do have some "Leonardo"s (ATMega32AU based), and a couple of "DCcEle DCcduino" (Essentially the Uno with on-board USB...based on the ATMega328PAU)....If that is compatible with a board you have on hand then I would be happy to try the process on it....I **Might** have some DIP ATMega328's on hand will have to check...I know I have some DIP ATMega32's on hand.....so in a pinch, perhaps I could breadboard a DIP AVR for testing....but at the end of the day I sure would like the code to run on the Mega2560.....

For the record, I have flashed and tested my Mega2560 board with both the "Bootloader" hex file created by the Arduino IDE and the "No-Bootloader" hex file created by the Arduino IDE....(obviously two different boards) no joy with either....

Again, Thanks for the Response!

Fish
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Umm ok. I don't have any boards with me at the moment so I can just do a bit of digging to see if I can help. So if we forget about not being able to programme it from the IDE you can actually load the blink LED programme by other means and that works, I mean flashes an LED?
Adam
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi fish
I can't see the library Grbl9fMega2560 which files did you download?
Thanks
Adam
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
Hey Adam!

Oooops.....While I **did** download the one I linked above....the one I am using came from here:

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

And perhaps that is the part of the problem? Not sure.....At this point I am open to any and all suggestions...If you have time, and don't mind looking at the above linked code to see if you notice anything "glaring" it would be great....if you don't, I certainly understand, and I will re-group and see if I can get the grbl library from the first link to work on a different target (one with an ATMega328 on it)......I just feel like I am "missing" some obvious step somewhere in the process.....like a line of code that says, "To make the program work, un-comment the next line....." LoL.

Again, Thanks for the Response!

Fish
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
115.2k is the setting for grbl .9x, but "watching" the Tx0 line from reset through several minutes on a DSO shows no outgoing pulses @ all from the ATMEGA Board.....The Rx0 line behaves as expected when a cmd is "sent"....but there has yet to be any sign of a response on the Tx0 line.....

Thanks!

Fish
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
There is a load of code blimey! Do you know where the port allocations are? Can't find them.
Adam
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
There seems a load of people that have issues with the TX RX part of the 2560. Some of them speak about disabling interrupts to get it to work. I'll have another look tomorrow, I am off to bed now..night night :) Good luck.
Adam
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
Adam......I just ordered:

3 x Arduino Uno R3 with the ATMega328P-PU (DIP with Socket) and ATMega16AU USB
5 x Arduino Uno R3 with the ATMEGA328P (SMD) and CH340G USB
5 x ATMega328P-PU bare chips

All are from US suppliers, so should all be here next week.....If you don't see anything "glaring" then I will just put this project on hold till the UNOs come in and I can use the EXACT set up that is "supported and documented" by the people writing the grbl code.....OBVIOUSLY I should NOT have started with an ATMega2560 regardless how many RepRaps are running grbl variants..... At this point I have invested way too much time in the Arduino//grbl to give up......it is readily apparent I have "missed" something ***probably obvious*** (just not to me) so I am going drop back and attempt to make my side look EXACTLY like "their side"....I will still likely be "missing something" (....and have no idea what it could be....LoL), but hopefully it will be easier to catch if I am using the exact set-up they use in their examples.....

The really screwed up thing is that I am currently only wanting to "use" grbl to test acceleration/deceleration on a single axis which is itself preliminary work to determine realistic feed rates//acceleration rates for a CNC project that will almost certainly ultimately use an industrial motion controller, LoL....I thought using grbl would be "Faster" than writing a VB program to calculate the step timing for trial acceleration rates........ "Easier" than removing an existing industrial motion controller from a working machine to do the testing and "Cheaper" than ordering a new industrial motion controller.....So I guess I was wrong on all three counts, LoL.....(well, a new industrial motion controller is $250.....so I guess a handful of Arduino Uno's is technically "cheaper" ---if they work--- but I will still almost certainly buy an industrial motion controller for the project's final assembly, so in the long run the cost of the Uno's goes in the "consumables" column of the project's ledger, LoL.)

Thanks for the Help!
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
^^^^^WoW^^^^^

It turns out I DID have an UnO variant on hand....one of the DCcEle UnO clone variants.....Still can't access it via the Arduino IDE.....BUT I was able to "compile & export" the GRBL source code from the first github link (several posts ago)....And then was able to Flash it using Extreme Burner (had to select ATMEGA32 as the target then click a couple of "Ignore" nags....) AND......Lo and Behold.......

Code:
ATR->Grbl 0.9j ['$' for help]

Tx => $
Rx ==> $$ (view Grbl settings)
$# (view # parameters)
$G (view parser state)
$I (view build info)
$N (view startup blocks)
$x=value (save Grbl setting)
$Nx=line (save startup block)
$C (check gcode mode)
$X (kill alarm lock)
$H (run homing cycle)
~ (cycle start)
! (feed hold)
? (current status)
ctrl-x (reset Grbl)
ok

The previously missing ATR <Grbl 0.9j ['$' for help]> popped up immediately upon power-up! Yea! As a quick sanity check I immediately typed <$> and amazingly got the expected result! (The main menu ;-) )

!me

What a FuBaR this experience has been.....

I have heard all kinds of noise about the ATMega2560s "having issues", but I have been using them w/o incident for quite a while....plenty of projects with all kinds of interrupts, multiple comm ports etc, etc....never even a hint of a problem (****NOTE: All my previous projects have been AVR-Studio//Atmel Studio ASM projects....So this was my first Arduino IDE project AND my first C project (hrmmm and also my first UnO project come to think of it)....****).... So....close to a week into "saving time/money/effort" I can now do some very simple, single axis stepper testing.....LoL!

**Adam** THANK YOU VERY MUCH for your efforts....Just knowing that there was nothing **GLARING Wrong** with what I was doing was enough to convince me that the problem HAD to be the Mega2560 Targets....and once I knew that I could stop banging my head against the walls and proactively correct the problem by changing targets......

Again, Thanks!

Fish
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Woooooohooo, great news. It would be nice however to know what was wrong with the other board...rainy day project I guess?
Cheers
Adam
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Maybe a random thought, but could you have overwritten the boot loader when you programmed it directly?

I generally prefer direct programming over usb/serial programming as it reduces the amount of extras fluff I need on the board.
 

Fish4Fun

So long, and Thanks for all the Fish!
Aug 27, 2013
481
Joined
Aug 27, 2013
Messages
481
@adam....
My guess would be the board is fine as I tried numerous Mega2560 boards purchased @ different times from different vendors.....I also strongly suspect the C source code when compiled works just fine....LoL What I *****Think***** is that there is a slight discrepancy between my compiler OR compiler settings and the developer's compiler or compiler settings.... Mind you, that is just a guess from an absolute C NooB..... I would need a copy of the binary compiled by the author's of the code to verify my speculation, and I really can't see that being a worth-while pursuit.... IMHO Compilers in general are in the realm of the Black-Arts.....I suspect in a language as information dense as C, even a tiny change in the compiler/compiler settings can make HUGE changes in the resulting binary....in most cases I doubt these differences in the binaries are even noticeable.....but sometimes they are ;-) But that is just a NooB guessing...

@*steve*.....
Thanks for the input! I am 100% certain I overwrote the bootloader.....The Arduino IDE (in the "Export Compiled Binary Mode") creates 2 binaries : One Includes the Bootloader, the other does not....I used the one that does not include the bootloader because I have never been able to use the Arduino IDE to "UpLoad a Sketch"....(Not exactly sure why, but it isn't really a problem) anyway, I feel more comfortable directly programming the chips and so don't really have any need for the bootloader or it's overhead....I have never had ANY trouble flashing an AVR ****Except**** when I try to use the Arduino IDE, LoL. GRBL certainly doesn't "need" the bootloader....

Again, Thanks for the Replies!

Fish
 
Top