Printing to Serial LCD

I'm trying to print messages from the Arduino Uno to a Serial LCD. I've tried connecting RX - Pin 2, GND - GND and VDD - 5V but the LCD displays a load of random characters. Any suggestions on how to get it working? Thanks

Are you also using the serial monitor? If not then RX should go to pin 1, and not pin 2. Post your code. Look for the # above the smiley faces, that is your code tags.

const int led_ProgRun = 13; //This led comes on whenever the program is running
const int ledPin_1 = 12;
const int ledPin_2 = 11;
const int ledPin_3 = 10;
const int buttonPin = 3;
long debounceDelay = 200;
long lastDebounceTime = 0;
int buttonState = LOW;
int letsgo= false;
int dosomethingat[5][3] =
{
  {1000, 1, 1},
  {1000, 2, 1},
  {8000, 1, 0},
  {8000, 2, 0},
  {9000, 0, 0}
  
}; // this array states what to do at various times
// first column represents time, second which LED 
// third on/off 
long currenttime = millis();
int dsa_point =0; //indicates current row of 'dosomethingat' array
// note that arrays are zero indexed in Arduino
long starttime = millis();

void setup() 
{
  pinMode(buttonPin, INPUT);
  pinMode(ledPin_1, OUTPUT);
  pinMode(ledPin_2, OUTPUT);
  pinMode(ledPin_3, OUTPUT);
  pinMode(led_ProgRun, OUTPUT);
}

void loop() 
{ 
  buttonState = digitalRead(buttonPin);
  if ((millis() - lastDebounceTime)>debounceDelay)
  {
  if (buttonState == HIGH)
  {
    if (letsgo == false)
    {
    letsgo=true;
    starttime = millis();
    dsa_point = 0;
    digitalWrite(led_ProgRun, HIGH);
    Serial.print("Hello world.");
    lastDebounceTime = millis();
    }
    else //letsgo == true
    {
    letsgo = false;
    digitalWrite(ledPin_1, LOW);
    digitalWrite(ledPin_2, LOW);
    digitalWrite(ledPin_3, LOW);
    digitalWrite(led_ProgRun, LOW);
    lastDebounceTime = millis();
    }
  }
  if (letsgo==true)
  { 
    currenttime = millis() - starttime; 
    if (dosomethingat[dsa_point][0] <= currenttime)
    {
     switch (dosomethingat[dsa_point][1])
     {
      case 1: //when switch variable = 1
      if (dosomethingat[dsa_point][2]==1)
      {
        digitalWrite(ledPin_1, HIGH);
      }
      else //"" = 0
      {
        digitalWrite(ledPin_1, LOW);
      }
      break;
      
      case 2:
      if (dosomethingat[dsa_point][2]==1)
      {
        digitalWrite(ledPin_2, HIGH);
      }
      else
      {
        digitalWrite(ledPin_2, LOW);
      }
      break;
      
      case 3:
      if (dosomethingat[dsa_point][2]==1)
      {
        digitalWrite(ledPin_3, HIGH);
      }
      else
      {
        digitalWrite(ledPin_3, LOW);
      }
      break;
      
      case 0: // 
      Serial.print("Sequence complete.");
      digitalWrite(ledPin_1, LOW);
      digitalWrite(ledPin_2, LOW);
      digitalWrite(ledPin_3, LOW);
      break;
    }
    dsa_point = dsa_point +1;
  }
}
}
}

I’ll try pin 1, do I need to initialize the LCD or use a library of some sort?

Post a link to the hardware you're using. There are several different display types all marked as "serial": UART, I2C, SPI, etc.

If your display is a UART style one, you should at least add the following line to setup:

Serial.begin(BAUDRATE);

where BAUDRATE is the baud rate your display uses.

Having a baud rate and a lcd library for your particular lcd, would be a big help.

http://proto-pic.co.uk/serial-lcd-with-cable-retail/

^^ Thats the LCD I'm using. What libraries might I be able to use with that? And what exactly is a 'baudrate'?

If go to the link that you posted there is a Quick Start Guide that has a link to the Liquid crystal library and source code for Arduino.

No lib is required with this unit.

You have to choices

  1. connect the LCD to the TX pin and ground to ground (of course).

  2. use software serial on some other pins.

Now start a new sketch assuming that you are using the TX pin and therfore Serial the following will clear the lcd and write "hello world"

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(1);//clear
  Serial.print("Hello world");

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Mark

Cheers holmes, will try that. Do the values 254 and 1 have any significance?

See the data sheet, sending 254/0xfe starts a command to the pic micro running the LCD the next number is the command its self.

Here's the (part of the) list

#define clearLCD 0x01
#define cursorRight 0x14
#define curaorLeft 0x10
#define scrollRight 0x1c
#define scrollLeft 0x18
#define displayOn 0x0c
#define displayOff 0x08
#define ULCursorOn 0x0e
#define ULCursorOff 0x0c
#define BBCursorOn 0x0d
#define BBCursorOff 0x0c
#define cursorPos 0x80
#define startSecondLine 0x40
#define command 0xfe

Serial.write(command); Serial.write(cursorPos+ 0x40);

Gets you to the start of the second line.

Mark

PS The arduino's bootup faster than the serLCD module, so adding a delay(1000) at the start of setup() clears a lot of problems.

M