Вы находитесь на странице: 1из 8

instructables

1602/2004 Scroll Single LCD Line

by R Jordan Kreindler

The Liquid Crystal Library has two useful functions (line to display text on, string to be scrolled). These
sc ro ll D ispla y Le ft () and sc ro ll D ispla y R igh t () . two functions which scroll lines into the LCD screen
These functions scroll the whole display. That is, they combined with the two functions, sc ro ll Lin e R igh t
scroll both lines on a 1602 LCD and all four lines on a (lin e t o d ispla y t e xt o n , st rin g t o b e
2004 LCD. What we often need is the ability to scroll a sc ro lle d ) and sc ro ll Lin e Le ft (lin e t o d ispla y
single line onto these displays rather than scroll the t e xt o n , st rin g t o b e sc ro lle d ) from my earlier
entire display. Instructable, which presented functions to scroll lines
o the screen, gives us several powerful ways to
This Instructable provides two additional functions, control how text can be presented on, or removed
sc ro ll In Fro mR igh t (lin e t o d ispla y t e xt o n , from, an LCD screen.
st rin g t o b e sc ro lle d ) and sc ro ll In Fro mLe ft

https://youtu.be/bIGZmTozqM8

Step 1: What's Needed

1602/2004 Scroll Single LCD Line: Page 1


- A 1602 or 2004 LCD standalone display, or LCD shield to scroll from the right by changing the lc d . b e gin ()
function to re ect that you are now using a 20
-- See note below regarding use of a 2004 LCD display character x 4 line display. [To scroll in from the left
using a 2004 display, a code rewrite of the function
- An Arduino UNO R3 or clone s c ro ll In Fro mLe ft () is necessary]. In addition to an
LCD you will need an Arduino UNO or clone, the
- A USB cable to connect the Arduino to a computer Arduino IDE, and a USB cable to connect the Arduino
to a computer.
- A half-size, 400 tie points, breadboard
An LCD shield can be used instead of the standalone
- The Arduino IDE LCD shown here. If that is the case, then the pin
assignments for the LCD in the sketch below will need
- An experimental platform (optional, but helpful) to be changed.

The items required are an LCD screen either 1602 or - For the independent 1602 LCD display I used the
2004 [if a 2004 is used, it will work without problems following pin assignments in my sketches:

// Liquid Cryst a l (rs, e n a b le , d 4, d 5, d 6, d 7) display was used in this Instructable, but as noted a
1602 shield can be used as well if the di erent pin
Liquid Cryst a l lc d (12, 11, 5, 4, 3, 2); assignments are taken into account.

and included the Liquid Crystal library I used an “experimental platform” to connect the
LiquidCrystal.h. Arduino UNO to a half-size, 400 tie points ,
breadboard. (See an earlier Instructable of mine,
- For the LCD shield, I use the following pin “Expe rime n t a l Pla t fo rm Fo r t h e A rd uin o UN O
assignments in my sketches, and also included the R3, Ho w To Pre pa re I t Fo r Use “). However, an
Liquid Crystal library LiquidCrystal.h. experimental platform is not needed, although for me
it makes connecting the LCD to the UNO much easier
// Liquid Cryst a l (rs, e n a b le , d 4, d 5, d 6, d 7) and quicker.

Liquid Cryst a l lc d (8 , 13, 9, 4, 5, 6, 7); The assignments I used for connecting the LCD to the
UNO can be seen above.
Either route will run the code here, i.e., either a LCD
shield or a standalone LCD. A 1602 standalone LCD

1602/2004 Scroll Single LCD Line: Page 2


Step 2: Hookup

The LCD is plugged into a breadboard and then knob, rather than a shield’s potentiometer which must
hookup wires are connected from the breadboard to be adjusted with a screwdriver.
the appropriate pins on the Arduino (see step 2 if you
have any questions on the connections I used). The standalone LCD requires the use of a separate 10k
ohm potentiometer. As noted above, I used one with a
I preferred a standalone LCD for this project rather knob which has its wiper connected to the third LCD
than a shield as it was more satisfying for me, and pin (counting from the right with the LCD pins facing
allowed me to easily see which pins were available. It you). The potentiometer is used to control the LCD’s
also allows me to use a potentiometer which has a contrast. The connections are the same for the 1602

and the 2004. However, the statement A look at the photographs attached shows the
lc d . b e gin (16, 2) needs to be changed in the sketch hookup I used, including the experimental platform,
to lc d . b e gin (20 , 4) to show that our LCD has and 10k potentiometer.
changed from a 16 character by two line display to a
20 character by four line one.

1602/2004 Scroll Single LCD Line: Page 3


Step 3: The Sketch

Just enter the attached sketch into the Arduino IDE. // Liquid Cryst a l (rs, e n a b le , d 4, d 5, d 6, d 7)
Please keep in mind that the Instructable site often
removes all greater than and less than signs and the Liquid Cryst a l lc d (12, 11, 5, 4, 3, 2);
text between them. Thus, be sure and include the
text, #include LiquidCrystal.h and enclose the words // D e c la re lc d a s a Liquid Cryst a l O b je c t
LiquidCrystal.h inside greater than and less than
symbols. in t i = 0 ;

// Ske t c h t o sc ro ll c h a ra c t e rs o n t o a n L CD in t j = 0 ;
sc re e n
in t k = 0 ;
#in c lud e //S e e n o t e in t e xt a b o ut wh a t is
n e e d e d h e re , i. e . , Liquid Cryst a l. h e n c lo se d in t d e la yTime 2 = 350 ; // D e la y b e t we e n
in sid e sh ift s

// gre a t e r t h a n a n d le ss t h a n symb o ls

// Th is sit e o ft e n re mo ve s gre a t e r t h a n a n d
le ss t h a n symb o ls a n d t h e t e xt b e t we e n vo id sc ro ll In Fro mR igh t (in t lin e , c h a r st r1[])
them {

1602/2004 Scroll Single LCD Line: Page 4


// Written by R. Jordan Kreindler June 2016 }

i = st rle n (st r1); }

fo r ( j = 16; j >= 0 ; j--) {

lc d . se t Curso r(0 , lin e );


vo id se t up() {
fo r (k = 0 ; k <= 15; k ++) {
S e ria l. b e gin (960 0 );
lc d . prin t (" " ); // Cle a r lin e
S e ria l. prin t ln (" St a r t in g t e st . . ." );
}
lc d . b e gin (16, 2);
lc d . se t Curso r( j, lin e );
lc d . c le a r();
lc d . prin t (st r1);
lc d . prin t (" Te st O n ly" );
d e la y(d e la yTime 2);
}
}
vo id lo o p() {
}
lc d . c le a r();

sc ro ll In Fro mR igh t (0 , " Lin e 1 Fro m R igh t " );

vo id sc ro ll In Fro mLe ft (in t lin e , c h a r st r1[]) { sc ro ll In Fro mR igh t (1, " Lin e 2 Fro m R igh t " );

// Writ t e n b y R. Jo rd a n Kre in d le r Jun e 20 16 lc d . c le a r();

i = 40 - st rle n (st r1); sc ro ll In Fro mLe ft (0 , " Lin e 1 Fro m Le ft ." );

lin e = lin e - 1; sc ro ll In Fro mLe ft (1, " Lin e 2 Fro m Le ft ." );

fo r ( j = i; j <= i + 16; j++) { lc d . c le a r();

fo r (k = 0 ; k <= 15; k ++) { sc ro ll In Fro mR igh t (0 , " Lin e 1 Fro m R igh t " );

lc d . prin t (" " ); // Cle a r lin e sc ro ll In Fro mLe ft (1, " Lin e 2 Fro m Le ft ." );

} lc d . c le a r();

lc d . se t Curso r( j, lin e ); }

lc d . prin t (st r1); The two functions: sc ro ll In Fro mR igh t (lin e t o


d ispla y t e xt o n , st rin g t o b e sc ro lle d ) and
d e la y(d e la yTime 2); sc ro ll In Fro mLe ft (lin e t o d ispla y t e xt o n ,
st rin g t o b e sc ro lle d ) can be moved into your

1602/2004 Scroll Single LCD Line: Page 5


sketch to control the lines that get scrolled onto the This scrolling ability allows us to present lines longer
LCD screen. These functions provide an elegant way that the display is normally capable of showing. That
to move new text to the screen. is, for a 1602 display we are not restricted to only 16
characters per line (although only 16 will show at a
When combined with the two functions in the sketch time), and for a 2004 we are not restricted to 20
contained in the Instructable “S c ro ll a sin gle L CD characters per line.
lin e o ut t o le ft o r righ t , Ho w t o ” the four
functions provide elegant ways to scroll text onto and As an aside, you may want to adjust the display time
o an LCD display. These functions allow you to scroll between scrolls to match your needs.
text one line at a time, and do not require that the
whole display be scrolled as do the functions,
sc ro ll D ispla y Le ft () and sc ro ll D ispla y R igh t () .

Step 4: Afterwards

That's all there is to it. These functions and the two If you would like to contact me with any questions or
from my previous Instructable can be added to any for additional information, or to expand my
sketch you have that uses an LCD and displays text. As knowledge in the area presented, I can be reached at
noted, the ability to use longer lines is a de nite transiintbox@gmail.com. (please replace the second 'i'
bene t that is possible through the use of scrolling. with an 'e' to contact me.

I just want to appear on the LCD2004, "Hello World", with this bit of code,

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);


void setup()

lcd.begin();
lcd.backlight();

lcd.print("Hello, world!");

1602/2004 Scroll Single LCD Line: Page 6


}

void loop()

}
I had time to think about your problem. Have you run a check on the address of your I2C? Perhaps
it is not 0x27 as you suspect,

Just a thought.

Again, the very best.


See my earlier message.

If a differrent library and LCD does not correct the problem, feel free to write again.
I have also used this code, but nothing appears on the screen.

/*
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
*/
// include the library code:
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"

// Connect via i2c, default address #0 (A0-A2 not jumpered)


Adafruit_LiquidCrystal lcd(0);

void setup()
{
// set up the LCD's number of rows and columns:
lcd.begin(20, 4);

// Print a message to the LCD.


lcd.print("hello, world!");
}

void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);

// print the number of seconds since reset:


lcd.print(millis()/1000);
lcd.setBacklight(HIGH);
delay(500);
1602/2004 Scroll Single LCD Line: Page 7
lcd.setBacklight(LOW);
delay(500);
}
Sorry, you are having a problem. I just, today, got notified by Instructable of your comment.

May I gently suggest you try another LCD library.

I have not used the AdaFruit LCD, so can offer no experience/help in that area.

The very best.


Even though you tried other libraries, it does sound as if the LCD libraries you have used just do
not work. So, I might suggest you try an LCD library you have not previously used.
Hello!
I am trying to use an LCD2004 I2C, with these libraries
"Wire.h"
"LiquidCrystal_I2C.h", LiquidCrystal.h, LCD.h, and others, there is no possible way that messages
appear on the screen, I have tried many libraries, I have tried many codes, I have seen and videos,
dog is not possible. I have tried many codes, including this one, I have seen and videos, the dog is
not possible. I would appreciate your help to solve it.

See my earlier message.

And what if you have text longer than 16 symbols, that will just stop at the first position.

The 1602 display buffers text beyond the visible 16 characters displayed on the screen, although
not initially presented on the display. That is, there are character positions (buffers) available past
those displayed that can be written to and read from.
Hey just tried editing your code to allow a longer character message and it doesnt work. It will only
display for the message 16 characters long and everything else gets cut off. how might I fix this?
Nice Instructable! It will be great having the ability to move the display one line at a time.
For learning the 16 pin connector works fine but for projects we like the I2C versions and they only
cost about $2 more. The I2C uses only 2 data pins and makes wiring very easy. Well worth it if
putting the display in a project box.
FYI- For inserting code use the 'code' option under formatting. It is a little quirky to use but you
don't lose any characters. You can see it on our Instructables.
Thank you for your kind comments.
I have not needed to include my displays in project boxes, yet, and find the ability to “plug” LCDs
into a breadboard stabilizes them if the appropriate “support feet” are used. See an earlier
Instructable of mine, “Stabilize and level a 1602 or 2004 breadboard-mounted LCD display, A
simple way to”.
I agree with your thoughts on I2C as it does allow many more pins on an Arduino
to be used when necessary. I also appreciate your comments on posting code. Thanks.
The very best.

1602/2004 Scroll Single LCD Line: Page 8