Looping gcode

I had no idea this was possible. I need to add this to the instruction page. Thanks for perseverance.

Hi all,

This is definitely the place to be asking about our sand plotter. I work for a community college and my students and I have spent the semester trying to put one together. Our objective is to have it display and demonstrate outside our classroom. We have the mechanicals completed and we are using a GRBL with G-shield. The G-code is created using the fantastic Sandify program and then we test it using Universal G-Code Sender. We are now at the stage where we need to somehow loop the G-code patterns, etc ,etc. I suppose I’m looking for a little guidance and advice. We have two ways of doing this…some of my students think the best way is to use a Raspberry Pi with SD, somehow read it using octoprint and setup some sort of print queue. Has anyone had any success with this or should we concentrate on having two arduinos - one being the GRBL controller and the other reading the SD card and sending it to the GRBL.

Thanks for any help…

Tim Callinan

https://www.youtube.com/channel/UCX7-9Akp9iRHKSbO_s7bbOQ?view_as=subscriber

Hi Tim, that looks like fun! Reading through the posts here, it looks like Bill had some success just listing the files in a master file. He had 11 lines for 2.5 hours, so a week would be 740 lines of gcode :slight_smile: . Not too bad for a copy-paste. He was using Marlin though…

Octoprint doesn’t work well with grbl, but cnc.js does. You can try my v1pi image, if you like. It won’t really be doing much though, unfortunately. I did want to have sandify eventually just connect straight to the machine, so you could use that and just hit “send”, but I’m very far from finishing that.

If you or one of your students is interested in some software developement, Karl and I were working on another arduino to read from an sd card and loop through, with shuffle. It was working well, but it’s far from “hardened”. Otherwise, scripting up some commands to pronterface from the pi could also work.

1 Like

Yes, my sand table runs continuously, reading files from an SD card with an arduino nano and sending them to the table, which is run by an arduino uno with cnc shield. As Jeff mentioned, the code is not elegant or hardened, but it does work, and might be a good starting point if you guys want to use an arduino for this purpose. A Pi is overkill, in my opinion.

if you’re interested, I’ll dig up the code tomorrow and post it, probably on github.

1 Like

Hi Jeff and Karl,

Thank you so much for the advice. I think having two arduinos seems to be way the go. We would definitely appreciate any code you could share. Our only (small) issue is we were thinking of displaying the g-code in some sort of visualizer on a nearby monitor so passers by could learn a little on CNCs but I’m sure we could figure that out. We will report back on how it works also. I’m planning on putting up a video showcasing the build ASAP.

Tim

Karl, the code you had a while ago was in github. Here’s my PR that I was using at my desk:

I think it wasn’t an uno, but a pro micro (the one with the 32u from the leonardo). That was useful for having two uarts.

Tim, for the visualization,

  1. You could have Karl’s code output a signal on the usb uart to a computer that would have the same source gcode. The signal might be sending “line 425”.

  2. Alternatively, you could have another uart to usb connected on the RX line of the grbl board and read what’s going into the grbl buffer. Then you’d have to parse the gcode and visualize it (python gcode tools, FTW). That would let you draw where it is at the top of the buffer, but the machine will lag behind that a bit.

  3. Grbl can also publish it’s current position (I know cnc.js uses this). Then you would read the TX line on grbl instead. That wouldn’t give you the gcode, just the current position. I bet it would look pretty real if you just draw the gcode (from a gcode file on the pc) in the background as gray and the history of the current position (from grbl) in front, in white or red or something. Of course, if you could use this info to actually draw sand, you’re awesome, and I want your help on sandify.

This is pretty interesting to me and although I don’t have a ton of available developer time for this, I can definitely help here and if you have any code you want reviewed, let me know. I will someday get my sand table working again…

Thanks, Jeff. You have a better memory than I. You’re right, the gcode feeder is using a pro micro because it has an extra uart.

Tim, you can get the code I’m using from github. I’m just a hack, not a coder, so Jeff’s your best bet for advice on that part of it, but if you have any questions about the hardware I used, let me know.

I should mention that to use my code as is, the gcode files need to be named 1.g, 2.g, 3.g, etc., and I also have a file called home.gc that homes the machine and then moves the ball to X0 Y0, which is where I usually have all my designs start and end. When the machine starts up, it runs home.gc, then counts the number of design files, and creates randomized array of that many numbers. It then looks for one of the pins to be low, and when it is, it sends the file whose name matches the next number in the array. I have that pin hooked up to both a toggle switch and a momentary button. If the toggle switch is off, you can press the button and the table will draw the next design and then stop, waiting for the next press of the button. If the toggle switch is on, the table will draw designs continuously. Note that pressing the button or flipping the switch does nothing while the table is drawing.

Hope that helps. Let us know how your project goes!

Karl

It might be easiest to just put a display on an Arduino and ask it to spit a line to the display for each gcode line executed. The example I give above works great with Marlin, and should work with most gcode interpreters. I run off an SD card placed in the display’s slot, so the display could potentially fill two tasks. You wouldn’t even need the second Arduino then.

I’m using Sandify files and alternating between files that start at 0,0 and files that start in the center of the table. I find I have to tweak the outward moving files to end at 0,0 instead of some other point on the outside edge.

Resurrecting an old thread! First time posting - this forum has been a life saver and great source for ideas.

I am trying to replicate @karltinsly work, augmented by @jeffeb3 . I think it is a very elegant solution to what I am trying to do with my own system, but am stuck in the home stretch.

I have everything set up and working using an UNO/CNC Shield set up. I independently have the Pro-Micro set up and running with the RX/TX pins bridged. The problem I run into is that I can’t seem to simultaneously communicate with the UNO through USB serial monitor AND the hardware RX/TX pins connected to the micro. Is dual serial communication not possible on the UNO? DO I need to change anything in the GRBL serial code?

Right now, If I get the Machine set up and error free/homed using the USB serial to the UNO, and then connect the hardware serial connection from the pro-micro, the system works great and loops through G-Code just fine. I understand that I shouldn’t need the UNO USB serial connection, but still want to be able to connect to adjust GRBL settings/debug/etc.

Any thoughts on an old thread? Thanks!

Jeremy

The uno only has one hardware serial. You’d need a mega or something to get another. You could almost certainly get away with a software serial for some simple stuff, like setup, but that would require editing the grbl code and you couldn’t use the usb for that (because it is attached to the hardware serial).

One option is to buy your way out. You could replace the uno with a grbl_esp32 board and it would have a web interface for setup and you could use the pro micro to send gcode after setup.

Another option is to use the pro micro as a multiplexer. You could send commands to the pro micro, and it would just send those on to the uno. Anything the pro micro heard from the UNO could be repeated to the USB.

Thanks for the quick reply. Your last point was the one I actually came to in my own brain after posting. Trying to go through the code to figure out how to forward serial monitor input on the pro micro to the UNO. A bit of a code noob, but I’ll fumble my way through :slight_smile: A fun challenge. This stuff is a ton of fun! Thanks for the help.

1 Like