gnea / grbl-Mega

An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on an Arduino Mega2560
https://github.com/gnea/grbl/wiki
Other
484 stars 223 forks source link

Adding LCD, Keypad, and SD card support #77

Open bdurbrow opened 5 years ago

bdurbrow commented 5 years ago

I'm thinking of setting this up on a common 3D printer platform (Arduino Mega 2560 + RAMPS 1.4 + LCD w/ SD card reader), and I'd like to make it run standalone (like Marlin does).

So, I figure I'm going to need to write/port a SD card reader module, keypad module, and LCD menu system module. Not a big deal, I'm a programmer. :-)

However, I would like some input from the official developers as to where I should hook into grbl... without making a mess of things.

So... where should I inject the G-code I have read off of the SD card? Where should I drop a call to my LCD update routine; and where should I drop a call to my keypad polling routine?

I'm going to want to support a Manual Pulse Generator hand wheel also... where is the proper place to inject jogging data? Or should I take over the Arduino when in MPG jog mode, and then update the machine position global variables afterwords (and if so, which variables should I update?)

Also, is there an officially sanctioned way of directly setting (from a C function, not by injecting a G-code into the input datastream) feedrate override, spindle override, and coolant override parameters?

Any pointers you can provide (er, no pun intended) would be much appreciated. Thanks!

terjeio commented 5 years ago

I am using function pointers to achieve a similar goal. But perhaps not the kind of pointers you are after...? Another kind of pointer may be this ESP32 port as it has SD card support, and perhaps it is possible to use its serial comms over blueetooth for GCode injection?

dangerousderek commented 5 years ago

I’ve been scouring the web looking for exactly this. I’m no coder, but I love grbl and I just want a stand alone system using a ramps board for a laser cutter I built. Any progress you make on this front would be awesome and I would be happy to beta test. Thanks!!!

bdurbrow commented 5 years ago

scouring the web looking for exactly this

So was I. I started trying to modify MK4Duo (a Marlin variant) to remove the 3D Printer specific components, but have determined that they are too deeply embedded into the firmware for that to be practical.

So I'm doing this instead. So far, I've got the device drivers (SD, Matrix Keypad, HD44780 LCD) ported from the Arduino codebase; and partially integrated into the Grbl codebase (there's quite a bit of incompatibility between the base Arduino core and Grbl, in particular in use of system resources like timers; so I've had to re-code quite a bit of the low-level Arduino support libraries to make it compatible... it wasn't a matter of drag-and-drop-and-compile).

Unless/until I'm told otherwise, I'm injecting the data from the SD card and jogging into protocol_main_loop(); and have put a call to my UITask() function into protocol_execute_realtime() and protocol_exec_rt_suspend().

Developkings commented 5 years ago

i believe using a ramps friendly premade solution like the lcd 2004 or ultra would be the best solution. i dont know about coding that much, but would it be easier to adapt marlins integration of this components t grbl instead ? if i`m not wrong it already as a basic cnc menu on it

bdurbrow commented 5 years ago

but would it be easier to adapt marlins integration of this components t grbl instead

No, it's not. I already went down that road.

ramps friendly premade solution like the lcd 2004 or ultra

Hardware wise, that's what I'm doing. I'm using the Reprap Discount Smart Controller with a RAMPS 1.4 board. I'm not making my own hardware for this project - the whole idea was to use off-the-shelf parts.

For performance reasons, I'm using the character LCD, and not the graphic LCD - I'm hoping to get nice, quick DRO updates during jogging.

bdurbrow commented 5 years ago

Status Update: Drivers are working, but could stand some optimization (reviewing the drivers that Arduino ships, they are excessively abstracted in their construction; and use slow IO functions. I intend to fix this before posting any code).

SD support is integrated into protocol.c; but is as of tonight untested. Keypad support is fully functional. Rotary encoder (i.e, the knob on the LCD pcb) support is fully functional. LCD support is functional.

User Interface code is about half done. The UI Page system infrastructure is functional; the menu system is itself functional but needs more menu items; and the SD directory access is working (however, at the moment, nothing happens when you select a file - that code needs to be written yet).

Still to do: SD file opening when you select a file. Jogging. Probing. Part Zero setting. MDI. "Conversational" operations for common simple tasks that don't warrant going to the extent of firing up a CAD/CAM program (drill a hole, bolt hole pattern, cut a slot, machine a face flat, etc).

Jogging, probing, and part zero setting basically just involves sending the appropriate command to the main grbl routine; in the same way that a PC would initiate that operation. The infrastructure is in place for this, it just needs to be "wired up" to the keypad & menu system.

MDI requires implementing a text editor to enter the MDI command line on. Conversational requires a similar text editor, but with a "form" style layout.

dangerousderek commented 5 years ago

I can't believe how much progress your making! It seems like such a no brainer I am amazed that no one has done it already, in fact, I kind of figured it must be extremely difficult to do since it hadn't been done. You're the man. Keep us updated and as soon as your looking for some guinea pigs I call dibs! I am pretty active in a couple of other forums and groups having to do with DIY CNC stuff and those folks are going to freak out if you manage to pull this off!

bdurbrow commented 5 years ago

I have now achieved my primary objective: GRBL, on a mega2560 with a RAMPS 1.4 & RepRap Discount Smart Controller, is streaming g-code from a file stored on a SD card, selected via LCD, and performing updates to the display faster than the liquid-crystal media can physically respond. Oh, and it's doing it while maintaining responsiveness to serial commands, too...

There's still additional work to be done, but as of right now, I'm pretty pleased with the way it's working. 😎

dangerousderek commented 5 years ago

Are you going to fork it from this github? I need it so bad! You’re a super hero. Good job!

bdurbrow commented 5 years ago

Are you going to fork it from this github?

Yes.

MDI is working, and the UI for jogging is halfway there. I need to go dig out a MPG handwheel and cook up a cable for it, but that's probably going to have to wait for tomorrow.

Anyone who wants to test this should probably make sure they have the requisite hardware now, since it often takes weeks to months for shipping...

I suggest:

dangerousderek commented 5 years ago

I’ve got everything but the 4x4 pad and the mpg wheel! I’m stoked!

bdurbrow commented 5 years ago

Well... that's a bummer. I can't find the MPG handwheels I had here... I already had a few spares on order, but they're gonna take a while to get here. I guess I should order a few more spares now, also... (of course, you know that just as soon as the new ones show up, the old ones will magically appear, also...)

So I'm having to use the (much coarser resolution) encoder on the LCD for now...

🤨

dangerousderek commented 5 years ago

Are you building an enclosure to hold all this biz? If so can I get some pics? I have a feeling you’re doing exactly the sort of stuff I need to do with my rig...

dangerousderek commented 5 years ago

So.. I hate to nag, but any updates? Thanks a ton!

bdurbrow commented 5 years ago

Sorry about the delay... I've had to wait on parts arrival - the MPG handwheels I had are still AWOL; and I had to order replacements. However, the new ones have arrived and I've made quite a bit of progress:

MPG Jogging works now, and I've not been able to over-run the CPU with pulses (I'm using an interrupt to capture the input pulses; the polling loop can, at high speeds, get swamped).

The infrastructure is in place for the conversational operations; and drilling is in place. Other operations (facing, hole interpolation, etc) need implementing.

MDI works. Part Zero setting works... but there's a feature I want to add (to take into account tool diameter and touch-plate thickness). Probing should be working, but requires testing.

I'm hoping to have a pre-beta up on github soon... perhaps a week or two.

dangerousderek commented 5 years ago

You don't have to apologize! I am just super excited and I am having a hard time reigning it in. I look forward to testing the pre-beta! It sounds like you're going above and beyond the call of duty!

bdurbrow commented 5 years ago

Getting real close...

manisaranbala commented 5 years ago

https://sites.google.com/view/arrsoft/автономные-контролеры/автономнй-контроллер-для- фрезера?authuser=0 On 19-Nov-2018 9:34 PM, "Britt" notifications@github.com wrote:

Getting real close...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gnea/grbl-Mega/issues/77#issuecomment-439945808, or mute the thread https://github.com/notifications/unsubscribe-auth/AFZSX9qxWxneE0Eyc34GkgAMy3rblvabks5uwtaigaJpZM4XLXm7 .

bdurbrow commented 5 years ago

@manisaranbala

Um... I don't read Russian, and google translate is making hash out of that.

Is that supposed to be some sort grbl based controller?

manisaranbala commented 5 years ago

http://www.cnc-club.ru/forum/viewtopic.php?f=41&t=20190 On 20-Nov-2018 12:22 AM, "Britt" notifications@github.com wrote:

@manisaranbala https://github.com/manisaranbala

Um... I don't read Russian, and google translate is making hash out of that.

Is that supposed to be some sort grbl based controller?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gnea/grbl-Mega/issues/77#issuecomment-440001932, or mute the thread https://github.com/notifications/unsubscribe-auth/AFZSX7L-wsySK_kO7VyMjFS8sZZNfPIoks5uwv4DgaJpZM4XLXm7 .

manisaranbala commented 5 years ago

https://sites.google.com/view/arrsoft On 20-Nov-2018 6:27 AM, "vst veeramani" vstveeramani@gmail.com wrote:

http://www.cnc-club.ru/forum/viewtopic.php?f=41&t=20190 On 20-Nov-2018 12:22 AM, "Britt" notifications@github.com wrote:

@manisaranbala https://github.com/manisaranbala

Um... I don't read Russian, and google translate is making hash out of that.

Is that supposed to be some sort grbl based controller?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gnea/grbl-Mega/issues/77#issuecomment-440001932, or mute the thread https://github.com/notifications/unsubscribe-auth/AFZSX7L-wsySK_kO7VyMjFS8sZZNfPIoks5uwv4DgaJpZM4XLXm7 .

bdurbrow commented 5 years ago

OK, here's something to play with.

WARNING: This is pre-beta software. This has not been tested with motors attached yet (my machine is in pieces at the moment). Although it seems to be working on my bench when connected to my oscilloscope, it could crash your machine! So, be careful... and be ready to pull the plug or hit your emergency stop (whichever is more applicable to your situation).

Also, there are known issues with the conversational programming... so don't try that yet.

I have included some photos of the wiring required for the keypad and MPG handwheel in the "UI Support" folder (and yes, that PCB is kinda' crusty!). A PDF file of the keypad overlay is in there also (it has versions in it to support 4 and 5 axis machines, even though grbl itself only goes to 3 at the moment).

Note that unlike a PC, you don't hold down the 'Shift' key; it's a toggle. Push shift, then push the other key.

Probing and setting part-zero are done from the Jog page.

Be aware that editing the tool table does put a cycle on the EEPROM of the atmega... so you probably want to set up your tools once and leave it alone. So does setting part-zero from the Jog page (I intend to implement a settings menu later on that will allow this to be disabled, so that you're not burning EEPROM cycles every time you run a part).

Documentation still needs to be written.

And yes, eventually this will get a proper github repository. I just wanted to get something up here for you all to play with.

😀

grbl-Mega.zip

dangerousderek commented 5 years ago

I’m super excited to mess with this. With the holidays I’ve been to busy to experiment in the shop, but I’m hoping this week to give it a try. One quick question- I still don’t have an mpg wheel (on a boat from China) will the rotary encoder on the reprap discount full graphic lcd work? I’m super stoked to try all the awesome built in features you’re working on, but for now I would settle for being able to see the status of the machine and do basic moves on the axis’s. Thanks again, you’re the man.

bdurbrow commented 5 years ago

Yes, the MPG is optional equipment. Recommended, but optional. Just disable (by commenting it out with a // )this line in config.h:

define USE_UI_ENCODER_B

This will redirect the jogging inputs from the MPG inputs to the main UI knob.

Minimum hardware requirements for using the UI: Arduino Mega 2560 (obviously... :-) RAMPS 1.4 Reprap Discount Smart Controller 20x4 LCD & rotary encoder panel. 4x4 Matrix Keypad

ghost commented 5 years ago

Here's a solution for laser burners/engravers: https://openbuilds.com/threads/arduino-based-off-line-cnc-controller-for-laser.13315/

bdurbrow commented 5 years ago

@dangerousderek -

on the reprap discount full graphic lcd work

Uh oh, I hope that's a typo... this does NOT, and will not, support GRAPHIC LCDs. 20x4 HD44780-compatible Character LCDs ONLY.

If you need to order one, and don't want to wait for the slow boat from China; Amazon has them with Prime Shipping for about $12USD... on eBay they can be had from China for under $8USD at the moment.

For example: https://www.amazon.com/BIQU-Display-Controller-2004LCD-Adapter/dp/B01FLU9X5Q/

@RunnyBore604 - It looks like that's not open source?

dangerousderek commented 5 years ago

@bdurbrow I think I’ve got one of those laying around. I was initially planning to use one of these: https://www.amazon.com/KINGPRINT-Graphic-Display-Controller-Adapter/dp/B076WQQX5K/ref=mp_s_a_1_1?ie=UTF8&qid=1543270471&sr=8-1&pi=AC_SX236_SY340_QL65&keywords=reprap+full+graphics+display

But I failed to read the 20x4 detail in your BOM! Thanks!

easytarget commented 5 years ago

Sorry OT ; but not sure how best to address this..

@RunnyBore604 - It looks like that's not open source?

He's cross posting/promoting from his own OpenBuilds project here, (check user details). Over there he says he wont share the source code.. Kinda against the ethos, and if he's also lurking here then I imagine GRBL is involved, GPL etc.. Anyone got a Openbuilds account and want to flag him?

Bazza1959 commented 5 years ago

Love your work bdurbrow, as soon as I came across this page I immediately dug out the ramps and mega stuff i purchased over a year ago and got all excited and started uploading your work, but uh oh, when I reread everything I found that I have one of those graphics lcds, so now have to wait for slowboat, as I am in ozzieland, but not to worry too much as I can still be printing all the components for the cnc in the meantime, thank you very much for all your hard work, I really do appreciate it, Barry

BillEng commented 5 years ago

Thank you bdurbrow, just what I have been wanting. I have tried this on hardware that has previously had Marlin on it (MPCNC version), I have no stepper drivers, no keypad and no second encoder. Connecting with bCNC I can run a gcode program, love the real time DRO, the LCD updates with feed and spindle overrides and preset Gcodes adjusted in bCNC but the push button does nothing, I can turn to different menu pages also SD card not recognized, tried two one from my 3D printer (8gig) and one I use on the MPCNC (16gig). I have tried commenting out the second encoder as mentioned above, no change. Am I missing something just running without anything else attached to Ramps. Thanks again, I can wait.

BillEng commented 5 years ago

Well I feel a right plonka with my comments above I had read the post a 100 times but obviously not absorbed them, I think I'll go dig a hole and bury myself. I have added a keypad and it is working to the point of development. The encoder on the LCD is too sensitive, can this be tweaked. I could buy a second encoder that has twice the PPM of the one mentioned above at 400 PPM could this be accommodated.

Bazza1959 commented 5 years ago

your not the only one, I am a plonker also, after purchasing the required components I have just realised you guys are setting up a lathe or a milling machine where as I am doing a cnc router is there anyway I can still setup the keypad and lcd screen for my setup and if so what do I need to do before I go dig that hole

BillEng commented 5 years ago

It's grand to know I'm not alone in the world Bazza1959. I'm using a CNC router, as yet I can see that it would suit my needs, just ignore the features that are not needed or maybe (a big maybe in my case) mod the menu. As mentioned above at the moment I am using Marlin, no disrespect to the devs but I hate all the 3D printer stuff in the menu. I have a remote pendant that helps but can only jog in increments, my wish list would be. Manually using the machine, handwheel. Feed rate override while running a gcode. Run gcode from SD card, semi headless. To enter gcodes and/or some preset gcodes from a keypad. The developmet so far seams to fit the bill.

bdurbrow commented 5 years ago

Sorry about the delay, I just haven't had much time to work on it lately. I should have something new up soon though...

@BillEng - The encoder on the LCD can be adjusted somewhat by changing it's configuration (UI_ENCODER_A_MODE in cpu_map.h); but it was designed for the encoder on a RepRap Discount Smart Controller; if you are using something else with more pulses per detent then I'll have to add a sub-divider (not a big deal; I just need to know to do it).

@Bazza1959 - I'm intending this to be usable on both mills and routers. If you can live without threading, a lathe could be setup also... but at the moment grbl has no support for syncing the axis movement to the spindle.

BillEng commented 5 years ago

bdurbrow, please don't retire you will have less time (-:, don't do any mods for an encoder at this time, I asked because I could buy one from my home country (UK) without the hassle of direct from China. When I was trying the firmeware I did have an odd problem, the second row of buttons is a duplicate of the first row, checked through the files as best I could. Flashed a test prog onto the Mega to test the keypad and my extension lead, all OK, I even tested the continuity of the Ramps tracks from AUX2 to where they connect to the Mega again all OK. Thanks again.

cadenote commented 5 years ago

Great work @bdurbrow ! Thank you very much. It is what I was searching for. When I have played with it, I have noticed that files coming from gcodetools ( inkscape ) stop when encounter a line with only a comment or a void line in the nc file. To overcome this issue I have introduced minor changes in protocol.c and SdFile_grbl.cpp files. I hope this will be useful and not to spoil anything. grbl_Mega_proposal.zip x:)

Bazza1959 commented 5 years ago

@cadenote is there anything needed to be done with the files if used on a cnc router or can I just simply replace the old files with the new ones T.I.A. Barry

cadenote commented 5 years ago

Just replace them in libraries/grbl directory and upload again grblUpload.ino into your arduino. :smiley:

Bazza1959 commented 5 years ago

BillEng if using an arduino mega and a ramps 1.4 board do not connect power to the ramps board without having stepper motors connected, Th reason is that it will burn out the stepper drivers and maybe even the ramps board, ask me how I know this lol very frustrating, it took me a month to work out why my steppers wouldn't move and another month to get new drivers from china and now that they have arrived I can see if the boards are stuffed also, but I did order new ramps board and an uno cnc board as well and they should be here in a few days

sinfocomp commented 5 years ago

Hello, I'm trying but can't load any file, what is the correct file extension to use? Also if I disable encoder I get compile error

cadenote commented 5 years ago

Hello, I'm trying but can't load any file, what is the correct file extension to use?

I also had the same problem. I had to dig into the software to find that extension has to be .nc or .NC

sinfocomp commented 5 years ago

can you please let me know how to load a file, i used .nc and .NC but still my display shows NO FILE

Bazza1959 commented 5 years ago

sinfocomp what file are you trying to load we are not sure of what you mean exactly. Are you trying to load cadenotes file or the original GRBL file from bdurdro or what?

sinfocomp commented 5 years ago

I have loaded firmware however I have two problems I cannot compile without the mpg And I get NO FILE on lcd even if my SD card contains a testjob.nc file Thanks

Bazza1959 commented 5 years ago

you should be able to find and comment out the mpg wheel so that fixes your first problem but you will have to wait until bdurbro can answer the second one. I am not at the stage of needing this firmware as I am still waiting on a new ramps board and drivers as I stuffed my old ones

sinfocomp commented 5 years ago

I commented the mpg line as noted somewhere on this thread however I get compile errors unless I Un comment the mpg line

cadenote commented 5 years ago

@sinfocomp in order to see your file in the display you have to presss menu key and after that you have to select SD Card option. Regards.

sinfocomp commented 5 years ago

Cadenote thanks, and in order to not use an mpg? Just one line needs to be commented on source?

cadenote commented 5 years ago

Well, up to I guess, to compile without errors you need to comment out two lines in config.h :

define USE_UI_ENCODER_B

define USE_UI_ENCODER_B_ISR

However in that case jog mode has to be tested deeply.

sinfocomp commented 5 years ago

Hello, i need some help making this work on a MKS Base V1.5 board, my problem so far is the keypad pins,can someone please helpme on remaping pins to A11,A12,D11,D12, and A13,A14,A15,D0, Thanks in advance