GCode interpreter for UNO and Adafruits Motor Shield v2

Hi folks,

the last weeks i had programmed a plotter control for the Arduino UNO and Adafruits Motor Shield v2.

Now i have reached a point where some review of other coder would be very helpful and commendable.

I'm pretty sure that there errors in the code code, I do not see as programming amateur. (simply because I do not know better) It is my first project in this scale (~1000 lines/ ~16kb) and i need some guidance from competent programmer.

You can find the project at Github.

Many thanks and have a nice day!

You are doing some very odd things

Why do you have lots of ino files, but only one function in them

Also, having a function called where() seems a very bad idea to me, I'm surprised it compiles as where is a reserved word as part of the C language

Does it even compile?

I have a lot of .ino-files because for me it is clear to jump between functions.
Click on a tab is a lot of easier as scroll with mousebutton/press [Page-up]/[Page-down] several times.

I cant see “where” as a reserved keyword in C (http://en.wikipedia.org/wiki/C_(programming_language)#Keywords).
Where did you get your info about “where” as a reserved word?
Maybe you confound it with SQL?

It compiles without error or warning and runs trouble-free on my UNO.

Happy hacking

Edit:

After some searching i think you mean C# relating to “where”.
But thats not C in terms of Arduino/Processing.

This is a subject that interests me.

I have downloaded your ZIP file and will have a look at it later.

...R

This is a subject that interests me.

Than maybe you are also interested in my controlling software (in VB.net) for this firmware hwCNC

Feel free to fork both of it and make changes and/or improvements.

hirnwunde: Than maybe you are also interested in my controlling software (in VB.net) for this firmware hwCNC

Thanks, but, sorry, I don't use Windows - just Linux.

...R

Edit to add ...

I have now had a quick look at your Arduino code. It seems to me your PC sends a GCode line to the Arduino which then parses it and excutes the move.

My idea is to interpret the GCode on my PC and just send the minimum data needed to define the move to the Arduino.

At the moment I'm thinking of sending 4 numbers (for 3 motors) the total number of microseconds for the move and, for each motor, the number of microseconds between steps. The idea is to minimize the amount of computation needed on the Arduino and do the heavy lifting on the PC where it is much easier.

The PC can convert the GCode into numbers and save them in a file. Then a simple PC program can send the next set of numbers as requested by the Arduino. My plan is that the total data from the PC will fit in the Arduino serial buffer so the data can be received in the background while the Arduino is implementing a move. The data for the next move will then be immediately available when the current move is finished.

The stepper motors will (hopefully) drive 3 axes on a small metal working lathe.

...R

Surely this has all been done already

It definitely has for 3d printers, e.g. marlin and sprinter. Arduino firmware.???

rogerClark: Surely this has all been done already

Of course it has. But reinventing the wheel can be fun.

Imagine if Bill Gates had decided not to bother with Windows just because Apple had already done it?

Or Boeing, or Airbus deciding to stay out of the civil airplane business?

...R

You must have more free time than I do ;-)

Imagine if Bill Gates had decided not to bother with Windows just because Apple had already done it?

Then the world would have been a much better place.

Robin2: Thanks, but, sorry, I don't use Windows - just Linux.

Maybe it will run an wine. ;)

Robin2: I have now had a quick look at your Arduino code. It seems to me your PC sends a GCode line to the Arduino which then parses it and excutes the move.

Correct. Thats the way i want it. Because i can drive the "CNC-Machine" without the need of any Software. Exempt from a serial console.

Robin2: My idea is to interpret the GCode on my PC and just send the minimum data needed to define the move to the Arduino.

This is a completly different solution. My intend was to build a little firmware which is controllable without OS-Limitation. Almost every system has a serial console. Even BeOS, indeed DOS.

When i will compute the paths to move on PC, MAC or Cray I'm tied to this devices. With my solution i can use every system that has support for COM-Ports and a serial console.

My written software hwCNC sends only GCode throug the serial line. This is also resolvable in Python or bash (with ncurses). I had used VB.net because it is the language that i have the most knowledge of. With a little bit of time and learning i could write a nearly similar software in Python or Perl.

Happy hacking

Grumpy_Mike: Then the world would have been a much better place.

That's a matter of opinion. But it is a common saying of the bulk of Apple-Users.

hirnwunde: Maybe it will run an wine.

That's even worse.

Correct. Thats the way i want it. Because i can drive the "CNC-Machine" without the need of any Software. Exempt from a serial console.

... snip ...

When i will compute the paths to move on PC, MAC or Cray I'm tied to this devices. With my solution i can use every system that has support for COM-Ports and a serial console.

My written software hwCNC sends only GCode throug the serial line.

I'm not trying to change your mind. I was just exploring to see if you were interested in my approach.

By the way, I don't see any significant difference (vis-a-vis the need for a PC and software on the PC) between my approach and your use of hwCNC. Something has to send some sort of data to the Arduino in both cases.

I don't understand why you would feel tied to the device that computes the paths. If they are stored in a text file they could be transferred to any other computer or even to an SD card to be mounted on the Arduino.

Please don't feel any obligation to reply if you are not interested.

...R

Grumpy_Mike:

Imagine if Bill Gates had decided not to bother with Windows just because Apple had already done it?

Then the world would have been a much better place.

I was wondering who would rise to the bait :) :)

I do, of course, agree. It would have preserved the use of computers to experts and kept out the riff-raff who could not afford Apples.

...R

Robin2: That's even worse.

I had already think about to bundle the Arduino together with an RaspPi. Then i have to code something for Linux. But for this i have a little bit to learn about GUI-Programming on Linux. I was thinking of Python in combination with QT.

Robin2: I'm not trying to change your mind. I was just exploring to see if you were interested in my approach.

I did't see it as an "attack on me"! Don't be afraid. I love discussions to figure out new ways. No matter of the subject.

Robin2: By the way, I don't see any significant difference (vis-a-vis the need for a PC and software on the PC) between my approach and your use of hwCNC. Something has to send some sort of data to the Arduino in both cases.

I don't understand why you would feel tied to the device that computes the paths. If they are stored in a text file they could be transferred to any other computer or even to an SD card to be mounted on the Arduino.

The requirements on the my system to work with the arduino are very low. It must only provide a program for serial communication. hwCNC was only build for easy and comfortable operation. I also can use the build-in Serial Monitor of the Arduino-IDE.

However, you have a different approach. Your way aims to do the work on PC which is made by the Arduino. In my opinion this is not really necessary in this case because the computing power of the Arduino always sufficient to convert the GCode in movements of the motors. grbl is far more complex and do his work fine on the UNO.

hirnwunde: But for this i have a little bit to learn about GUI-Programming on Linux. I was thinking of Python in combination with QT.

I don't like the Java language (for much the same reason I don't use C/C++ if I can avoid it) but I am a great believer in the JVM. A GUI program written to run on the JVM (and the Arduino IDE is an obvious example) works unchanged on Windows, Linux and Mac. I use JRuby for my PC programming which is Ruby running on the JVM. It is very easy to build an entire application (including the JRuby interpreter) into a single directory (with subdirectories) which just needs to be copied to another computer that has the JVM installed and it "just works". The only external dependency is the JVM.

Obviously there are system differences in relation to the naming of com ports and directories, but all the code is transferrable.

Your way aims to do the work on PC which is made by the Arduino. In my opinion this is not really necessary

In the sense that the Arduino is capable of doing it, I agree with you. My concern is to minimize the amount of Arduino programming by doing work on the PC which is generally much easier to program as it has huge memory and disk space and can do floating point maths without apparent effort.

...R

My project here has Arduino Gcode software. I adapted it from a Rep Rap original. http://www.thebox.myzen.co.uk/Hardware/CNC_Conversion.html

Robin2: I don't like the Java language

FULL ACK! Had tryed two times to "learn" Java. I don't get it! First time i failed with Java I've learned Perl, second time i switched to VB.Net.(had programmed many in Excel-VBA so i had not much to learn)

Robin2: I use JRuby for my PC programming which is Ruby running on the JVM.

I had read some Wiki-Pages on JRuby.org. This is an complete new syntax for me. I would have to learn so many basics of Ruby. ATM this is not an option for me. The Multi-Platform-Aspect has a lot of potential. But I think PyQT is also portable.

Robin2: My concern is to minimize the amount of Arduino programming by doing work on the PC which is generally much easier to program as it has huge memory and disk space and can do floating point maths without apparent effort.

I let speak the Arduino-IDE:

Binary sketch size: 16,244 bytes (of a 32,256 byte maximum)

;)

hirnwunde: I had read some Wiki-Pages on JRuby.org. This is an complete new syntax for me. I would have to learn so many basics of Ruby. ATM this is not an option for me. The Multi-Platform-Aspect has a lot of potential. But I think PyQT is also portable.

In this Thread I have published equivalent Python and JRuby code - you will see that conversion between them is fairly straightforward. I learned Ruby/JRuby long before I tried Python because of Ruby's connection with Rails. Ruby is entirely an object oriented language.

Because Python exists on most PCs I did a tiny bit of research recently anout the portability of Python GUI code and I came to the conclusion that it is portable as long as you install the appropriate "libraries" on the host PC. I couldn't find any information about the ability to package the entire code (with or without the Python interpreter) into a single file that can be installed without needing host system dependencies. But I may well have missed something.

And, to be fair, you would search for a long time for instructions for packaging a JRuby project. Even though it is easy to do when you figure it out, the "experts" like to find complex ways to do stuff :)

...R

Python and GUI is a pain! I love the comfortable way building GUIs in Visual Studio.

Yesterday I found another option.

Processing in connection with G4P. It has a GUI-Builder on board. It is Java, even if I do not see anything of it.

From Processing I can build packages for Linux (x32 / x64), Windows (x32 / x64) and MacOS.

At the weekend I'll deal with it a little.

Happy hacking!