Scroll Single LCD Line

41,279

63

18

Introduction: Scroll Single LCD Line

The Liquid Crystal Library has two useful functions scrollDisplayLeft() and scrollDisplayRight(). These functions scroll the whole display. That is, they scroll both lines on a 1602 LCD and all four lines on a 2004 LCD. What we often need is the ability to scroll a single line onto these displays rather than scroll the entire display.

This Instructable provides two additional functions, scrollInFromRight (line to display text on, string to be scrolled) and scrollInFromLeft (line to display text on, string to be scrolled). These two functions which scroll lines into the LCD screen combined with the two functions, scrollLineRight (line to display text on, string to be scrolled) and scrollLineLeft (line to display text on, string to be scrolled) from my earlier Instructable, which presented functions to scroll lines off the screen, gives us several powerful ways to control how text can be presented on, or removed from, an LCD screen.

Step 1: What's Needed

- A 1602 or 2004 LCD standalone display, or LCD shield

-- See note below regarding use of a 2004 LCD display

- An Arduino UNO R3 or clone

- A USB cable to connect the Arduino to a computer

- A half-size, 400 tie points, breadboard

- The Arduino IDE

- An experimental platform (optional, but helpful)

The items required are an LCD screen either 1602 or 2004 [if a 2004 is used, it will work without problems to scroll from the right by changing the lcd.begin() function to reflect that you are now using a 20 character x 4 line display. [To scroll in from the left using a 2004 display, a code rewrite of the function scrollInFromLeft() is necessary]. In addition to an LCD you will need an Arduino UNO or clone, the Arduino IDE, and a USB cable to connect the Arduino to a computer.

An LCD shield can be used instead of the standalone LCD shown here. If that is the case, then the pin assignments for the LCD in the sketch below will need to be changed.

- For the independent 1602 LCD display I used the following pin assignments in my sketches:

// LiquidCrystal (rs, enable, d4, d5, d6, d7)

LiquidCrystal lcd(12,11,5,4,3,2);

and included the Liquid Crystal library LiquidCrystal.h.

- For the LCD shield, I use the following pin assignments in my sketches, and also included the Liquid Crystal library LiquidCrystal.h.

// LiquidCrystal (rs, enable, d4, d5, d6, d7)

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

Either route will run the code here, i.e., either a LCD shield or a standalone LCD. A 1602 standalone LCD display was used in this Instructable, but as noted a 1602 shield can be used as well if the different pin assignments are taken into account.

I used an “experimental platform” to connect the Arduino UNO to a half-size, 400 tie points , breadboard. (See an earlier Instructable of mine, “Experimental Platform For the Arduino UNO R3, How To Prepare It For Use “). However, an experimental platform is not needed, although for me it makes connecting the LCD to the UNO much easier and quicker.

The assignments I used for connecting the LCD to the UNO can be seen above.

Step 2: Hookup

The LCD is plugged into a breadboard and then hookup wires are connected from the breadboard to the appropriate pins on the Arduino (see step 2 if you have any questions on the connections I used).

I preferred a standalone LCD for this project rather than a shield as it was more satisfying for me, and allowed me to easily see which pins were available. It also allows me to use a potentiometer which has a knob, rather than a shield’s potentiometer which must be adjusted with a screwdriver.

The standalone LCD requires the use of a separate 10k ohm potentiometer. As noted above, I used one with a knob which has its wiper connected to the third LCD pin (counting from the right with the LCD pins facing you). The potentiometer is used to control the LCD’s contrast. The connections are the same for the 1602 and the 2004. However, the statement lcd.begin(16, 2) needs to be changed in the sketch to lcd.begin(20, 4) to show that our LCD has changed from a 16 character by two line display to a 20 character by four line one.

A look at the photographs attached shows the hookup I used, including the experimental platform, and 10k potentiometer.

Step 3: The Sketch

Just enter the attached sketch into the Arduino IDE. Please keep in mind that the Instructable site often removes all greater than and less than signs and the text between them. Thus, be sure and include the text, #include LiquidCrystal.h and enclose the words LiquidCrystal.h inside greater than and less than symbols.

// Sketch to scroll characters onto an LCD screen

#include //See note in text about what is needed here, i.e., LiquidCrystal.h enclosed inside

// greater thanand less than symbols

// This site often removes greater than and less than symbols and the text between them

// LiquidCrystal (rs, enable, d4, d5, d6, d7)

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Declare lcd as a LiquidCrystal Object

int i = 0;

int j = 0;

int k = 0;

int delayTime2 = 350; // Delay between shifts


void scrollInFromRight (int line, char str1[]) {

// Written by R. Jordan Kreindler June 2016

i = strlen(str1);

for (j = 16; j >= 0; j--) {

lcd.setCursor(0, line);

for (k = 0; k <= 15; k++) {

lcd.print(" "); // Clear line

}

lcd.setCursor(j, line);

lcd.print(str1);

delay(delayTime2);

}

}


void scrollInFromLeft (int line, char str1[]) {

// Written by R. Jordan Kreindler June 2016

i = 40 - strlen(str1);

line = line - 1;

for (j = i; j <= i + 16; j++) {

for (k = 0; k <= 15; k++) {

lcd.print(" "); // Clear line

}

lcd.setCursor(j, line);

lcd.print(str1);

delay(delayTime2);

}

}


void setup() {

Serial.begin(9600);

Serial.println("Starting test ...");

lcd.begin(16, 2);

lcd.clear();

lcd.print("Test Only");

}

void loop() {

lcd.clear();

scrollInFromRight(0, "Line1 From Right");

scrollInFromRight(1, "Line2 From Right");

lcd.clear();

scrollInFromLeft(0, "Line1 From Left.");

scrollInFromLeft(1, "Line2 From Left.");

lcd.clear();

scrollInFromRight(0, "Line1 From Right");

scrollInFromLeft(1, "Line2 From Left.");

lcd.clear();

}

The two functions: scrollInFromRight (line to display text on, string to be scrolled) and scrollInFromLeft (line to display text on, string to be scrolled) can be moved into your sketch to control the lines that get scrolled onto the LCD screen. These functions provide an elegant way to move new text to the screen.

When combined with the two functions in the sketch contained in the Instructable “Scroll a single LCD line out to left or right, How to” the four functions provide elegant ways to scroll text onto and off an LCD display. These functions allow you to scroll text one line at a time, and do not require that the whole display be scrolled as do the functions, scrollDisplayLeft() and scrollDisplayRight().

This scrolling ability allows us to present lines longer that the display is normally capable of showing. That is, for a 1602 display we are not restricted to only 16 characters per line (although only 16 will show at a time), and for a 2004 we are not restricted to 20 characters per line.

As an aside, you may want to adjust the display time between scrolls to match your needs.

Step 4: Afterwards

That's all there is to it. These functions and the two from my previous Instructable can be added to any sketch you have that uses an LCD and displays text. As noted, the ability to use longer lines is a definite benefit that is possible through the use of scrolling.

If you would like to contact me with any questions or for additional information, or to expand my knowledge in the area presented, I can be reached at transiintbox@gmail.com. (please replace the second 'i' with an 'e' to contact me.

1 Person Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

18 Discussions

0
Rcastro03
Rcastro03

1 year ago

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!");

}

void loop()

{

}

0
R Jordan Kreindler
R Jordan Kreindler

Reply 1 year ago

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.

0
R Jordan Kreindler
R Jordan Kreindler

Reply 1 year ago

See my earlier message.

If a differrent library and LCD does not correct the problem, feel free to write again.

0
Rcastro03
Rcastro03

1 year ago

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);
lcd.setBacklight(LOW);
delay(500);
}

0
R Jordan Kreindler
R Jordan Kreindler

Reply 1 year ago

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.

0
R Jordan Kreindler
R Jordan Kreindler

Reply 1 year ago

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.

0
Rcastro03
Rcastro03

1 year ago

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.

0
Ramkulov
Ramkulov

3 years ago

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

0
R Jordan Kreindler
R Jordan Kreindler

Reply 3 years ago

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.

0
RjH15
RjH15

Reply 2 years ago

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?

0
1206.sachin
1206.sachin

Question 2 years ago

Where to get first part mentioned in this Instructable ?

0
R Jordan Kreindler
R Jordan Kreindler

Answer 2 years ago

Dear 1206.sachin,

Thank you for the question.

If you are referencing the Experimental Platform you can try AliExpress),

https://www.aliexpress.com/item/Universal-for-Ardu...

This seller has an App for you phone or tablet that makes the price even better if you order thru it.

If you are asking about another item just let me know.

The very best.

0
R Jordan Kreindler
R Jordan Kreindler

Question 2 years ago

I believe I understand what you would like to do. I will take a look at what you sent and get back to you.

The very best

0
R Jordan Kreindler
R Jordan Kreindler

Answer 2 years ago

I looked at your code and it appears you do not have anything after the include statement. In my Instructable paper I noted:

#include //See note in text about what is needed here, i.e., LiquidCrystal.h enclosed inside

// greater thanand less than symbols

// This site often removes greater than and less than symbols and the text between them

// LiquidCrystal (rs, enable, d4, d5, d6, d7)

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Declare lcd as a LiquidCrystal Object


Thus, if you replace the include statement you have, you should have no issue. That is, use

#include <LiquidCrystal.h>

instead of the #include you have that includes no text.

The very best, sorry if there was some confusion. However, the Instructable editor appears to remove all text between < and > signs, as well as the "greater than" and "less than" signs themselves.

Jordan

0
toniwidiyanto
toniwidiyanto

Question 2 years ago

Hello, I want place my word in row 1 as scrolling text, and row 2 as fixed text, can you explain how about it?

i use this code, but i wrong.






/*
* MONSTER ARDUINO V2 : BASIC SENSOR
* Program Mengontrol Lampu Backlight LCD
* www.ElangSakti.com
*/

// library LCD dengan modul I2C
#include


// jumlah kolom dan baris LCD (16x2)
#define LCD_COL 16
#define LCD_ROW 2

// ===== Konfigurasi LCD ===========

// LCD1602 dengan Modul I2C
// Alamat I2C di 0x27
// lcd_Addr, EN, RW, RS, D4, D5, D6, D7, PIN_BACKLIGHT, Pol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);



int i = 0;

int j = 0;

int k = 0;

int delayTime2 = 500; // Delay between shifts



void scrollInFromRight (int line, char str1[]) {


i = strlen(str1);

for (j = 40; j >= 16; j--) {

lcd.setCursor(j, line);



lcd.print(str1);; // Clear line
delay(delayTime2);
}



}






void setup() {

// Nyalakan Backlight
lcd.setBacklight(BACKLIGHT_ON);
lcd.begin(16, 2);
Serial.begin(9600);



lcd.clear();



}

void loop() {
{
scrollInFromRight(1, "DAFTAR PENGHUNI KOS KALISEGARA UNNES: ");
}
{

lcd.clear();
lcd.setCursor(0,1);
lcd.print("TONI WIDIYANTO");
delay(1000);
lcd.setCursor(0,1);
lcd.print("JUNANTO ");
delay(1000);
lcd.setCursor(0,1);
lcd.print("ARIS TRIYONO ");
delay(1000);
lcd.setCursor(0,1);
lcd.print("M. TEGUH A. ");
delay(1000);
lcd.setCursor(0,1);
lcd.print("KUSWORO ");
delay(1000);
}
}

0
blic19933
blic19933

4 years ago

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.

0
R Jordan Kreindler
R Jordan Kreindler

Reply 4 years ago

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.