ATMega 2560 + LCD1602 - LCD displaying text that does not match input?

My ultimate end goal of this is to be able to send a string from my Java application, and have that string print onto the LCD.
However, I'm starting with the basics - which would be sending a string in the Serial Monitor and then displaying it.

For some reason, when I put in a string "aaaaaaaaaa" for example, I the LCD displays some text that is not it.
It also prints an unknown character each time the monitor starts (It does not show up here when I paste it)

Here are some examples of what it's been writing (All responses are [THE_RESPONSE_HERE] to indicate spaces and etc that may be at the start):
Input: aaaa Response: [ aa]
Input: aaaaaaa Response: [ !a`]
Input: helloworld Response: [ V¢πØdDDDDDDDDDD]

I semi-understand why it's always 1 character away, and that's because it's reading a unrecognized character each time.

Here is my code:

#include <LiquidCrystal.h>

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

void setup(){
    // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
}

char letters[] = { 'A', 'B', 'C', 'D', 'E', 'F',
 'G', 'H', 'I', 'J', 'K',
  'L', 'M', 'N', 'O', 'P',
  'Q', 'R', 'S', 'T', 'U',
  'V', 'W', 'X', 'Y', 'Z'};

void loop()
{
   String s = "";
  if (Serial.available()) {
    delay(100);
    while (Serial.available() > 0) {
      int readIn = Serial.read();
      s += letters[readIn - 97];
    }
    s.toLowerCase();
    Serial.println(s);
  }
  lcd.print(s);
  delay(1000);
  lcd.clear();
}

And this is my wiring:
LCD PIN 1 > GND
LCD PIN 2 > 5V
LCD PIN 3 > 100 ohm resistor > GND
LCD PIN 4 > PIN 0
LCD PIN 5 > GND
LCD PIN 6 > PIN 1
LCD PIN 7 > Empty
LCD PIN 8 > Empty
LCD PIN 9 > Empty
LCD PIN 10 > Empty
LCD PIN 11 > PIN 2
LCD PIN 12 > PIN 3
LCD PIN 13 > PIN 4
LCD PIN 14 > PIN 5
LCD PIN 15 > 5V
LCD PIN 16 > GND

A couple of small notes:

The array for letters is not correct. I kind of lazily made it work by always typing in lower case letters, and then just subtracting 97 (the value of a) from the value read. It works perfectly in the serial monitor, but not on the lcd.

I used s.toLowerCase(); to see if it changed anything - it did not.

If any more information is needed please let me know

When using Serial.println(s);, the string shows perfectly (Except for 1 unknown character at the start EVERY time)

      int readIn = Serial.read();
      s += letters[readIn - 97];

Suppose the use enters a 'D'. The ASCII code for that is 68. You've just defined an index outside of your array.

The type of the variable that the value from Serial.read() should be char, when you KNOW that there is data to read, as you do.

Then, just append the character to the String instance (or shitcan the String class, and store the character in a char array).

If you think you have handled everything when the user types in lower case, what about the carriage return (13) and/or line feed (10) and/or space (32)?

Using pins D0 & D1 for both the lcd and serial could lead to some interesting results...

dannable:
Using pins D0 & D1 for both the lcd and serial could lead to some interesting results...

Indeed it can.

PaulS:

      int readIn = Serial.read();

s += letters[readIn - 97];



Suppose the use enters a 'D'. The ASCII code for that is 68. You've just defined an index outside of your array.

The type of the variable that the value from Serial.read() should be char, when you KNOW that there is data to read, as you do.

Then, just append the character to the String instance (or shitcan the String class, and store the character in a char array).

If you think you have handled everything when the user types in lower case, what about the carriage return (13) and/or line feed (10) and/or space (32)?

I expected someone to point this out.
I'm well aware that my character array and my read code is not done. I was actually making sure to only type in lower case letters (As their codes are 97+) and nothing else.
The reason for this was that I am still doing testing.. As I'm really not going to worry about handling every single character when I can't even get one to display correctly (If that makes any sense).
Once the LCD is displaying correctly I was going to use a more conventional method to getting the characters.

dannable:
Using pins D0 & D1 for both the lcd and serial could lead to some interesting results...

The wiring I used was actually based on a guide..
I move the two pins, and also added in another resistor - and all that combined seems to have solved the issue.
Moving the pins made it possible for the data to be read correctly, but when doing that somehow the screen decided to have white blocks on everything, which the resistor fixed.

Thank you everyone for the help. I now get to write out a proper character array and all the other goodies :smiley:

Edit:

Everything seems to be coming along nicely so far.
However, one small issue.
When using a string that is greater than 16 characters, it does not split off onto the second line of the LCD. What can I do to solve this?

What can I do to solve this?

Obviously, you can count. So, you know that a given character is number 1, 2, 15, 16, 17, 18, etc., right?

lcd.setCursor() looks like a function you should become familiar with.