Book Image

C Programming for Arduino

By : Julien Bayle
Book Image

C Programming for Arduino

By: Julien Bayle

Overview of this book

Physical computing allows us to build interactive physical systems by using software & hardware in order to sense and respond to the real world. C Programming for Arduino will show you how to harness powerful capabilities like sensing, feedbacks, programming and even wiring and developing your own autonomous systems. C Programming for Arduino contains everything you need to directly start wiring and coding your own electronic project. You'll learn C and how to code several types of firmware for your Arduino, and then move on to design small typical systems to understand how handling buttons, leds, LCD, network modules and much more. After running through C/C++ for the Arduino, you'll learn how to control your software by using real buttons and distance sensors and even discover how you can use your Arduino with the Processing framework so that they work in unison. Advanced coverage includes using Wi-Fi networks and batteries to make your Arduino-based hardware more mobile and flexible without wires. If you want to learn how to build your own electronic devices with powerful open-source technology, then this book is for you.
Table of Contents (21 chapters)
C Programming for Arduino
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding Arduino software architecture


In order to understand how to make our nice Arduino board work exactly as we want it to, we have to understand the global software architecture and the toolchain that we'll be using quite soon.

Take your Arduino board in hand. You'll see a rectangle-shaped IC with the word ATMEL written on the top; this is the processor.

This processor is the place that will contain the entire program that we'll write and that will make things happen.

When we buy (check Appendix G, List of Components' Distributors, and this link: http://arduino.cc/en/Main/Buy) an Arduino, the processor, also named chipset, is preburnt. It has been programmed by careful people in order to make our life easier. The program already contained in the chipset is called the bootloader (http://en.wikipedia.org/wiki/Booting). Basically, it takes care of the very first moment of awakening of the processor life when you supply it some power. But its major role is the load of our firmware (http://en.wikipedia.org/wiki/Firmware), I mean, our precious compiled program.

Let's have a look at a small diagram for better understanding:

I like to define it by saying that the bootloader is the hardware's software and the firmware is the user's software. Indeed, it also has some significance because memory spaces in the chipset are not equal for write operations (within a specific hardware which we'll discuss in the future sections of this book). Using a programmer, we cannot overwrite the bootloader (which is safer at this point of our reading) but only the firmware. This will be more than enough even for advanced purposed, as you'll see all along the book.

Not all Arduino boards' bootloaders are equivalent. Indeed, they have been made to be very specific to the hardware part, which provides us more abstraction of the hardware; we can focus on higher levels of design because the bootloader provides us services such as firmware upload via USB and serial monitoring.

Let's now download some required software:

Processing is used in this book but isn't necessary to program and use Arduino boards.

Tip

What is the Arduino's toolchain?

Usually, we call Arduino's toolchain a set of software tools required to handle all steps from the C code we are typing in the Arduino IDE on our computer to the firmware uploaded on the board. Indeed, the C code you type has to be prepared before the compilation step with avr-gcc and avr-g++ compilers. Once the resulting object's files are linked by some other programs of the toolchain, into usually only one file, you are done. This can later be uploaded to the board. There are other ways to use Arduino boards and we'll introduce that in the last chapter of this book.