Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
66 views

Introduction To Arduino

The document provides an introduction to the Arduino Mega 2560 microcontroller board. It details that the Arduino Mega 2560 has an ATmega2560 microcontroller, 54 digital input/output pins, 16 analog inputs, 256KB of flash memory, 8KB of SRAM, and operates at 16MHz. It also describes the board's power supply, memory, digital and analog pins, communication interfaces like UART, TWI, and SPI, and that it can be programmed via the Arduino IDE.

Uploaded by

osama.20en714
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Introduction To Arduino

The document provides an introduction to the Arduino Mega 2560 microcontroller board. It details that the Arduino Mega 2560 has an ATmega2560 microcontroller, 54 digital input/output pins, 16 analog inputs, 256KB of flash memory, 8KB of SRAM, and operates at 16MHz. It also describes the board's power supply, memory, digital and analog pins, communication interfaces like UART, TWI, and SPI, and that it can be programmed via the Arduino IDE.

Uploaded by

osama.20en714
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Real Time System Laboratory

Department of Computer Engineering


College of Engineering
Mosul University
Introduction to Embedded System
Introduction to Embedded System
Introduction to Embedded System
Introduction to Embedded System
Arduino

Introduction
Introduction to Arduino
• Arduino is a prototype platform (open-source) based
on an easy-to-use hardware and software. It consists of
a circuit board, which can be programed (referred to as
a microcontroller) and a ready-made software called
Arduino IDE (Integrated Development Environment),
which is used to write and upload the computer code
to the physical board.
• Arduino boards are able to read analog or digital input
signals from different sensors and turn it into an output
such as activating a motor, turning LED on/off, connect
to the cloud and many other actions.
Arduino IDE
• The open-source Arduino Software
(IDE) makes it easy to write code and
upload it to the board. It runs on
Windows, Mac OSX, and Linux. You
can control your board functions by
sending a set of instructions to the
microcontroller on the board via
Arduino IDE (referred to as uploading
software). The Arduino IDE uses a
simplified version of C++, making it easier
to learn to program.
Data Types in Arduino
Program Structure in Arduino
Arduino - Board
• Various kinds of Arduino boards are available
depending on different microcontrollers used.
However, all Arduino boards have one thing in
common: they are programed through the Arduino
IDE.
• The differences are based on the number of inputs and
outputs (the number of sensors, LEDs, and buttons you
can use on a single board), speed, operating voltage,
form factor etc. Some boards are designed to be
embedded and have no programming interface
(hardware), which you would need to buy separately.
Some can run directly from a 3.7V battery, others need
at least 5V.
Arduino - Board
Voltage Levels in Arduino
Voltage Levels in Arduino
Arduino - I/O Functions
• Digital Mode in Arduino
• You can set the mode of any Pin by using the
following command:
Syntax:
• pinMode(pin, mode)
Parameters:
• pin: the Pin number whose mode you wish to set
• mode: INPUT or OUTPUT
Arduino - I/O Functions
• Arduino Digital Input
• You can read the status of any Pin by using the following
command:
Syntax:
• Val=digitalRead(pin)
Parameters:
• Val: variable to save the return of the function
• pin: the Pin number you wish to read its status
• Note: the pin should be previously set as INPUT port.
Arduino - I/O Functions
• Arduino Digital Output
• You can set the value (sending logic value) of
any Pin by using the following command:
Syntax:
• digitalWrite(pin, value)
Parameters:
• pin: the Pin number
• value: HIGH or LOW
First Example (Blinking an LED)
Turn the LED (ON) for one second and then turn it (OFF) for tow second connected to
digital pin 2
Operating an LED
Blinking an LED
Program Code
The circuit Assumptions:
- LED attached to pin 2
-1K resistor attached to LED (Negative pin) and then to ground
-Turns a light emitting diode(LED) connected to digital pin 2 (ON) for one
second and then turn it (OFF) for tow second
Arduino - I/O Functions
Arduino Analog Input:
• The Arduino Uno board contains a 6 channel, 10-bit analog to
digital converter. This means that it will map input voltages
between 0 and 5 volts into integer values between 0 and
1023. This yields a resolution between readings of:
5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
Syntax:
• Var=analogRead(pin)
Parameters:
• Var: variable to save the return of the function (int)
• pin: the number of the analog input pin to read from (0 to 5)
• Not: This function returns a number between 0 and 1023,
which represents voltages between 0 and 5 volts.
Arduino - I/O Functions
Producing PWM in Arduino:
• Writing an analog value to a pin can be used to generate
PWM signal. The frequency of the PWM signal on most pins
is approximately 490 Hz. On the Uno and similar boards,
pins 5 and 6 have a frequency of approximately 980 Hz.
Syntax:
• analogWrite(Pin, Value)
Parameters:
• Pin: the pin to write to,
• Value: the duty cycle: between 0 (always off) and 255
(always on).
Arduino - I/O Functions
Mapping Variables:
• Mapsa number from one range to another.
Syntax:
• X= map(value, fromLow, fromHigh, toLow, toHigh)
Parameters:
• X= new remapped value.
• value: the number or variable to map.
• fromLow: the lower bound of the value's current range.
• fromHigh: the upper bound of the value's current range.
• toLow: the lower bound of the value's target range.
• toHigh: the upper bound of the value's target range.
Arduino Mega 2560

Arduino Mega 2560


Summary
• Microcontroller: ATmega2560
• Operating Voltage: 5V
• Input Voltage (recommended): 7-12V
• Digital I/O Pins: 54
– of which 15 provide PWM output
• Analog Input Pins: 16
• Flash Memory: 256 KB
– of which 8 KB used by boot-loader
• SRAM: 8 KB
• EEPROM: 4 KB
• Clock Speed: 16 MHz
Power
• The Arduino Mega can be powered via the USB
connection or with an external power supply.
The power source is selected automatically.
• The power pins are as follows:
– VIN: The input voltage to the Arduino board when it's
using an external power source.
– 5V: This pin outputs a regulated 5V from the regulator
on the board.
– 3V3: A 3.3 volt supply generated by the on-board
regulator.
– GND: Ground pins.
Arduino Mega 2560
Memory

• The ATmega2560 has


– 256 KB of flash memory for storing code (of
which 8 KB is used for the boot-loader)
– 8 KB of SRAM
– 4 KB of EEPROM (which can be read and
written with the EEPROM library).
Digital I/O Pins
• Each of the 54 digital pins on the Mega
can be used as an input or output, using
pinMode(), digitalWrite(), and digitalRead()
functions.
• Some pins have specialized functions:
– Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX)
and 18 (TX); Serial 2: 17 (RX) and 16 (TX);
Serial 3: 15 (RX) and 14 (TX). Used to receive
(RX) and transmit (TX) TTL serial data
Digital I/O Pins
– External Interrupts: 2 (interrupt 0), 3 (interrupt
1), 18 (interrupt 5), 19 (interrupt 4), 20
(interrupt 3), and 21 (interrupt 2). These pins
can be configured to trigger an interrupt on a
low value, a rising or falling edge, or a change
in value. See the attachInterrupt() function for
details.
– PWM: 2 to 13 and 44 to 46. Provide 8-bit
PWM output with the analogWrite() function.
Digital I/O Pins (cont)
– SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53
(SS). These pins support SPI communication
using the SPI library.
– LED: 13. There is a built-in LED connected to
digital pin 13. When the pin is HIGH value, the
LED is on, when the pin is LOW, it's off.
– TWI: 20 (SDA) and 21 (SCL). Support TWI
communication using the Wire library.
Analog Input Pins
• The Mega2560 has 16 analog inputs, each
of which provide 10 bits of resolution (i.e.
1024 different values).
• By default they measure from ground to 5
volts, though is it possible to change the
upper end of their range using the AREF
pin and analog Reference () function.
Mega 256 Pin Descriptions
Communication
• The ATmega2560 provides four hardware
UARTs for TTL (5V) serial communication.
• An ATmega16U2 on the board channels
RX0/TX0 over USB and provides a virtual
com port to software on the computer.
• The Arduino software includes a serial
monitor which allows simple textual data to
be sent to and from the board.
Communication (cont)
• The ATmega2560 also supports TWI and
SPI communication. The Arduino software
includes a Wire library to simplify use of
the TWI bus. For SPI communication, use
the SPI library.
Programming
• The Arduino Mega can be programmed
with the Arduino software.
• The ATmega2560 on the Arduino Mega
comes pre-burned with a boot-loader that
allows you to upload new code to it without
the use of an external hardware
programmer.
• Automatic (software) reset after uploading.
THANK YOU ANY QUESTION

You might also like