Arduino Sketches. Langbridge James A.
Чтение книги онлайн.

Читать онлайн книгу Arduino Sketches - Langbridge James A. страница 8

Название: Arduino Sketches

Автор: Langbridge James A.

Издательство: Автор

Жанр: Зарубежная образовательная литература

Серия:

isbn: 9781118919699

isbn:

СКАЧАТЬ closing motorized shades at the push of a button. Some people come up with even more amazing and fun projects: a remote-controlled lawn mower, even a chess playing robot. The possibilities are almost unlimited. There are a few things that an Arduino cannot do, but that list is becoming shorter every time a new Arduino-compatible board is released.

      Arduino is an excellent way to learn about software development and electronics because it is a low-cost, robust device that is easy to program.

      Some people use Arduino for hobbyist electronics, with projects ranging from the simple to the incredibly absurd. I know of one person who has entirely automated his house using 10 Arduino Megas, each room communicating with the others to better estimate electrical consumption, heating, and personal comfort.

      Arduino is also used professionally because the components are low-cost and highly reliable and have the added flexibility of being open source. When an initial design is completed, developers can make a board much smaller to be included in toys, small embedded systems, and even industrial machines. Several 3-D printers are based on Arduino for their ease of use and reliability.

      What You Will Need for This Book

      Each chapter has a list of elements required to complete. However, when creating an Arduino project, a few items are required every time. Following is a list:

      • A power supply– The Arduino Uno accepts an input voltage of 6 to 20 V, with 7 to 12 V being recommended. Any standard AC-to-DC center-positive adapter should work fine, preferably one that can supply up to or over 1 amp of current.

      • Multimeter– Almost any model. You do not need to buy the most expensive, far from it, but it should test DC voltage, DC amperage and continuity, with optional resistance calculation, and AC voltage and amperage if you plan to interface your Arduino to main's power.

      • Breadboard– The size depends on your project. Consider a medium-sized board; if it is too small you might not fit all your components (or it might be too cramped, possibly creating short circuits), and large breadboards can cost more and require more space. (I use 680-point breadboards for most of my examples and projects.)

      • Resistors– A common element of every project. There are numerous values, but there are some values that will be used more often. There are kits on the market that propose 10 of every value, or you can go with the most common, the choice is yours. To start out, ten 220-ohm, ten 1-kilohm, and ten 10-kilohm resistors should suffice.

      • LEDs– A great way of knowing the output of a pin. Coupled with a resistor, it can instantly show the state of your project.

      • Other electronic components– Sometimes it is handy to have a small collection of capacitors, switches, and diodes on hand. Each example in this book has a complete list of the required components.

      Summary

      This chapter briefly talked about some of what an Arduino can do, but there is no way of knowing exactly what everyone will do with it. As I said, your only limitation will be your imagination, and I would love to hear about what you have done with an Arduino! You can contact me on my website at http://packetfury.net. I look forward to hearing about your projects!

      In the next chapter, you will learn more about programming an Arduino, including how to install the Arduino IDE, how to connect an Arduino to your computer, and uploading your first sketch.

      Chapter 2

      Programming for the Arduino

      The Arduino is an embedded system, that is to say it has the minimum amount of hardware to get the job done. That does not mean that it is by any means a weak system; there is no point in having a PCI bus if it will never be used – it will only take up space, energy, and increase the overall cost of the device. Arduinos are lightweight – and inexpensive – and make excellent embedded systems. Just like all embedded systems, programming is done on a host computer, not the Arduino itself.

      Programming an embedded system, and indeed programming any sort of system, is the art of writing text that can be understood by a human, and translating it into a binary file that can be understood by a processor. For this, some tools are required. The data written by humans is called source code, and because most source code is in text format, sometimes a simple text editor is enough. Most people go with an Integrated Development Environment (IDE), an augmented text editor with add-ons designed for developers. These add-ons can range from text auto-completion to debugging and often include tools to handle different types of source files, which contain source code. Some projects might use only one file, but large projects can sometimes have hundreds of files, if not thousands. After the source code is written, a compiler must be used, which reads in the source code and creates one or more binary files. These binary files are later uploaded onto the Arduino and run by the microcontroller.

      Arduino developed all the tools required to get straight to work. With a different embedded system, you may have to make a choice of an IDE, install a compiler, and sometimes even a flasher, and spend precious hours setting up the system. With Arduino, this isn't the case; everything is delivered in a simple package and contains everything needed, from writing your programs to flashing the final binary file.

      An Arduino program is known as a sketch. There are several definitions of the word sketch such as a brief literary composition or a brief musical composition. Whatever your preference, an Arduino sketch is like a work of art; you, the artist, gather and assemble elements to create your masterpiece. Google X engineer Jeremy Blum, author of the book Exploring Arduino (Wiley, 2013), said,

      I believe that creative engineering is indistinguishable from fine artwork.

      The Arduino will be your canvas; you are on your way to making something amazing using sketches and electronics. Your only limitation will be your imagination.

      Installing Your Environment

      The first thing that you need to do is to install the Arduino IDE. The Arduino IDE is a fully integrated piece of software written in Java. Java can run on multiple platforms, and the IDE is available for Windows, Mac OS X, and Linux. You can get the Arduino IDE free of charge at the Arduino website:

      http://arduino.cc/en/main/software

      On this page, you will most likely have several options. The latest stable version will always be listed first. Next, any beta versions available will be listed. Beta versions are test versions that might not be up to the quality of a finished version but that add functionality; it will be up to you to decide if you want to use it. Beta versions sometimes support more hardware, and if you use the latest Arduino boards, you might not have a choice.

      Also listed on the site are nightly builds and builds for specific hardware. Nightly builds are installers that are generated every night that contain the latest updates but may in some rare cases also have bugs. Specific builds are builds created for a single board in mind. At the time of writing, there is an IDE available for the Intel Galileo, an Arduino compatible board designed and manufactured by Intel that does not use the same compiler.

      Downloading the Software

Time to get to work! You have to download the software, so find the latest version and download it. Figure 2.1 shows what the Arduino site looks like on my development computer.

СКАЧАТЬ