Correctly display long sentences on LCD

Hi guys!

For my first ever Arduino project I've decided to program a generator for the Liquid Crystal (16x2) which randomly displays suggestions for making your days a bit more special when you press a button.

I've got it to work, but now I've got the problem that the longer sentences are pretty messed up.

How do I get it to display those correctly?

(I've attached the code. Sorry the suggestions are in german.)

RAG_by_AJ.ino (1.84 KB)

AnniMagZombies:
For my first ever Arduino project I've decided to program a generator for the Liquid Crystal (16x2) which randomly displays suggestions for making your days a bit more special when you press a button.

I've got it to work, but now I've got the problem that the longer sentences are pretty messed up.

How do I get it to display those correctly?

(I've attached the code. Sorry the suggestions are in german.)

It is possible to show text scrolling on a 16x2 LCD.

The scrolling is not running very smooth, because it is more a "jumping char by char", but easily readable if the speed is perhaps at scrolling 4 characters per second or something like that.

I think that two years ago or so I also posted some scrolling code in the German section of the Arduino forum.

Just looked it up, here it is in reply #4:
http://forum.arduino.cc/index.php?topic=176732.msg1312111#msg1312111

The routines can scroll two lines of text.
Scrolling is possible from left to right or right to left, and with different scroll speed, which can be defined seperately for each line.

Hi,

Thank you for your responses. Sorry I should have explained my problem more detailed.

The text is scrolling, but the textwrapping is a bit messed up. E.g. sometimes it jumps from the first row to the second one in the middle of a word. It's very hard to read that way.

Can I somehow controll this?

This is the code for the generator:

// Random Adventure Generator by Annika Jenssen


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// variable to check if button is pressed
int val;

boolean cle = true;
boolean cle2 = false;

// array of strings with suggestions to mix up my day
char* vors[] = {"Stell dir ein total verruecktes Essen zusammen","Wie waer's mit nem neuen Klamottenstil?","Verschoenere jemandem den Tag!","Erzaehle bei jeder Gelegenheit deinen liebsten schlechten Witz","Trag heute mal nen lustigen Hut","Nimm mal einen anderen Weg zur Arbeit","Probier doch mal ein neues Restaurant aus","Koch dir mal was was du noch nicht kennst", "Iss dein Abendbrot zum Fruehstueck und umgekehrt", "Tu auf deiner Arbeit so, als waerst du eigentlich ein Spion", "Geh in den naechsten Tierladen und guck dir flauschige Tiere an", "Hol dir einen Tamagotchi :D", "Melde dich mal wieder bei einem Freund den du nicht oft siehst"};

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // turn on the cursor:
  lcd.cursor();
  
  Serial.begin(9600);
  
  // display first message
  lcd.setCursor(1,0);
  lcd.print("MIX UP MY DAY!");
}

void loop() {
  // map val to only 0 and 1 and give out current value
  val = map(analogRead(0),0,1010,0,1);
  Serial.println(val);
  
  // if the button is pressed clear screen and give out randomly
  // selected character from array
  if(val == 1){
    if(cle == true){
      lcd.clear();
      int r = random(0,(sizeof(vors)/2));
      lcd.setCursor(1,0);
      lcd.print(vors[r]);
    }
    cle = false;
    cle2 = true;
   }
   
  // if the button isn't pressed display and scroll the generated
  // suggestion
    else{
      if(cle2 == true){
        lcd.scrollDisplayLeft();
        delay(500);
        cle = true;
      }
   }
}

AnniMagZombies:
Can I somehow controll this?

You can control everything as you like.

Currently you are programming using the GIGO principle: Garbage In - Garbage Out

Why the hell do you believe, that this might work:

  • take a LCD display with 16 characters line length
  • take a string that is much longer than 16 characters in length
  • try to print that much too long string on the LCD
  • and then expect, that scrolling left the string may retrieve the correct characters from wherever they are lost in the garbage of the LCD controller where you have thrown them?

Controlling a 16 character LCD means:

  1. Do NOT try to print more characters in one LCD line than characters fit into the LCD line!
  2. Do NOT expect characters that are in some garbage area because you missed point 1., can be retrieved successfully from the garbage area into the LCD line by "scrolling left".