0% found this document useful (0 votes)
4 views27 pages

Unit IV - Programming the Arduino and AVR Microcontrollers

The document provides an overview of programming Arduino and AVR microcontrollers, detailing the process of cross-compiling software on different systems and the role of bootloaders in uploading programs. It introduces the Arduino Uno, its features, and the necessary steps to code using the Arduino IDE, including installation and configuration. Additionally, it outlines the Arduino software build process, emphasizing the importance of functions like setup() and loop() in a sketch.

Uploaded by

Gowthami Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views27 pages

Unit IV - Programming the Arduino and AVR Microcontrollers

The document provides an overview of programming Arduino and AVR microcontrollers, detailing the process of cross-compiling software on different systems and the role of bootloaders in uploading programs. It introduces the Arduino Uno, its features, and the necessary steps to code using the Arduino IDE, including installation and configuration. Additionally, it outlines the Arduino software build process, emphasizing the importance of functions like setup() and loop() in a sketch.

Uploaded by

Gowthami Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Programming the Arduino

and AVR Microcontrollers


Cross-Compiling for Microcontrollers
• For most single-board microcontroller systems, programs for an
Arduino and its AVR MCU are developed on another system of
some type (Windows, Linux, or Mac) and then transferred, or
uploaded, to the AVR microcontroller on the Arduino board.
• The Arduino or other MCU-based device is called the target.
• The development system is referred to as the development host,
and
• The technique of creating software for one type of processor on a
different type of system is referred to as cross-compiling.
Boot loaders
• Getting a program into a modern microcontroller might entail any one of
several different methods, but the easiest is to let the MCU itself assist with
the process. This is
accomplished with a small preloaded bit of firmware called a bootloader.
• The AVR family of microcontrollers provides reserved space in the on-board
flash memory space for a bootloader.
• Once the MCU has been configured to use the bootloader, the address of this
special memory space is the first place the AVR MCU will look for
instructions when it is powered up (or rebooted). So long as the bootloader is
not overwritten with an uploaded program, it will persist in memory between
onoff power cycles.
Introduction to arduino
Arduino

• Basically Arduino is Microcontroller.

• Microcontroller is microprocessor with memory, RAM and some other


peripheral connected with it.

• The Arduino Uno is a microcontroller board based on the ATmega328 .


The ATmega328 has Flash memory of 32 KB (with 0.5 KB used for the
bootloader). It also has 2 KB of SRAM and 1 KB of EEPROM

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 4


Different types of Arduino
Boarduino Kit

Arduino LilyPad
DIY Arduino

Arduino Uno

Arduino Mega 2560

5
Arduino uno
• What does it have?
• 14 Digital In/Out pins (6 can be used as PWM)
• 6 Analog Inputs
• A USB Connection
• A Power Jack
• Reset Button
• On-board LED
• SCL/SDA pins (Serial Clock/ Serial Data pins)
• In short, it contains everything needed to support the microcontroller; simply connect it

to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started.
6
USB
PWR IN
(to Computer)

RESET

SCL\SDA
(I2C Bus)

POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)

Analog
INPUTS

7
How to code in arduino

• You need to download Arduino IDE (Integrated


Development Environment).
• Arduino IDE is available for all Mac, Windows.and
Linux.

8
How to code in arduino

• Once you have downloaded


and installed/extracted the
folder, you can directly run
Arduino.exe, which will
take you to its IDE.
• The IDE will look like the
shown screenshot.

error & status messages

9
Program your arduino

• Before you start


programming, double
check that correct
board is selected
under Tools  Board.
• Now, you can start
playing with Arduino.

10
Program your arduino
• The Arduino Uno can be
programmed with the Arduino
software. Select "Arduino Uno
from the Tools > Board menu
(according to the
microcontroller on your board).
• All the peripheral connected
with Computers are using
Serial Port.
• You can check port for Arduino
Uno in Device Manger.

11
Input vs output

12
6 Major concepts
• digitalWrite()
• analogWrite()
• digitalRead()
• If (statements) / Boolean
• analogRead
• Serial Communication

13
Analog vs digital

•Microcontrollers are digital devices – ON or OFF. Also called –


discrete.

•Analog signals are anything that can be a full range of values.

5V 5V

0V 0V

14
Analog vs digital

•Analog Sensors Digital Sensors


• Digital sensors are more
Sensors Variables straight forward than
Analog.
Mic soundVolume
Photoresistor lightLevel • No matter what the sensor
Potentiometer dialPosition there are only two
Temp Sensor temperature settings: On and Off
Flex Sensor bend
•Example, Push button, Switch
Accelerometer tilt/acceleration

15
Serial communication
• “Serial” because data is broken into bits, each sent one
after another in a single wire.

• Compiling turns your program into binary data (ones and


zeros)

• Uploading sends the bits through USB cable to the Arduino

• The two LEDs near the USB connector blink when data is
transmitted.
• RX blinks when the Arduino is receiving data.
• TX blinks when the Arduino is transmitting data

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 16


Project #1 led blink
• digitalWrite()

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 17


Upload

Compile

Status Message

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 18


The Arduino IDE Environment

The Arduino IDE main screen


Installing the Arduino IDE
• The procedure for installing the Arduino IDE and libraries varies from
extremely easy to very involved, depending on your platform and how much
effort you want to put into it.

• For most people using Linux the easiest approach is to download an


installation package via a package manager and it let it deal with also
installing the necessary support packages.
Configuring the Arduino IDE

• You can tailor the IDE to suit your needs by


• using the Preferences dialog, found under
• File→Preferences on the main menu
• (under “Arduino” on a Mac).

• This dialog allows you to specify the


• sketch directory, specify an external
• editor (if you don’t like the one that
• comes with the IDE), and modify various
• behaviors of the IDE.

IDE Preferences
dialog
The Arduino Executable Image
• Executable Arduino software (the executable image described earlier) typically
consists of three primary components:
• The sketch created by a developer,
• The libraries used to access the various functions of an AVR, and
• the runtime code that contains a main() function and a loop for the application
software to execute within.
• The tools and software components involved in creating executable code for an AVR
microcontroller can be divided into two primary categories:
host development tools and
runtime compilation sources, and
the target-side executable binary code for the AVR microcontroller.
Figure shows a block diagram of the primary Arduino software components, and includes the
user-supplied program (sketch) to show how things fit into a complete executable binary image.
The Arduino Software Build Process

Arduino software
organization
There are five main steps in the Arduino build process when using the IDE:
Source preparation
• The IDE also attempts to create function prototypes for any functions other
than setup() and loop() found in the sketch.
• These are placed at the top of the sketch file, immediately after any
comments or preprocessor statements (#include and #define) but before any
other types of statements.
Compilation
• Arduino uses the AVR-GCC compiler suite to translate the source code into

binary files called object files. These are not immediately executable, but

must be processed by the tool called the linker before the Arduino hardware

can deal with them (refer to the next step).


• The AVR-GCC compiler is a form of the base GCC compiler built specifically
Linking
• Linking is the process of connecting object files and library modules. The basic idea is to
fill in the “holes” in the object files where the original source code referred to a data
object or function in an external library or object, but the compiler couldn’t resolve the
address at the time the code was compiled.
• The linker’s job is to locate the missing references and write them into a final executable
binary file, along with the binary code for the referenced data or functions.
Conversion
• The binary file created by the linker must be converted to what is called Intel hex format,
which is what the bootloader firmware on the AVR device expects.
• The utility avr-objcopy can be used to do this.
• Uploading
• The final step involves transferring the completed executable binary file to the Arduino
hardware.
• This is accomplished using a USB link (usually) and the bootloader firmware in the
microcontroller, along with a utility called AVRDUDE
Arduino Software Architecture
• A sketch always consists of at least two required functions:
setup() and loop().
• The setup() function is called once when the sketch starts.
• The loop() function executes continuously until the power is disconnected or
the Arduino board is reset. loop() is called repeatedly by the main() function
that is automatically supplied by the Arduino IDE.
• A sketch may also have additional functions. For example, the sketch for the
thermostat has multiple functions in addition to the mandatory setup() and
loop().
Arduino program
structure

You might also like