top of page

Overview

On the software side, we have three major components: a Graphical User Interface (or GUI), G-code generation, and GRBL. The GUI allows the user to control our machine intuituvely. G-code is a numerical control programming language used in CNC mills and 3d printers. It defines points in space using x, y, and z positions. It also has other codes to tell a machine what to do at that point. Based on the user input, we were able to generate our own G-code that controlled the position of the pen and pressure the pen was exerting on the paper. GRBL is a program written for Arduino microcontrollers that takes in G-code line by line and controls stepper motors. GRBL was essential for taking our user input and transferring it to the machine.

Graphical User Interface (GUI)

To control the machine, we have a Graphical User Interface (or GUI). The primary GUI allows the user to input text and a variety of formatting options, which is then sent to the machine. Our default options allow the user to simply input text and get the machine writing in two mouse clicks. To make sure the user understands their output, we included a preview where the user sees what their text will look like and where it will be on the page. The user must then approve this to start the machine. 



​

​

​

​

​

​

​

​

​

​

​

​

​

​

 

​

​

​

​

​

​

​

​

​

​

We wrote the GUI in Python using Tkinter, matplotlib, and Python Imaging Library. On the left half of the primary GUI, the user chooses all the format settings for the document. Options include page size, font, title font size, body font size, margins, body alignment (horizontal and vertical) and title alignment (horizontal). These options all default to our most common selections. While most of this side was just Tkinter's radio buttons and spinboxes, we did have an interesting time figuring out how to insert pictures of our fonts so the user could see an example. Using ImageTk from Python Imaging Library, we were able to insert the pictures as buttons for the user.



On the right half of the GUI, the user can input two different types of text. First, there is title input, where the user has the ability to enter one line of text. This line will be inserted first and can be formatted differently from the rest of the page. Next, the user inputs the body text. If the input user gives is larger than their space constraints, a pop-up warns them about what they need to change.



On the bottom of the GUI, the user has three different options: quit, continue, or submit their own file. Submitting their own file is a feature that allows users to submit previous writings or new G-code that we didn't generate, which follows our goal of not holding the user back. This gives our machine the ability to draw pictures. The user's G-code does need to fit within Herald's G-code specifications so it does not cause our machine to damage itself. Regardless of whether the user is opening or creating the G-code, a preview GUI shows the user what the machine will write. This preview is generated by opening the G-code and filtering it into x, y and z. We then use the x and y position to plot how the pen will move and z to determine whether the pen is touching the paper or not. The plot also shows the margins and the page size. Once the user approves the preview, the function that runs the machine is called.​

 

G-code Generation

In order to send the user's input to the machine, we had to convert text and options into G-code. G-code is code containing instructions that tell machines where to move to, how fast to move, and what path to move through. G-code has machine commands like G01 (move linearly to the next location) and G04 (wait a set amount of time then continue) and location commands like X-1.05 Y-2.30 or Z-0.1.


To get from user input to G-code, we took two fonts and extracted the X,Y-coordinate information that defines the outline of the letter. We wrote a function that creates a python dictionary for the font from a .CHR file to map each ASCII character to a nested list containing all the information for the letter path. The text inputted by the user is broken down into lists of characters. The starting position is then set based on margin and centering choices specified by the user. The function then goes through and creates that page by generating G-code based on the strokes of each character. When we want to add a title and body text, we call this function twice.

​

Once we have G-code and the user has approved the preview, we send it off to the machine.
GRBL is a program that integrated the software side and mechanical side of the project. We send GRBL G-code line by line through the Serial Port to the Arduino. GRBL reads the G-code and sends the signals to drive our motors accordingly. GRBL is optimized so that it can go through our G-code as quickly as possible.


For those who spend their time on stackoverflow and read hackernews, GRBL is written completely in C, and compiles down to a hex file which is flashed onto the Arduino. We configured it by serial, in order to account for our choices of direction, steps per revolution for each stepper motor, maximum velocity and maximum acceleration. When the G-code is created, we use a version of GRBL's 'stream.py' file that we optimized, to stream G-code to GRBL. GRBL uses complex algorithms and look ahead to control the motors in such a way that optimizes for speed and avoids skipping. Because GRBL is written in optimized C and includes many lines of code, we made design decisions to minimze changes to GRBL. The most notable was using steppers for all three axis. We consider this limitation to be well worth it, however, because using GRBL greatly increased the possible speed of our machine and also simplified serial communication and motor control.

bottom of page