Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Maik Schmidt - Arduino A Quick-Start Guide, 2nd Edition (The Pragmatic Programmers) - 2015.pdf
Скачиваний:
146
Добавлен:
22.03.2016
Размер:
30.47 Mб
Скачать

Learning How to Desolder 247

As soon as the solder starts to flow, you’re safer, because the solder distributes heat automatically. Feed some more solder (not too much!) until you have a nice, shiny solder joint. The whole process shouldn’t take more than two to three seconds. When you’re finished, remove the iron tip quickly and give the joint a few seconds to cool down.

Repeat this for all six pin headers, and the result should look like this:

Test it by building the motion-sensing game controller, and play a video game to relax.

Congratulations! You have just finished your first soldering job!

Learning How to Desolder

Let’s face it: even if soldering isn’t that difficult, things can still go wrong. Sometimes you solder a part to the wrong place. In other cases you accidentally use too much solder and create unwanted connections. To correct such mistakes, you have to remove the excessive solder.

The following figure shows two of the most popular tools for desoldering. On the left you see a desoldering braid, and on the right you see a desoldering pump (also known as a solder sucker).

report erratum • discuss

Appendix 1. Electronics and Soldering Basics 248

Both tools work the same in principle: you heat the solder you want to get rid of with the soldering iron, and then you use the tool to remove the molten solder. When you use the desoldering pump, you heat the solder until it melts, and then you press the pump’s button to suck the solder.

To desolder using braid, put the braid on top of the solder joint you’d like to remove. Then press the soldering iron’s tip to the braid and wait until the solder melts. The braid will suck the molten solder automatically.

Make sure that the distance between your fingers and the solder joint is reasonable, because the braid gets pretty hot. Also make sure you’re using a part of the braid that isn’t full of solder already.

This tutorial is only a starting point for your new shiny soldering career. You now know that soldering isn’t too difficult, and as a next step, you can try to build some beginner’s kits. All electronics stores offer them, and they usually come with soldering instructions, too. You can also find excellent tutorials and even videos on the Internet to build your skills.3

3.http://store.curiousinventor.com/guides/How_to_Solder

report erratum • discuss

APPENDIX 2

Advanced Arduino Programming

In reality, the Arduino programming language is nothing but C++, but it has some restrictions, and it uses a special tool suite. In this appendix, you’ll learn what your options are. Also, you’ll find a short section showing how bit operators work, because you need them often when working with sensors and other devices.

The Arduino Programming Language

The first sketches you’ll write for an Arduino might seem to be written in a special Arduino language, but they aren’t. To program the Arduino, you usually use plain old C/C++. Unfortunately, the Arduino doesn’t understand C or C++ code, so you have to compile the code on your PC or Mac into machine code suitable for the Arduino’s microcontroller. This process is called cross-compiling, and it’s the usual way of creating executable software for microcontrollers. You edit and compile the software on your PC, and then you transfer the machine code to the microcontroller.

In case of the Arduino, these microcontrollers are often part of the AVR family produced by a company named Atmel. To make software development for Atmel microcontrollers as easy as possible, Atmel has developed a whole tool chain based on the GNU compiler tools. All tools work like the originals, but they have been optimized for generating code for the Atmel microcontrollers.

For nearly all GNU development tools, such as gcc, ld, or as, there’s an AVR variant: avr-gcc, avr-ld, and so on. You can find them in the hardware/tools/avr/bin directory of the Arduino IDE.

The IDE is mainly a graphical wrapper that helps you avoid using the com- mand-line tools directly. Whenever you compile or upload a program using the IDE, it delegates all work to the AVR tools. As a serious software developer,

report erratum • discuss

Appendix 2. Advanced Arduino Programming 250

you should turn on a more verbose output, so you can see all command-line tool invocations. Enable verbose output for both compilation and upload in the Preferences menu, as described in Changing Preferences, on page 26. Then load your blinking LED sketch and compile it. (We did this back at the start of our journey in Changing Preferences, on page 26).

The command invocations look weird at first because of the names of the many temporary files that are created. You should still be able to identify all compile and link steps necessary to build even a simple sketch like our blinking LED example. That’s the most important thing the Arduino team did: they hid all these nasty details well behind the IDE, so even people with no software development experience can program the Arduino. For programmers, it’s a good idea to work in verbose mode, because the best way to learn about all the AVR tools is to see them in action.

Upload the program to the Arduino now to see avrdude in action. This tool is responsible for loading code into the Arduino and can be used for programming many other devices, too. Interestingly, the AVR tools even make it possible to use the Arduino IDE for non-Arduino projects.

There’s another difference between Arduino programming and regular C++ code. When programming for the Arduino, you don’t define main yourself, because it is already defined in the libraries provided by the Arduino developers. As you might have guessed, it calls setup first and then runs the loop function in a loop. Since Arduino 1.0, it also calls serialEvent at the end of the loop function.

Further restrictions when programming C++ on AVR microcontrollers include the following:1

You cannot use the Standard Template Library (STL) because it’s way too big for the small AVR microcontrollers.

Exception handling isn’t supported. That’s why you see the -fno-exceptions switch often when the avr-gcc compiler is invoked.

Dynamic memory management using new and delete isn’t supported.

In addition to all that, you should keep an eye on performance. C++ automatically creates a lot of functions (copy constructors, assignment operators, and so on) in the background that are rarely needed on the Arduino. Even with these restrictions, the Arduino supports a powerful subset of the C++ programming language. So there’s no excuse for sloppy coding!

1.http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus

report erratum • discuss

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]