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)