Create your pancakes with code!
This lesson introduces you to the concepts behind CNC Computer language called G-Code and walks you through a step by step introduction on creating your own computer generated pancake designs with your PancakeBot.
Outcomes/Objectives
Use G-Code to learn how to control PancakeBot and use the coordinate plane to create horizontal or vertical lines in G-code.
Lesson Overview
In this lesson, students will relate their earlier work with the coordinate plane to the PancakeBot. The teacher will demonstrate, using this exciting technology, a real-world application of this math skill. The teacher will show students how to use G-code to communicate with PancakeBot to print out horizontal or vertical lines on the machine’s coordinate plane.
After understanding the basic commands needed for printing out a horizontal or vertical line on PancakeBot, students will work in pairs to write the code. The teacher and/or other adults will circulate among pairs to give real time, constructive feedback on whether their code will work.
Students can then assess each other’s code, making any changes as needed. Once they are happy with their work, they can use PancakeBot one pair at a time to enter their code.
When all students have had a chance to enter their code, they can approach the PancakeBot one pair at a time to test out their code. Teacher or other adults in the room will assist with turning the machine on and off, filling the machine with pancake batter, clean up, etc. Each pair of students will create two lines using their code, so that they can eat the results afterwards.
At the end of the lesson, students will complete a short assessment, the Sample Coding Scenario sheet, that presents them with the following question: If Student X wrote the following code for PancakeBot, would it produce a horizontal line? Why or why not?
Teacher: Laptop, LCD projector, big G-code chart, PancakeBot, premixed batter, towels, forks and plates.
Students: 1 laptop per pair, G-code sheet, Sample Coding Scenario sheet, plates, forks, and assessments.
Grouping Strategy: Students can be paired according to their comfort level with the coordinate plane, their comfort level with technology, or their comfort level with programming languages. Goal-oriented students with greater stamina or a greater ability to try new challenges can be paired with students that need more support and encouragement. If all students are close in ability, pairing them according to stamina and readiness for challenge may be a good strategy.
Academic Vocabulary:
Programming language
G-Code
Zeroing
Extrusion
Polygon
Pressure
Vacuum Pressure
Calibration
Feed Rate
Standard
CNC
SAFETY FIRST
When operating the PancakeBot, there are few precautions one must take.
Become familiar with PancakeBot's G-code commands and a G-code file.
G-code Commands
PancakeBot is a CNC machine which uses basic commands to move the bottle to different places on the griddle, and drop pancake batter.
The commands are written in a programming language called G-Code that tells a machine how it should make a pancake.
Here is a list of the commands that commands that PancakeBot uses.
Typical G-Code File Setup
When creating a G-Code file, you simply use a text editor and change the extension of the file from .txt to .gcode. You will neet to set up your settings on your computer to see file extensions if you cannot see them.
You can add comments after the semicolon after any command.
For Example, if you want to make a comment after the G-Code command to turn the motors off, you write the following:
M84; Turn Movement Motors Off
You can also just add a semicolon and a comment afterwards.
A newline is a new command.
Task 1:
Write the G-code command to create a line from the following points:
10,15 to 30,40
Task 2: Write the G-code command to set the speed to 5.4 meters per minute
Task 3: Write the G-code command to turn the batter pump on, and then add a the comment “Batter is flowing!”
It is time to code and draw your first pancake. You'll set up the coordinates, and print out your pancake. You'll aslo get an opportunity to review your design and make changes to it.
*******
;Set Up My PancakeBot
G21; Set Units to MM
G1 F7600; Set Speed to 7600 mm per minute
M107; Turn Batter Dispenser off to stop batter flow
G28; Home All Axis
;Making My Pancake
;Finish Printing
G28 X0 Y0; Home all axis
M84; Turn Movement Motors Off
*******
Once the file is set up, we can now begin looking at how we will draw our square pancake.
Note that this setup can be used for al types of pancakes!
In this step you'll make a drawing on graph paper, and use that drawing as a reference for your square pancake. The PancakeBot uses mm as its unit of measurement, but your graph paper does not have to be in mm, you just have to be consistent with your numbers.
When you look at the griddle of the pancakebot, you will need to imagine that there is a grid made up of one by one mm squares. There are 220 squares along the short side of the PancakeBot griddle, and 485 squares on the long side of the PancakeBot griddle, this means we have an area of 220mm x 485 mm. In Figure 1, we shows squares every 10 mm (not to scale).
For your first pancake, you’ll only need to go out at least 150 mm. You can set up your graph paper to have as many mm per square as you want based on the scale of your drawing. In Figure 2, each square is 10mm X 10mm
This grid shows a square with the following coordinates
(30,30)
(130,30)
(130,130)
(30,130)
Notice that the points aren’t in any order, so you could start drawing your pancake from any point. For this example, we will start at (30,30) and move in a counterclockwise fashion. Use Figure 3 as a referance.
Next, we need to take these coordinates and write them into the G-Code so PancakBot can understand what to do.
We’ll go ahead and start off with 30,30 as our first point and work our way around.
G00 X30 Y30; Move bottle to coordinates (30,30)
G00 X130 Y30; Move bottle to coordinates (130,30)
G00 X130 Y130; Move bottle to coordinates (130,130)
G00 X30 Y130; Move bottle to coordinates (30,130)
G00 X30 Y30; Move bottle to coordinates (30,30)
Figure 4 shows how the G-Code and Coordinates relate to one another.
These are the G-Code Commands we will be using to tell the PancakeBot to move from one spot to another.
We'll take the previous steps and wrap it all together to print our first Pancake.
Copy the G-Code commands from the previous two steps to complete your square file.
It should look something like this.
**********
;Set Up My PancakeBot
G21; Set Units to MM
G1 F7600; Set Speed to 7600 mm per minute
M107; Turn Batter Dispenser off to stop batter flow
G28; Home All Axis
G00 X30 Y30; Move bottle to coordinates (30,30)
G00 X130 Y30; Move bottle to coordinates (130,30)
G00 X130 Y130; Move bottle to coordinates (130,130)
G00 X30 Y130; Move bottle to coordinates (30,130)
G00 X30 Y30; Move bottle to coordinates (30,30)
;Finish Printing
G28 X0 Y0; Home all axis
M84; Turn Movement Motors Off
********
Test Your Code
Take your file and save it to the SD Card. Try running the pancakebot without any batter and see if your code works.
Once you tested it, and the PancakeBot moved in a square, you need to tell the PancakeBot to turn on the Pancake Bottle Dispenser.
We use the M106 & M107 commands to start the batter pouring.
**********
;Set Up My PancakeBot
G21; Set Units to MM
G1 F7600; Set Speed to 7600 mm per minute
M107; Turn Batter Dispenser off to stop batter flow
G28; Home All Axis
M106; Turn Batter Dispenser On to start batter flow
G00 X30 Y30; Move bottle to coordinates (30,30)
G00 X130 Y30; Move bottle to coordinates (130,30)
G00 X130 Y130; Move bottle to coordinates (130,130)
G00 X30 Y130; Move bottle to coordinates (30,130)
G00 X30 Y30; Move bottle to coordinates (30,30)
M107; Turn Batter Dispenser off to stop batter flow
;Finish Printing
G28 X0 Y0; Home all axis
M84; Turn Movement Motors Off
********
Now that your batter control is started, give your file a test run with PancakeBot and test out your print.
In this final step we talk about timing is everything with the PancakeBot, and how you need to use timing, to get different results.
First Consideration: Mind The Gap
After your first test print, did you notice something strange about your square pancake? It probably looked like this.
But why?
Well, let’s look at what is happening. You have a gap at the beginning of the line, and a blob on the end. When you start off your square, you turn the batter bottle on, and instantly start moving the head of the PancakeBot.
Since batter can be thick or thin, the batter may not start flowing instantly, so if the head is moving, you will get a space on the griddle between the time the head starts moving, and when the batter hits the griddle.
To avoid that, you can start the batter flow, and use the pause command to give the batter time to hit the griddle.
Look back at the first code, and look for the pause command.
The G4 command pauses the movement of the machine for a specified time.
The time you specify depends on how thick the batter is.
A good rule of thumb is that thin batter, needs about .5 seconds to get to the griddle if the bottle is in the lowest notch, and thick batter, can need about 1.35 seconds to get to the griddle if the bottle is in the lowest notch.
You can change the pause time as you see fit, but go ahead and place it in between the start of the bottle and the first movement.
**********
;Set Up My PancakeBot
G21; Set Units to MM
G1 F7600; Set Speed to 7600 mm per minute
M107; Turn Batter Dispenser off to stop batter flow
G28; Home All Axis
M106; Turn Batter Dispenser On to start batter flow
G4 P750; Pause the machine for 750 milliseconds (¾ of a second). This allows the batter to drop down to the griddle.
G00 X30 Y30; Move bottle to coordinates (30,30)
G00 X130 Y30; Move bottle to coordinates (130,30)
G00 X130 Y130; Move bottle to coordinates (130,130)
G00 X30 Y130; Move bottle to coordinates (30,130)
G00 X30 Y30; Move bottle to coordinates (30,30)
M107; Turn Batter Dispenser off to stop batter flow
G4 P750; Pause the machine for 750 milliseconds (¾ of a second).
;Finish Printing
G28 X0 Y0; Home all axis
M84; Turn Movement Motors Off
********
Last consideration: The Blob
Run your print one more time and see how it looks.
Here is an image of the anticipated results based on our last change.
Do you notice that there is still a blob at the end of the print? Why do you think this might happen?
When the head of the dispenser reaches the end, it stops the batter flow by switching to a negative pressure and retracting the batter. This of course, takes a bit of time to fully stop the flow since there is a gap between the bottle tip, and the surface of the griddle.
The way this is addressed is by stopping the batter flow before it reaches the end of the line.
Based on the viscocity of the batter, this timing will vary. Unfortunately the PancakeBot does not have the ability to adjust the timing and distance delay on the unit itself, so one has to do this with G-Code.
To do this, you will break up the last line between coordinates (30,130) and (30,30) into two shorter lines. The first line will take us from (30,130) to (30,40).
G00 X30 Y130; Move bottle to coordinates (30,130);
G00 X30 Y40; Move bottle to coordinates (30,40);
You will then stop the flow by turning of the dispenser with the M107 command.
M107; Turn Batter Dispenser off to stop batter flow;
Then, you will continue to the last coordinate
G00 X30 Y30; Move bottles to final coordinates (30,30);
Here is the final code.
**********
;Set Up My PancakeBot
G21; Set Units to MM
G1 F7600; Set Speed to 7600 mm per minute
M107; Turn Batter Dispenser off to stop batter flow
G28; Home All Axis
M106; Turn Batter Dispenser On to start batter flow
G4 P750; Pause the machine for 750 milliseconds (3/4 of a second). This allows the batter to drop down to the griddle.
G00 X30 Y30; Move bottle to coordinates (30,30)
G00 X130 Y30; Move bottle to coordinates (130,30)
G00 X130 Y130; Move bottle to coordinates (130,130)
G00 X30 Y130; Move bottle to coordinates (30,130)
G00 X30 Y40; Move bottle to coordinates (30,40), stopping the flow before reaching the end.
M107; Turn Batter Dispenser off to stop batter flow
G00 X30 Y30; Move bottle to coordinates (30,30)
G4 P750; Pause the machien for 750 milliseconds (3/4 of a second)
;Finish Printing
G28 X0 Y0; Home all axis
M84; Turn Movement Motors Off
********
If all goes well, you should either have not blob or reduce the blob at the end of your print.
After the modeling, teacher will assess student understanding. During the independent practice, teacher will visit each pair of students, refining their code as needed. Students will show success with lesson outcomes when their pancakes have been printed to their specifications. Formal assessment at the end of the lesson will assess understanding by asking students to apply their skills to a sample coding situation.
What was the most challenging aspect of writing code for PancakeBot? What was fun or exciting? How long do you think it would take to become comfortable writing in G-code?
How do you think the timing of the dispensing (The Gap and The Blob) relate to other CNC devices or 3D Printers?
Anticipated Difficulties:
Many students will be new to computer programming. Start the lesson by appealing to students’ sense of how the world works. They will quickly see that their favorite songs, shows, art supplies, sports equipment, video games, etc. all require technology to exist. Using lots of visuals, step-by-step instructions, and strong teacher modeling to give students confidence with programming will help.
Some students will not work well in pairs. Constant circulation of the teacher and any other adults in the room will help to keep groups focused and productive.
Stamina may also be an issue. If students are struggling, provide more support by talking them through the process step by step.
Consider different geometric shapes other than squares. How might you generate them with G-Code? Use the 'Remix this Lesson' Feature to upload new lessons with variations of shapes.
What G-Code coordinates are needed for the follow shapes?
Having trouble? Let us know by completing the form below. We'll do our best to get your issues resolved quickly.
"*" indicates required fields