AVR Workshop

Book description

AVR Workshop is a comprehensive introduction to working with the Microchip AVR 8-bit family of microcontrollers – made famous through their use in Arduino and other compatible boards. Whether you’re an absolute beginner or longtime electronics enthusiast, this book gives you the latest coding and hardware knowledge required to build 60 projects.

Rather than relying on libraries that hide operations under the hood, AVR Workshop teaches the basic C programming skills you need to work directly with ATmega328P-PU and ATtiny85 microcontrollers. You’ll get your operation up and running, then go from blinking LEDs and handling various types of user input to creating real-time clocks and digital thermometers, and even controlling small motorized devices. Once you understand the basic properties of electricity and electronic components, you’ll learn how to:

•Detect input signals from external devices and put them to work
•Work with popular parts like LCDs, motors, servos, and interfacing chips
•Implement the SPI and I²C buses with AVR microcontrollers
•Send serial data between AVR and a computer with USART
•Use hardware interrupts, AVR timers, Pulse-Width Modulation, and EEPROM
•Write your own AVR libraries

Whether your aim is hobbyist tinkering or full product development, AVR Workshop will give you the skills to harness a wide variety of devices, sensors, motors, displays, and more with your AVR microcontroller and bring your own ideas to life.

Table of contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. About the Author
  6. Brief Contents
  7. Contents in Detail
  8. Acknowledgments
  9. Introduction
  10. 1: Getting Started
    1. The Possibilities Are Endless
    2. The Microchip AVR Microcontrollers
    3. Required Parts and Accessories
      1. Electronic Components
      2. Choosing an AVR Programmer
    4. Required Software
      1. macOS 10.6 or Later
      2. Ubuntu Linux 20.04 LTS or Later
      3. Windows 7 Through 11
    5. Current, Voltage, and Power
    6. Electronic Components
      1. Resistors
      2. Light-Emitting Diodes
      3. Power Diodes
      4. Capacitors
      5. Integrated Circuits
      6. Solderless Breadboards
      7. Powering Your Projects
  11. 2: First Steps
    1. Testing the Hardware and Toolchain
      1. Build the Circuit
      2. Connect and Run the Programmer
      3. What If It Didn’t Work?
        1. Project 0: Blinking an LED
      4. Uploading Your First AVR Code
      5. What If It Didn’t Work?
    2. Controlling Digital Outputs
      1. Hardware Registers
        1. Project 1: Experimenting with ATtiny85 Digital Outputs
      2. The Hardware
      3. The Code
    3. Using Schematic Diagrams
      1. Components in Schematics
      2. Wires in Schematics
      3. Dissecting a Schematic
        1. Project 2: Experimenting with ATmega328P-PU Digital Outputs
      4. The Hardware
      5. The Code
        1. Project 3: Bit-Shifting Digital Outputs
        2. Project 4: Experimenting with NOT
        3. Project 5: Experimenting with AND
        4. Project 6: Experimenting with OR
        5. Project 7: Experimenting with XOR
  12. 3: Getting and Displaying Input
    1. Digital Inputs
      1. Introducing the Pushbutton
      2. Reading the Status of Digital Input Pins
        1. Project 8: Blinking an LED on Command
      3. The Hardware
      4. The Code
    2. Making Decisions in Code
      1. if Statements
      2. if . . . else Statements
      3. Making Two or More Comparisons
      4. switch . . . case Statements
    3. Creating Your Own Functions
      1. Project 9: A Simple Custom Function
      2. Project 10: Custom Functions with Internal Variables
      3. Project 11: Custom Functions That Return Values
    4. Switch Bounce
    5. Protecting Your AVR from Fluctuating Voltages
      1. Pullup Resistors
      2. Pulldown Resistors
    6. Introducing Seven-Segment LED Displays
      1. Project 12: Building a Single-Digit Numerical Counter
      2. The Hardware
      3. The Code
    7. Analog Inputs
    8. Using ATtiny85 ADCs
      1. Project 13: Making a Single-Cell Battery Tester
      2. The Hardware
      3. The Code
    9. Using the ATmega328P-PU ADCs
    10. Introducing the Variable Resistor
      1. Project 14: Experimenting with an ATmega328P-PU ADC
      2. The Hardware
      3. The Code
    11. Doing Arithmetic with an AVR
    12. Using External Power
    13. The TMP36 Temperature Sensor
      1. Project 15: Creating a Digital Thermometer
      2. The Hardware
      3. The Code
  13. 4: Communicating with the Outside World using the USART
    1. Introducing the USART
    2. Hardware and Software for USART Communication
      1. Project 16: Testing the USART
      2. The Hardware
      3. The Code
        1. Project 17: Sending Text with the USART
        2. Project 18: Sending Numbers with the USART
        3. Project 19: Creating a Temperature Data Logger
      4. The Hardware
      5. The Code
        1. Project 20: Receiving Data from Your Computer
        2. Project 21: Building a Four-Function Calculator
  14. 5: Taking Control with Hardware Interrupts
    1. External Interrupts
      1. Setting Up Interrupts in Code
        1. Project 22: Experimenting with Rising Edge Interrupts
      2. The Hardware
      3. The Code
        1. Project 23: Experimenting with Falling Edge Interrupts
      4. The Hardware
      5. The Code
        1. Project 24: Experimenting with Two Interrupts
      6. The Hardware
      7. The Code
    2. Pin-Change Interrupts
      1. Project 25: Experimenting with Pin-Change Interrupts
      2. The Hardware
      3. The Code
        1. Project 26: Creating an Up/Down Counter Using Interrupts
      4. The Hardware
      5. The Code
    3. Final Notes on Interrupts
  15. 6: Using Hardware Timers
    1. Introducing Timers
      1. Project 27: Experimenting with Timer Overflow and Interrupts
      2. The Hardware
      3. The Code
        1. Project 28: Using a CTC Timer for Repetitive Actions
        2. Project 29: Using CTC Timers for Repetitive Actions with Longer Delays
    2. Examining the Accuracy of the Internal Timer
    3. Addressing Registers with Bitwise Operations
      1. Addressing Individual Bits in a Register
      2. Addressing Multiple Bits in a Register
        1. Project 30: Experimenting with Overflow Timers Using Bitwise Operations
  16. 7: Using Pulse-Width Modulation
    1. Pulse-Width Modulation and Duty Cycles
      1. Project 31: Demonstrating PWM with the ATtiny85
      2. The Hardware
      3. The Code
    2. Individual PWM Pin Control for the ATtiny85
      1. Project 32: Experimenting with Piezo and PWM
      2. The Hardware
      3. The Code
    3. Individual PWM Pin Control for the ATmega328P-PU
    4. The RGB LED
      1. Project 33: Experimenting with RGB LEDs and PWM
      2. The Hardware
  17. 8: Controlling Motors with Mosfets
    1. The MOSFET
      1. Project 34: DC Motor Control with PWM and MOSFET
      2. The Hardware
      3. The Code
        1. Project 35: Temperature-Controlled Fan
      4. The Hardware
      5. The Code
    2. The L293D Motor Driver IC
      1. Project 36: DC Motor Control with L293D
      2. The Hardware
      3. The Code
        1. Project 37: Controlling a Two-Wheel-Drive Robot Vehicle
      4. The Hardware
      5. The Code
  18. 9: Using the Internal EEPROM
    1. Storing Bytes in EEPROM
      1. Project 38: Experimenting with the ATtiny85’s EEPROM
    2. Storing Words
      1. Project 39: A Simple EEPROM Datalogger
      2. The Hardware
      3. The Code
    3. Storing Floating-Point Variables
      1. Project 40: Temperature Logger with EEPROM
      2. The Hardware
  19. 10: Writing Your Own AVR Libraries
    1. Creating Your First Library
      1. Anatomy of a Library
      2. Installing the Library
        1. Project 41: Your First Library
    2. Creating a Library That Accepts Values to Perform a Function
      1. Project 42: Using the blinko2.c Library
    3. Creating a Library That Processes Data and Returns Values
      1. Project 43: Creating a Digital Thermometer with the thermometer.c Library
  20. 11: AVR and the SPI Bus
    1. How Buses Work
      1. Pin Connections and Voltages
      2. Implementing the SPI Bus
      3. Sending Data
        1. Project 44: Using the 74HC595 Shift Register
      4. The Hardware
      5. The Code
        1. Project 45: Using Two 74HC595 Shift Registers
      6. The Hardware
      7. The Code
        1. Project 46: Using the MAX7219 LED Driver IC
      8. The Hardware
      9. The Code
        1. Project 47: Adding a Reset Button
    2. Multiple SPI Devices on the Same Bus
    3. Receiving Data from the SPI Bus
      1. Project 48: Using the MCP3008 ADC IC
      2. The Hardware
      3. The Code
  21. 12: AVR and the I2C Bus
    1. Increasing AVR Speed
    2. Introducing the I2C Bus
      1. Pin Connections and Voltages
      2. Writing to I2C Devices
        1. Project 49: Using the MCP23017 16-Bit I/O Expander
      3. The Hardware
      4. The Code
    3. Reading Data from I2C Devices
      1. Project 50: Using an External IC EEPROM
      2. The Hardware
      3. The Code
        1. Project 51: Using the DS3231 Real-Time Clock
      4. The Hardware
      5. The Code
  22. 13: AVR and Character Liquid Crystal Displays
    1. Introducing LCDs
      1. Send Commands to the LCD
      2. Initialize the LCD for Use
      3. Clear the LCD
      4. Set the Cursor
      5. Print to the LCD
        1. Project 52: Using a Character LCD with Your AVR
      6. The Hardware
      7. The Code
        1. Project 53: Building an AVR-Based LCD Digital Clock
      8. The Hardware
      9. The Code
    2. Displaying Floating-Point Numbers on the LCD
      1. Project 54: LCD Digital Thermometer with Min/Max Display
      2. The Hardware
      3. The Code
    3. Displaying Custom Characters on the LCD
      1. Write Data to CGRAM
      2. Send Custom Character Data to LCD
      3. Display Custom Characters on LCD
        1. Project 55: Displaying Custom LCD Characters
  23. 14: Controlling Servos
    1. Setting Up Your Servo
      1. Connecting a Servo
      2. Controlling a Servo
        1. Project 56: Experimenting with Servos
      3. The Hardware
      4. The Code
        1. Project 57: Creating an Analog Thermometer
      5. The Hardware
      6. The Code
        1. Project 58: Controlling Two Servos
      7. The Hardware
      8. The Code
        1. Project 59: Building an Analog Clock with Servo Hands
      9. The Hardware
      10. The Code
  24. Epilogue
  25. Index

Product information

  • Title: AVR Workshop
  • Author(s): John Boxall
  • Release date: October 2022
  • Publisher(s): No Starch Press
  • ISBN: 9781718502581