Beruflich Dokumente
Kultur Dokumente
Arduino
Introduction
Arduino is an open-source platform used for building electronics projects. It
consists of a microcontroller and a piece of software i.e. Integrated
Development Environment (IDE) that runs on your computer. This code is
used to write and upload computer code to the microcontroller.
Why Arduino:-
It is very flexible to be customized and extended and it is an open-
source project, software/hardware which is extremely accessible.
It offers a variety of digital and analog inputs, SPI and serial interface
and digital and PWM outputs
It is easy to use, communicates using standard serial protocol, that
connects to computer via USB and runs in standalone mode and as
interface connected to PC.
Aurdino IDE:-
One of the most important component of the Arduino platform is
the Arduino IDE. This contains all the software which will run a computer in
order to program and communicate with an Arduino board.
There is an editor in Arduino IDE which we can use to write Arduino programs
/sketches in a simple programming .
Arduino Types
Arduino Uno (R3)
14 digital input/output pins (of which 6 can be used as PWM outputs)
6 analog inputs
a USB connection
a reset button
a power jack
This USB connection can also be used to upload code into the
microcontroller.
Do NOT use a power supply greater than 20 Volts ,for most aurdinos the
recommended voltage is between 6 and 12 Volts.
The pins on Arduino are the places where we connect wires to construct a
circuit. They usually have black plastic headers through which we can plug a
wire right into the board. The Arduino has several different kinds of pins.
Each of pin is labeled on the board and each pin is used for different
functions.
Ground: There are several ground pins on the Arduino, any of which can be
used to ground your circuit. These pins are labeled (3) in the above figure.
5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power,
and the 3.3V pin supplies 3.3 volts of power. Most of the simple components
used with the Arduino run happily off of 5 or 3.3 volts.
Analog Pins: The labels (A0 through A5 on the UNO) are Analog In pins.
These pins can read the signal from an analog sensor and convert it into a
digital value. These pins are labeled (6) in the above figure.
Digital Pins: On the board other than analog pins we have the digital pins (0
through 13). These pins can be used for both digital input and digital output.
These pins are labeled (7) in the above figure.
Pulse Width Modulation: Next to some of the digital pins, some pins are
with tilde (~) sign. These pins include 3, 5, 6, 9, 10, and 11 on the UNO.
These pins act as normal digital pins, but can also be used for something
called Pulse-Width Modulation (PWM).These pins as being able to simulate
analog output. These pins are labeled (8) in the above figure.
Reset Button: There is a reset button in Arduino. Labeled (10) in the above
figure. By pushing it, connect the both reset pin and ground pin and restart
the code which we had loaded on the Arduino. If we want to test our code
multiple times and if our code doesnt repeat itself this can be very useful.
Power LED Indicator: There is a LED on the board labeled as ON
and (11). When we powered our Arduino, this LED lightens up. If this LED
does not glow, there is something wrong. We have to re-check our circuit.
Main IC: There is a black IC with all the metal legs labeled as (13) in the
above figure. This IC act as the brain of Arduino. This IC on the Arduino is
little bit different from board type. Before loading a new program from the
IDE, this is important to know the IC type. This information is written on the
top side of the IC.
Technical Specifications
Microcontroller ATmega328
Operating Voltage 5V
EEPROM 1 KB
Mega Leonardo
Digital I/O 14 54 54 20
3Features
Low cost, long-term stability, relative humidity and temperature measurement, excellent
quality, fast response, strong anti-interference ability, long distance signal transmission, digital
signal output, and precise calibration.
LCD INTERFACING
3.1 Introduction:
The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580. In this tutorial, we will
discuss about character based LCDs, their interfacing with various microcontrollers,
various interfaces (8-bit/4-bit), programming, special stuff and tricks you can do
with these simple looking LCDs which can give a new look to your application .
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4
Line LCDs which have only 1 controller and support at most of 80 characters,
whereas LCDs supporting more than 80 characters make use of 2 HD44780
controllers.
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two
pins are extra in both for back-light LED connections). Pin description is shown in
the table below.
25
Pin No. Name Description
0 = Instruction input
Pin no. 4 RS
1 = Data input
0 = Write to LCD
module
Pin no. 5 R/W
1 = Read from LCD
module
Pin no.
D3 Data bus line 3
10
Pin no.
D4 Data bus line 4
11
Pin no.
D5 Data bus line 5
12
Pin no.
D6 Data bus line 6
13
Pin no.
D7 Data bus line 7 (MSB)
14
TABLE 3.2.A: PIN DISCRIPTION OF LCD
26
Display data RAM (DDRAM) stores display data represented in 8-bit character codes.
Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM
(DDRAM) that is not used for display can be used as general data RAM. So whatever
you send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, only
16 characters are visible, so whatever you write after 16 chars is written in DDRAM
Now you might be thinking that when you send an ASCII value to DDRAM, how the
character is displayed on LCD? So the answer is CGROM. The character generator
ROM generates 5 x 8 dot or 5 x 10 dot character patterns from 8-bit character codes
(see Figure 5 and Figure 6 for more details). It can generate 208 5 x 8 dot character
patterns and 32 5 x 10 dot character patterns. User defined character patterns are
also available by mask-programmed ROM.As you can see in both the code maps,
the character code from 0x00 to 0x07 is occupied by the CGRAM characters or the
user defined characters. If user wants to display the fourth custom character then
the code to display it is 0x03 i.e. when user sends 0x03 code to the LCD DDRAM
then the fourth user created character or pattern will be displayed on the LCD.
As clear from the name, CGRAM area is used to create custom characters in LCD. In
the character generator RAM, the user can rewrite character patterns by program.
For 5 x 8 dots, eight character patterns can be written, and for 5 x 10 dots, four
character patterns can be written.
BF - Busy Flag:
Busy Flag is a status indicator flag for LCD. When we send a command or data to
the LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is
executed
27
successfully this flag is cleared (BF = 0). This is helpful in producing and exact
amount of delay for the LCD processing.To read Busy Flag, the condition RS = 0 and
R/W = 1 must be met and The MSB of the LCD data bus (D7) act as busy flag. When
BF = 1 means LCD is busy and will not accept next command or data and BF = 0
means LCD is ready for the next command or data to process.
There are two 8-bit registers in HD44780 controller Instruction and Data register.
Instruction register corresponds to the register where you send commands to LCD
e.g. LCD shift command, LCD clear, LCD address etc. and Data register is used for
storing data which is to be displayed on LCD. When send the enable signal of the
LCD is asserted, the data on the pins is latched in to the data register and data is
then moved automatically to the DDRAM andhenceisdisplayedontheLCD.
Data Register is not only used for sending data to DDRAM but also for CGRAM, the
address where you want to send the data, is decided by the instruction you send to
LCD.
In 4-bit mode the data is sent in nibbles, first we send the higher nibble and then
the lower nibble. To enable the 4-bit mode of LCD, we need to follow special
sequence of initialization that tells the LCD controller that user has selected 4-bit
mode of operation. We call this special sequence as resetting the LCD. Following is
the reset sequence of LCD.
Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)
28
The busy flag will only be valid after the above reset sequence. Usually we do not
use busy flag in 4-bit mode as we have to write code for reading two nibbles from
the LCD. Instead we simply put a certain amount of delay usually 300 to 600uS. This
delay might vary depending on the LCD you are using, as you might have a different
crystal frequency on which LCD controller is running. So it actually depends on the
LCD module you are using. In 4-bit mode, we only need 6 pins to interface an LCD.
D4-D7 are the data pins connection and Enable and Register select are for LCD
control pins. We are not using Read/Write (RW) Pin of the LCD, as we are only
writing on the LCD so we have made it grounded permanently. If you want to use it,
then you may connect it on your controller but that will only increase another pin
and does not make any big difference. Potentiometer RV1 is used to control the LCD
contrast. The unwanted data pins of LCD i.e. D0-D3 are connected to ground.
We will now look into the common steps to send data/command to LCD when
working in 4-bit mode. In 4-bit mode data is sent nibble by nibble, first we send
higher nibble and then lower nibble. This means in both command and data sending
function we need to separate the higher 4-bits and lower 4-bits.The common steps
are: