Free Resources
now we will discuss the engineering process and how you can use it streamline your prototypes by avoiding problems with hardware and software and keeping to a fixed schedule. Throughout this book, you will have projects that will be organized into a sequence I like to call the ?engineering process.? Here?s a quick summary of the sequence:
As you can imagine, even this summary of engineering process is
very effective when prototyping, which is why we will use it with the Arduino in
this book. What is the Arduino? The Arduino is a very customizable
microcontroller used by hobbyists and engineers alike. Also, it is open source,
which means that the source code is available to you for your programming needs;
the integrated development environment (IDE) (where you will be writing your
software) is free, and most the resources you can find are open source. The only
thing you have to buy is the Arduino microcontroller itself. The Arduino is
supported very well on the Web and in books, which makes it very easy to
research how-to topics; a few sites that will help you get started are
http://www.arduino.cc/
and
http://tronixstuff.wordpress.com/tutorials/
.
But this book is more than simply a how-to reference; this book is going to
teach you the engineering process?a skill that is useful for making projects
more readable, efficient, and reliable.
Before we examine the engineering process steps, it?s important to know some of the parts and materials you?ll need. Throughout this book, you will need the following pieces of hardware to complete the various projects we?ll be working on (for a complete list of hardware used in this book, please see Appendix A ):
Figure 1-1. Arduino UNO (left) and Duemilanove (right)
Figure 1-2. ArduinoBT (left) and Bluetooth Mate Silver (right)
Figure 1-7. Miscellaneous pieces of hardware (terminal blocks, capacitors, resistors, LEDs, and switches)
You will also use a variety of tools; this section will briefly describe them. For a full list of tools you will need, please see Appendix A.
Figure 1-8. A Soldering iron and its stand
The engineering process is very useful in making your designs more efficient, streamlined, and comprehensible. The process consists of gathering requirements, creating the requirements document, gathering the correct hardware, configuring the hardware, writing the software, debugging the software, troubleshooting the hardware, and the signing off on the finished prototype.
One Day, when you?re an engineer, you may be asked to go to a company and assess its needs for a particular project. This part of the engineering process is crucial; everything will depend on the requirements you gather at this initial meeting. For example, assume you learn that your client needs to blink an LED at a certain speed[insert an example case here to flush out the idea]. And for that task, you and the client determine that the Arduino microprocessor is the best choice. To use the Arduino to blink the LED [insert the example task here], a customer needs an LED to blink at 100ms intervals.
Based on the client?s needs and your proposed solution, the following is a very simple requirements document:
Mind you, this is a very simple example, but we will be using this format for the rest of this book. One of the reasons you create a requirements document is to stop feature creep. This happens when a customer keeps adding features to the software and/or hardware. This is, of course, a problem because you will be working more hours without more pay on a project that may never end. You should create a requirements document, so you and the client know what you are doing and the features you will be creating for your project. After you have created the requirements document, you can create a flowchart that will help you debug the software later in the design process (see Figure 1-10 ).
Figure 1-10.Blinking LEDs processes
The next very important part of the engineering process is making sure you have the right hardware. Your hardware needs should be decided as you?re gathering requirements, but it is important to make sure all your hardware is compatible. If it is not compatible, hardware changes may be necessary, but you should consult the company you are working with to make sure it is satisfied with any hardware changes.
Once you have the correct hardware, it is time to configure it. Depending on the hardware required for the project, the configuration can change. For example, let?s take a look at the hardware configuration for the blinking LED project.
To set up the hardware, we need to connect the LED to digital pin 13 and ground on the Arduino(see Figure 1-11 ), as illustrated in the schematic shown in Figure 1-12 .
Figure 1-11. The hardware setup for the Blinking LED project
Figure 1-12. A schematic of Blinking LED project
First, we need to install the Arduino IDE. To do this, go to
www.Arduino.cc/en/Main/Software
.
The Arduino IDE will work with Windows Vista or 7, Mac OS X, and Linux systems.
After the Arduino IDE is downloaded to your desktop, it will be in a zipped
format, so unzip the Arduino-0022
file to your desktop. The Arduino
IDE is now installed.
Now that you have the Arduino IDE installed on your computer, you need to make sure it is configured correctly. To do this, open the Arduino IDE, and go to Tools Serial port; select the serial port your Arduino is connected to. Next, select Tools Boards, and select the Arduino board you are using (this book uses the Arduino Duemilanove Atmega328). Once your hardware is configured, it is time to write the software.
Now, let?s consider the software we need to write. This part of the engineering process is crucial. Let?s take a look at the blinking LED software requirements document to decide what the software will need to do: the LED needs to blink in 100msn intervals. The software might look something like this:
// This code blinks an LED at 100ms
const int
LEDdelay = 100; // delay time
void
setup()
{
pinMode(13, OUTPUT); //
makes pin 13 an output
}
void
loop()
{
digitalWrite(13,
HIGH); // this writes a high bit to pin
13
delay(LEDdelay); //
delay 100ms
digitalWrite(13,
LOW);
delay(LEDdelay)
//
this will throw a syntax error due to a missing semicolon
}
Note When you
try to compile this program to your Arduino, it gives you an error. This is
because of a syntax error that we will debug in the next section.
The last program failed to compile because of a syntax error . This type of error is because of incorrectly formatted code, such as a missing semicolon (which is why the last program didn?t compile). Here is the revised code:
// This code blinks an LED at 100ms
const int
LEDdelay = 100; // delay time
void
setup()
{
pinMode(13, OUTPUT); //
makes pin 13 an output
}
void
loop()
{
digitalWrite(13,
HIGH); // this writes a high bit to pin
13
delay(LEDdelay); //
delay 100ms
digitalWrite(13,
LOW);
delay(LEDdelay); //
the semicolon is now present and the code will compile
}
Syntax errors are not the worst errors out there. The worst errors you can receive are logical errors; these errors allow the code to compile, but the end result is unexpected. For example, using a greater-than symbol instead of less-than is a logical error, and if it is in a project with thousands of lines, it can be almost impossible to fix.
We can debug logical errors in an Arduino program by using a flowchart to figure out where the values are not lining up.
The number one tool used to troubleshoot hardware is the multimeter. This tool can save your hardware from being damaged. For instance, if your multimeter detects that your power supply is more than is required, the hardware setup for the blinking LED project could use a 22ohm resistor to keep the LED from burning out.
Once you have finished debugging the software and troubleshooting the hardware, you should have a completed prototype that will work under most circumstances. In this chapter, we used a very simple project, but in future chapters, the projects will get more complicated, and the engineering process will become even more necessary to make sure our code is efficient, streamlined, and comprehensible.
In this chapter, you learned the different pieces of hardware and various tools such as: The Arduino, Arduino Shields, Multimeter, and needle-nose pliers; just to name a few that will be used throughout this book. We then went over the engineering process, which is a sequence you can use to solve problems that provides the format for this book. The steps in the process are requirements gathering, creating the requirements document, gathering the hardware, configuring the hardware, writing the software, debugging the Arduino software, troubleshooting the hardware, and finished prototype. I also defined a few new terms that will help you understand the engineering process, and you learned the differences between logical and syntax errors.