Tag Archives: Lessons

LESSON 32: Understanding Arduino Functions

So far we have written programs as a long string of code, pretty much all in the void loop. As we begin to need to develop more complicated code, putting all the programming in the void loop can become unmanageable. It is easy to lose track of what we are doing. For more complicated programs, we want to break the problem up into manageable chunks of code. This is called modular program. We develop small modules that do specific tasks, and then our void loop simply calls these modules. The modules are called “Functions” in arduino.

Lets consider an example. Lets say we want to write an arduino program that prompts the user for the number of grades he has. Then it averages the grades, prints the grades and then prints the average. The following program would do this job, with all the code in the void loop:

You can see that the void loop is getting pretty complicated, and it would be easy to begin to lose track of what is going on. If we think about what we are trying to do, lets try to break it down more logically. These are the logical tasks we need to do:

Input Grades

Average Grades

Print Grades and Average

I think that is the logical way to break the program down. Hence, we need three modules or functions, which we could define as follows:

inputGrades();

avGrades();

printGrades();

We could call these three functions in the void loop. then down below the void loop we would need to define, or teach arduino what each of these functions do. In effect, the code in the example above is put down in three logical blocks, which we call functions. Notice that when we do that, the functions must be defined AFTER the void loop. That means it is done after the closing curly bracket for the void loop. Using functions, we can rewrite the program above as follows:

Notice now that the void loop is very simple to understand, since each function is logically named. Also, if we look down at the function definition, it is clear what each chunk of code does. In this example, we are using global variables, so each function, and the void loop are all working with the same set of variables. In future lessons we will look at the use of local variables, and then how that would affect the structure of our functions.

Sketchup Tutorial LESSON 6: Understanding Design Rules

One of the keys to success in mechanical design comes from understanding that you can draw things that you can not build. Just because you can make it in Sketchup does not mean your fabricator can make it. You must design being mindful of the capabilities of your fabrication infrastructure. This comes down to the concept of design rules. Design rules are a set of conditions. If you design your devices following the conditions in your design rules, your design will fabricate properly. Your design rules will depend on your fabrication infrastructure. In our case, we are building on our own 3D printer, but none the less, we still need to develop some design rules. In this video we show how to design a simple test device that will allow us to know how small of a line we can print, and how closely we can put two holes to each other. This simple set of two design rules is a good start of successful designing for a 3D printer.

Sketchup Tutorial LESSON 3: Printing Sketchup Designs on a 3D Printer

In this video lesson we describe how to print designs from Sketchup on a 3D printer.  Key thing is you need to go to the sketchup Extension Warehouse, under the window tab in scketchup. Then you need to search for and install the .STL Export extension. With this extension, you can export your design file as an .stl file. Then you can load the .stl file into your slicer software to generate the gcode for the printer. I found that it is very straightforward to go from sketchup to the 3D printer.

Raspberry Pi Zero Model W Tutorial 2: Making a Wireless Portable IP Camera

Raspberry Pi Zero W Camera
Super Cool Portable Wireless streaming IP Camera

This is a super cool project where we build a concealable, portable, live streaming IP camera based on the Raspberry Pi Zero Model W, and the Raspberry Pi camera module. In order to do this lesson, you need to start with Lesson 1,  where we show you how to get the IP address of your Pi zero, and how to get it booted. For this project, you need a Raspberry Pi Zero Model W. If you do not have one, you can get the ESSENTIAL HARDWARE HERE.  In addition, you will need the Raspberry Pi  Camera, which you can GET HERE.  The Pi Zero needs a special Camera Cable, which you can get HERE.

That should be the equipment you need to this really fun project. When you are ready to go, the instructions are in the video below.