C Programming for Arduino

C Programming for Arduino
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Use Arduino boards in your own electronic hardware and software projects
  • Sense the world by using several sensory components with your Arduino boards
  • Create tangible and reactive interfaces with your computer
  • Discover a world of creative wiring and coding fun!

Book Details

Language : English
Paperback : 512 pages [ 235mm x 191mm ]
Release Date : May 2013
ISBN : 1849517584
ISBN 13 : 9781849517584
Author(s) : Julien Bayle
Topics and Technologies : All Books, Other, Open Source

Table of Contents

Chapter 1: Let's Plug Things
Chapter 2: First Contact with C
Chapter 3: C Basics – Making You Stronger
Chapter 4: Improve Programming with Functions, Math, and Timing
Chapter 5: Sensing with Digital Inputs
Chapter 6: Sensing the World – Feeling with Analog Inputs
Chapter 7: Talking over Serial
Chapter 8: Designing Visual Output Feedback
Chapter 9: Making Things Move and Creating Sounds
Chapter 10: Some Advanced Techniques
Chapter 11: Networking
Chapter 12: Playing with the Max 6 Framework
Chapter 13: Improving your C Programming and Creating Libraries
  • Chapter 1: Let's Plug Things
    • What is a microcontroller?
    • Presenting the big Arduino family
    • About hardware prototyping
    • Understanding Arduino software architecture
    • Installing the Arduino development environment (IDE)
      • Installing the IDE
      • How to launch the environment?
      • What does the IDE look like?
    • Installing Arduino drivers
      • Installing drivers for Arduino Uno R3
      • Installing drivers for Arduino Duemilanove, Nano, or Diecimilla
    • What is electricity?
      • Voltage
      • Current and power
      • What are resistors, capacitors, and so on?
      • Wiring things and Fritzing
        • What is Fritzing?
      • Power supply fundamentals
      • Hello LED!
        • What do we want to do exactly?
        • How can I do that using C code?
        • Let's upload the code, at last!
    • Summary
    • Chapter 2: First Contact with C
      • An introduction to programming
        • Different programming paradigms
        • Programming style
      • C and C++?
        • C is used everywhere
        • Arduino is programmed with C and C++
      • The Arduino native library and other libraries
        • Discovering the Arduino native library
        • Other libraries included and not directly provided
          • Some very useful included libraries
          • Some external libraries
      • Checking all basic development steps
      • Using the serial monitor
        • Baud rate
        • Serial communication with Arduino
        • Serial monitoring
      • Making Arduino talk to us
        • Adding serial communication to Blink250ms
        • Serial functions in more detail
          • Serial.begin()
          • Serial.print() and Serial.println()
        • Digging a bit…
        • Talking to the board from the computer
      • Summary
      • Chapter 3: C Basics – Making You Stronger
        • Approaching variables and types of data
          • What is a variable?
          • What is a type?
            • The roll over/wrap concept
          • Declaring and defining variables
            • Declaring variables
            • Defining variables
        • String
          • String definition is a construction
          • Using indexes and search inside String
            • charAt()
            • indexOf() and lastIndexOf()
            • startsWith() and endsWith()
          • Concatenation, extraction, and replacement
            • Concatenation
            • Extract and replace
          • Other string functions
            • toCharArray()
            • toLowerCase() and toUpperCase()
            • trim()
            • length()
          • Testing variables on the board
            • Some explanations
        • The scope concept
        • static, volatile, and const qualifiers
          • static
          • volatile
          • const
        • Operators, operator structures, and precedence
          • Arithmetic operators and types
            • Character types
            • Numerical types
          • Condensed notations and precedence
          • Increment and decrement operators
        • Type manipulations
          • Choosing the right type
          • Implicit and explicit type conversions
            • Implicit type conversion
            • Explicit type conversion
        • Comparing values and Boolean operators
          • Comparison expressions
          • Combining comparisons with Boolean operators
            • Combining negation and comparisons
        • Adding conditions in the code
          • if and else conditional structure
          • switch…case…break conditional structure
          • Ternary operator
        • Making smart loops for repetitive tasks
          • for loop structure
            • Playing with increment
            • Using imbricated for loops or two indexes
          • while loop structure
          • do…while loop structure
          • Breaking the loops
          • Infinite loops are not your friends
        • Summary
        • Chapter 4: Improve Programming with Functions, Math, and Timing
          • Introducing functions
            • Structure of a function
              • Creating function prototypes using the Arduino IDE
              • Header and name of functions
              • Body and statements of functions
            • Benefits of using functions
              • Easier coding and debugging
              • Better modularity helps reusability
              • Better readability
          • C standard mathematical functions and Arduino
            • Trigonometric C functions in the Arduino core
              • Some prerequisites
              • Trigonometry functions
            • Exponential functions and some others
          • Approaching calculation optimization
            • The power of the bit shift operation
              • What are bit operations?
              • Binary numeral system
              • AND, OR, XOR, and NOT operators
              • Bit shift operations
              • It is all about performance
            • The switch case labels optimization techniques
              • Optimizing the range of cases
              • Optimizing cases according to their frequency
            • The smaller the scope, the better the board
            • The Tao of returns
              • The direct returns concept
              • Use void if you don't need return
            • Secrets of lookup tables
              • Table initialization
              • Replacing pure calculation with array index operations
            • The Taylor series expansion trick
            • The Arduino core even provides pointers
          • Time measure
            • Does the Arduino board own a watch?
              • The millis() function
              • The micros() function
            • Delay concept and the program flow
              • What does the program do during the delay?
              • The polling concept – a special interrupt case
              • The interrupt handler concept
              • What is a thread?
              • A real-life polling library example
          • Summary
          • Chapter 5: Sensing with Digital Inputs
            • Sensing the world
              • Sensors provide new capacities
                • Some types of sensors
              • Quantity is converted to data
              • Data has to be perceived
            • What does digital mean?
              • Digital and analog concepts
              • Inputs and outputs of Arduino
            • Introducing a new friend – Processing
              • Is Processing a language?
              • Let's install and launch it
              • A very familiar IDE
                • Alternative IDEs and versioning
              • Checking an example
              • Processing and Arduino
            • Pushing the button
              • What is a button, a switch?
                • Different types of switches
              • A basic circuit
                • Wires
                • The circuit in the real world
              • The pull-up and pull-down concept
                • The pseudocode
                • The code
              • Making Arduino and Processing talk
                • The communication protocol
                • The Processing code
                • The new Arduino firmware talk-ready
            • Playing with multiple buttons
              • The circuit
              • The Arduino code
              • The Processing code
            • Understanding the debounce concept
              • What? Who is bouncing?
              • How to debounce
            • Summary
            • Chapter 6: Sensing the World – Feeling with Analog Inputs
              • Sensing analog inputs and continuous values
                • How many values can we distinguish?
                • Reading analog inputs
                  • The real purpose of the potentiometer
                  • Changing the blinking delay of an LED with a potentiometer
                  • How to turn the Arduino into a low voltage voltmeter?
              • Introducing Max 6, the graphical programming framework
                • A brief history of Max/MSP
                • Global concepts
                  • What is a graphical programming framework?
                  • Max, for the playground
                  • MSP, for sound
                  • Jitter, for visuals
                  • Gen, for a new approach to code generation
                  • Summarizing everything in one table
                • Installing Max 6
                • The very first patch
                  • Playing sounds with the patch
              • Controlling software using hardware
                • Improving the sequencer and connecting Arduino
                  • Let's connect Arduino to Max 6
                  • The serial object in Max 6
                  • Tracing and debugging easily in Max 6
                  • Understanding Arduino messages in Max 6
                  • What is really sent on the wire?
                  • Extracting only the payload?
                  • ASCII conversions and symbols
                  • Playing with sensors
                  • Measuring distances
                  • Reading a datasheet?
                  • Let's wire things
                  • Coding the firmware
                  • Reading the distance in Max 6
                • Measuring flexion
                  • Resistance calculations
                • Sensing almost everything
              • Multiplexing with a CD4051 multiplexer/demultiplexer
                • Multiplexing concepts
                • Multiple multiplexing/demultiplexing techniques
                  • Space-division multiplexing
                  • Frequency-division multiplexing
                  • Time-division multiplexing
                • The CD4051B analog multiplexer
                  • What is an integrated circuit?
                  • Wiring the CD4051B IC?
                  • Supplying the IC
                  • Analog I/O series and the common O/I
                  • Selecting the digital pin
              • Summary
              • Chapter 7: Talking over Serial
                • Serial communication
                  • Serial and parallel communication
                  • Types and characteristics of serial communications
                    • Synchronous or asynchronous
                    • Duplex mode
                    • Peering and bus
                    • Data encoding
                • Multiple serial interfaces
                  • The powerful Morse code telegraphy ancestor
                    • The famous RS-232
                    • The elegant I2C
                    • The synchronous SPI
                    • The omnipresent USB
                • Summary
                • Chapter 8: Designing Visual Output Feedback
                  • Using LEDs
                    • Different types of LEDs
                      • Monochromatic LEDS
                      • Polychromatic LEDs
                    • Remembering the Hello LED example
                    • Multiple monochromatic LEDs
                      • Two buttons and two LEDs
                      • Control and feedback coupling in interaction design
                      • The coupling firmware
                      • More LEDs?
                  • Multiplexing LEDs
                    • Connecting 75HC595 to Arduino and LEDs
                    • Firmware for shift register handling
                      • Global shift register programming pattern
                      • Playing with chance and random seeds
                    • Daisy chaining multiple 74HC595 shift registers
                      • Linking multiple shift registers
                      • Firmware handling two shift registers and 16 LEDs
                      • Current short considerations
                  • Using RGB LEDs
                    • Some control concepts
                    • Different types of RGB LEDs
                    • Lighting an RGB LED
                      • Red, Green, and Blue light components and colors
                      • Multiple imbricated for() loops
                  • Building LED arrays
                    • A new friend named transistor
                    • The Darlington transistors array, ULN2003
                    • The LED matrix
                    • Cycling and POV
                    • The circuit
                    • The 3 x 3 LED matrix code
                  • Simulating analog outputs with PWM
                    • The pulse-width modulation concept
                    • Dimming an LED
                      • A higher resolution PWM driver component
                  • Quick introduction to LCD
                    • HD44780-compatible LCD display circuit
                    • Displaying some random messages
                  • Summary
                  • Chapter 9: Making Things Move and Creating Sounds
                    • Making things vibrate
                      • The piezoelectric sensor
                      • Wiring a vibration motor
                      • Firmware generating vibrations
                    • Higher current driving and transistors
                    • Controlling a servo
                      • When do we need servos?
                      • How to control servos with Arduino
                      • Wiring one servo
                      • Firmware controlling one servo using the Servo library
                    • Multiple servos with an external power supply
                      • Three servos and an external power supply
                      • Driving three servos with firmware
                    • Controlling stepper motors
                      • Wiring a unipolar stepper to Arduino
                      • Firmware controlling the stepper motor
                    • Air movement and sounds
                      • What actually is sound?
                      • How to describe sound
                      • Microphones and speakers
                      • Digital and analog domains
                        • How to digitalize sound
                        • How to play digital bits as sounds
                      • How Arduino helps produce sounds
                    • Playing basic sound bits
                      • Wiring the cheapest sound circuit
                      • Playing random tones
                    • Improving the sound engine with Mozzi
                      • Setting up a circuit and Mozzi library
                      • An example sine wave
                        • Oscillators
                        • Wavetables
                      • Frequency modulation of a sine wave
                        • Adding a pot
                        • Upgrading the firmware for input handling
                    • Controlling the sound using envelopes and MIDI
                      • An overview of MIDI
                      • MIDI and OSC libraries for Arduino
                      • Generating envelopes
                      • Implementing envelopes and MIDI
                      • Wiring a MIDI connector to Arduino
                    • Playing audio files with the PCM library
                      • The PCM library
                      • WAV2C – converting your own sample
                      • Wiring the circuit
                      • Other reader libraries
                    • Summary
                    • Chapter 10: Some Advanced Techniques
                      • Data storage with EEPROMs
                        • Three native pools of memory on the Arduino boards
                          • Writing and reading with the EEPROM core library
                        • External EEPROM wiring
                        • Reading and writing to the EEPROM
                      • Using GPS modules
                        • Wiring the Parallax GPS receiver module
                        • Parsing GPS location data
                      • Arduino, battery, and autonomy
                        • Classic cases of USB power supplying
                        • Supplying external power
                          • Supplying with batteries
                        • Power adapter for Arduino supply
                        • How to calculate current consumption
                      • Drawing on gLCDs
                        • Wiring the device
                        • Demoing the library
                        • Some useful methods' families
                          • Global GLCD methods
                          • Drawing methods
                          • Text methods
                      • Using VGA with the Gameduino Shield
                      • Summary
                      • Chapter 11: Networking
                        • An overview of networks
                          • Overview of the OSI model
                          • Protocols and communications
                          • Data encapsulation and decapsulation
                          • The roles of each layer
                            • Physical layer
                            • Data link layer
                            • Network layer
                            • Transport layer
                            • Application/Host layers
                          • Some aspects of IP addresses and ports
                            • The IP address
                            • The subnet
                            • The communication port
                        • Wiring Arduino to wired Ethernet
                          • Making Processing and Arduino communicate over Ethernet
                            • Basic wiring
                            • Coding network connectivity implementation in Arduino
                            • Coding a Processing Applet communicating on Ethernet
                          • Some words about TCP
                        • Bluetooth communications
                          • Wiring the Bluetooth module
                          • Coding the firmware and the Processing applet
                        • Playing with Wi-Fi
                          • What is Wi-Fi?
                            • Infrastructure mode
                            • Ad hoc mode
                            • Other modes
                          • The Arduino Wi-Fi shield
                          • Basic Wi-Fi connection without encryption
                          • Arduino Wi-Fi connection using WEP or WPA2
                            • Using WEP with the Wi-Fi library
                            • Using WPA2 with the Wi-Fi library
                          • Arduino has a (light) web server
                        • Tweeting by pushing a switch
                          • An overview of APIs
                          • Twitter's API
                          • Using the Twitter library with OAuth support
                            • Grabbing credentials from Twitter
                            • Coding a firmware connecting to Twitter
                        • Summary
                        • Chapter 12: Playing with the Max 6 Framework
                          • Communicating easily with Max 6 – the [serial] object
                            • The [serial] object
                            • Selecting the right serial port
                            • The polling system
                          • Parsing and selecting data coming from Arduino
                            • The readAll firmware
                            • The ReadAll Max 6 patch
                              • Requesting data from Arduino
                              • Parsing the received data
                              • Distributing received data and other tricks
                          • Creating a sound-level meter with LEDs
                            • The circuit
                            • The Max 6 patch for calculating sound levels
                            • The firmware for reading bytes
                          • The pitch shift effect controlled by hand
                            • The circuit with the sensor and the firmware
                            • The patch for altering the sound and parsing Arduino messages
                          • Summary
                          • Chapter 13: Improving your C Programming and Creating Libraries
                            • Programming libraries
                              • The header file
                              • The source file
                            • Creating your own LED-array library
                              • Wiring six LEDs to the board
                              • Creating some nice light patterns
                              • Designing a small LED-pattern library
                                • Writing the LEDpatterns.h header
                                • Writing the LEDpatterns.cpp source
                                • Writing the keyword.txt file
                              • Using the LEDpatterns library
                            • Memory management
                            • Mastering bit shifting
                              • Multiplying/dividing by multiples of 2
                              • Packing multiple data items into bytes
                              • Turning on/off individual bits in a control and port register
                            • Reprogramming the Arduino board
                            • Summary
                            • Conclusion
                              • About Packt Publishing
                              • About Packt Open Source
                              • Writing for Packt

                            Julien Bayle

                            Julien Bayle owns his Master Degree of biology & computer sciences in 2000. After several years in pure IT System Design, he founded Design the Media early 2010 in order to provide his own courses, training & tools for art fields. As a digital artist, he designed some huge new media art installations, like the permanent exhibition of La Maison des Cinématographies de la Méditerranée (Château de la Buzine) in Marseille, France, in 2011. He also works as a new media technology consultant for some private & public entities. As an A/V live performer, he plays his cold electronic music from New York to Marseille, where he actually lives. Arduino framework is one of his first electronic hardware studies early 2005 and he designed the famous protodeck controller with some opensource framework too. As an art & technology teacher, also certified by Ableton in 2010, he teaches a lot of courses about the digital audio workstation named Ableton Live, about the real-time graphical programming framework Max6 and also about Processing and Arduino.

                            As a minimalist digital artist, he works at the crossroads of sound, visual and data. He explores relationships between sounds and visuals through his immersive A/V installations, his live performances and his released music. His work, often described as “complex, intrigating and relevant”, tries to break classical codes to bring audience a new vision of our world through his pure digital and real-time generated stimuli.

                            He's deeply involved in the open source community and loves to share and provide workshops and masterclasses online and on-site too. His personal website is http://julienbayle.net.

                            Sorry, we don't have any reviews for this title yet.

                            Code Downloads

                            Download the code and support files for this book.

                            Submit Errata

                            Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

                            Sample chapters

                            You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                            Frequently bought together

                            C Programming for Arduino +    Autodesk AutoCAD 2013 Practical 3D Drafting and Design =
                            50% Off
                            the second eBook
                            Price for both: £27.35

                            Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                            What you will learn from this book

                            • Understand what an Arduino board is
                            • Sense the world through a variety of digital inputs
                            • Feel the world with analog sensors
                            • Design a visual output feedback system
                            • Use Max6 and Processing with Arduino
                            • Connect your Arduino to wired and wireless networks
                            • Add GPS localisation modules to your Arduino

                            In Detail

                            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.


                            Written as a practical Packt book brimming with engaging examples, C Programming for Arduino will help those new to the amazing open source electronic platform so that they can start developing some great projects from the very start.

                            Who this book is for

                            This book is great for people who want to learn how to design & build their own electronic devices. From interaction design art school students to the do-it-yourself hobbyist, or even simply people who want to learn electronics, this book will help by adding a new way to design autonomous but connected devices.

                            Code Download and Errata
                            Packt Anytime, Anywhere
                            Register Books
                            Print Upgrades
                            eBook Downloads
                            Video Support
                            Contact Us
                            Awards Voting Nominations Previous Winners
                            Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                            Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software