Scrolling Text on 16×2 LCD using MSP430 Microcontroller and Energia

This scrolling text on LCD using MSP430 microcontroller tutorial shows you how to animate text left and right on a 16×2 HD44780 LCD connected to the MSP430G2 LaunchPad. You have probably seen scrolling messages on store signs, airport displays, and seven-segment marquees — the same basic idea applies to any character LCD. By calling two built-in Energia functions, lcd.scrollDisplayRight() and lcd.scrollDisplayLeft(), you can move a text string one position at a time in either direction, and loop the calls to create a smooth scrolling animation.

Scrolling text on 16x2 LCD using MSP430 microcontroller and Energia IDE

Scrolling text is a great way to display messages that are longer than the LCD’s 16-character width, to draw the user’s attention to a status change, or simply to add polish to an otherwise static display. In this guide we build a complete scrolling demo on the MSP430G2 LaunchPad — print a two-line message, scroll it right a few positions, then scroll it back left, and repeat forever.

Before continuing, if you have not wired up an LCD to the MSP430 before, work through the prerequisite tutorial first — it covers pinout, 4-bit mode, contrast wiring, and the basic LiquidCrystal library, which we build on directly here:

What You Will Learn

  • How text scrolling works internally on an HD44780 LCD (DDRAM shift, not character redraw)
  • The two Energia functions that drive scrolling: scrollDisplayRight() and scrollDisplayLeft()
  • How to use for loops to chain multiple scroll steps together for smooth animation
  • How scroll speed is controlled by the delay() between scroll calls
  • A complete working example that scrolls a two-line message right and left
  • How to scroll only one line while keeping the other static (advanced pattern)
  • How to handle text longer than 16 characters using the hidden DDRAM buffer
  • Troubleshooting common scrolling issues: flicker, both lines shifting, wrong direction

Prerequisites and Required Components

  • MSP430G2 LaunchPad (MSP430G2553)
  • 16×2 character LCD (HD44780 controller)
  • 10 kΩ potentiometer for contrast adjustment
  • Breadboard and jumper wires
  • Energia IDE with the LiquidCrystal library (built in)
  • Completed wiring from the LCD interfacing tutorial — the circuit for scrolling is identical

LCD Connection with MSP430 Microcontroller (Same as Previous Tutorial)

The wiring for this scrolling demo is exactly the same as the previous LCD interfacing tutorial. You do not need to change any connections — just re-upload the new sketch. For reference, the circuit diagram is reproduced below.

Circuit diagram for 16x2 LCD interfacing with MSP430 LaunchPad used for scrolling text tutorial

Pin summary (4-bit mode):

  • LCD RS → LaunchPad header pin 2
  • LCD EN → LaunchPad header pin 3
  • LCD D4–D7 → LaunchPad header pins 4–7
  • LCD R/WGND (write-only)
  • LCD VSS, LED−GND
  • LCD VDD, LED+TP1 (5 V) (LED+ through a 220 Ω resistor)
  • LCD V0 (contrast) → wiper of 10 kΩ potentiometer (outer pins to 5 V and GND)

How LCD Scrolling Works on the HD44780

Before writing any code, it helps to understand what’s actually happening inside the LCD when it scrolls. The HD44780 controller stores characters in an internal memory called DDRAM (Display Data RAM), which is 80 bytes long — significantly larger than the 32 visible character positions on a 16×2 display. Each row has a DDRAM window of 40 characters, but only 16 are visible at a time. The rest live off-screen, waiting to be shown.

When you call scrollDisplayLeft() or scrollDisplayRight(), the controller simply shifts which 16-character window of DDRAM is visible on the screen — it does not redraw the characters one by one. This is why scrolling is fast and flicker-free: no byte-by-byte rewriting happens. Each call shifts the display by exactly one character position.

Two important consequences:

  • Both rows scroll together. The HD44780 does not support scrolling only one row — every call to scrollDisplayLeft() shifts the entire display window. If you need one line static and one scrolling, you have to redraw the static line manually on each iteration (shown later in this tutorial).
  • Text that was past position 16 comes into view. If you printed a string longer than 16 characters, the extra characters are stored in DDRAM and scroll in from the right as the display shifts. For text that fits in 16 characters, scrolling it to the right just moves it off the visible area, leaving blank space behind.

Complete Code for Scrolling Text on LCD with MSP430

For this demonstration we print “IOT LAB” on line 1 and “MSP430 BOARD” on line 2, then scroll the entire display 6 positions to the right, and then 6 positions back to the left. The sequence repeats forever, producing a smooth back-and-forth animation.

The sketch starts by including the LiquidCrystal library (built into Energia) and using #define directives to name the MSP430 header pins connected to the LCD. The last line hands those pin numbers to the library so it knows how your hardware is wired:

#include <LiquidCrystal.h>   // Energia's built-in HD44780 LCD library

#define RS 2
#define EN 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

Inside setup(), we initialize the LCD as 16 columns × 2 rows, print “IOT LAB” on line 1, and “MSP430 BOARD” on line 2 — identical to the LCD interfacing tutorial:

void setup()                 // runs once on reset
{
  lcd.begin(16, 2);          // 16 columns, 2 rows
  lcd.setCursor(0, 0);
  lcd.print("IOT LAB ");

  lcd.setCursor(0, 1);
  lcd.print("MSP430 BOARD");

  delay(1000);
}

The interesting part happens in loop(). Two built-in functions — lcd.scrollDisplayRight() and lcd.scrollDisplayLeft() — each shift the display one character position. To move the text multiple positions you call the function multiple times, typically inside a for loop with a short delay() between calls so the motion is visible to the human eye. A delay of 300–500 ms per step gives a pleasant reading pace; faster than that and the text becomes hard to read:

void loop()                  // runs repeatedly
{
  // Scroll 6 positions to the right
  for (int PositionCount = 0; PositionCount < 6; PositionCount++)
  {
    lcd.scrollDisplayRight();
    delay(450);              // 450 ms between scroll steps
  }

  // Then scroll 6 positions to the left (back to start)
  for (int PositionCount = 0; PositionCount < 6; PositionCount++)
  {
    lcd.scrollDisplayLeft();
    delay(450);
  }
}

Upload the sketch. On the LCD you will see the full message print first, then the whole display slowly shifts right for six steps, pauses briefly, then shifts left six steps back to the original position, then loops forever. Both lines move together because that’s how the HD44780 scroll command works internally.

Controlling Scroll Speed and Direction

Two parameters control the feel of the scroll animation:

  • Scroll speed — set by the delay() value between scroll calls. Typical values: 200 ms (fast), 400 ms (moderate), 600 ms (slow and readable).
  • Scroll distance — set by the number of iterations in the for loop. Scrolling 6 positions moves the text halfway across the display; scrolling 16 positions moves the current view completely off-screen.

For long messages that don’t fit in 16 characters, print the entire string to the LCD first (the extra characters go into DDRAM, off-screen), then scroll left repeatedly. The hidden characters will shift into view one by one. The HD44780 DDRAM is 40 characters wide per line, so any message up to 40 characters can be scrolled through without re-writing.

Scrolling Only One Line (Advanced)

Because scrollDisplayRight() and scrollDisplayLeft() always shift both lines simultaneously, scrolling just one line requires a different approach. The cleanest method is to implement the scroll manually: take a long message string, and on each iteration of the loop, print a 16-character substring at a different offset using standard lcd.print(). Here is a minimal one-line scroll pattern:

const char message[] = "Welcome to Microcontrollerslab.com  ";
const int msgLen = sizeof(message) - 1;  // exclude null terminator

void loop() {
  for (int offset = 0; offset < msgLen; offset++) {
    lcd.setCursor(0, 0);          // line 0
    for (int i = 0; i < 16; i++) {
      lcd.print(message[(offset + i) % msgLen]);
    }
    // line 1 stays static — redraw it once if needed
    lcd.setCursor(0, 1);
    lcd.print("MSP430 BOARD    ");
    delay(300);
  }
}

This pattern manually re-prints 16 characters starting at a sliding offset, wrapping around the end of the message using the modulo operator. Row 1 stays static because we never call scrollDisplayRight(). Trade-off: the manual redraw is slightly more CPU-heavy, but it gives you full control over which line moves.

Troubleshooting LCD Scrolling Issues

  • Text appears briefly then goes blank. You scrolled too far — beyond the 16-character visible window. Reduce the number of scroll iterations, or use a shorter message.
  • Both lines scroll when I only wanted one. That’s the HD44780’s built-in behavior — scrollDisplayRight() always shifts both lines. Use the manual scrolling pattern shown above to move just one line.
  • Scrolling is too fast / too slow. Adjust the delay() value between scroll calls. 300–500 ms per step is comfortable for reading.
  • Text appears reversed or scrolled in the wrong direction. Swap scrollDisplayLeft() for scrollDisplayRight() (or vice versa) — they are intuitively named from the text’s perspective, which can occasionally feel inverted when you think from the display’s perspective.
  • Text flickers visibly on each scroll step. The HD44780 native scroll should not flicker. If you see flicker, you are probably calling lcd.clear() or lcd.begin() on every iteration — move those calls to setup().
  • Message stops scrolling after a few seconds. Look at the for loop bounds. If PositionCount is never reset or the loop exits early, the animation freezes.

Frequently Asked Questions

Can I scroll text longer than 16 characters on a 16×2 LCD?

Yes — the HD44780 has 40 characters of DDRAM per row, so you can print messages up to 40 characters long and scroll through them using scrollDisplayLeft(). For messages longer than 40 characters, you need to implement software scrolling (print sliding 16-character substrings) as shown in the “Scrolling Only One Line” section above.

How fast can the MSP430 scroll an LCD?

The HD44780 can accept commands every ~40 µs, so scrolling as fast as 25,000 steps per second is theoretically possible. In practice, any scroll step faster than ~100 ms per character is hard for a human to read. For display purposes stick to 200–600 ms per step.

Is there a way to scroll only the top or bottom line independently?

Not with the native HD44780 scrollDisplay commands — they always move both rows. To scroll just one line, implement manual scrolling in software by re-printing sliding substrings to that line on each iteration. See the code example earlier in this tutorial for the working pattern.

Can I combine scrolling with dynamic data like sensor readings?

Yes. A common pattern is to scroll a title on the top line and display a live reading (temperature, ADC value, elapsed time) on the bottom line. Implement the title with software scrolling, and update the second line separately with lcd.setCursor(0, 1); lcd.print(sensorValue); on each refresh. The two animations run independently.

Why does scrolling look jerky?

Two common causes: (1) the delay() value varies because you’re also doing slow work elsewhere in loop() (sensor reads, serial prints), which makes the scroll step inconsistent; or (2) you’re calling lcd.clear() on each iteration, which causes a visible blank flash. For smooth scrolling, keep loop() lean and avoid clear() except when you really need to wipe the entire display.

Does this code work on other Arduino-compatible boards?

Yes, the code uses standard LiquidCrystal library functions that work identically on Arduino Uno, Mega, ESP32, ESP8266, STM32, and any other Arduino-compatible board. Only the pin numbers in the #define block need to change to match the target board’s GPIO pinout.

Conclusion

You now know how to scroll text on a 16×2 LCD using an MSP430 microcontroller. You learned the two built-in Energia functions — scrollDisplayRight() and scrollDisplayLeft() — how they interact with the HD44780’s internal DDRAM, and the manual pattern for scrolling just one line while keeping the other static. The same functions and techniques work on any HD44780-based character LCD, from 16×2 up to 20×4, and across every Arduino-compatible microcontroller. Next in the MSP430G2 series we move on to UART serial communication.

Related MSP430G2 LaunchPad Tutorials

1 thought on “Scrolling Text on 16×2 LCD using MSP430 Microcontroller and Energia”

Leave a Comment