Pages: [1]   Go Down
Author Topic: Arduino 1.0 with Sparkfun Serial LCD  (Read 1842 times)
0 Members and 1 Guest are viewing this topic.
Cwmbran, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

In upgrading to Arduino 1.0 I have ammended the LCD.print commands to Serial.write as follows:

Code:
#include <SoftwareSerial.h>

#define txPin 2

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

// wbp: goto with row & column
void goTo(int row, int col) {
  Serial.write(0xFE);   //command flag
  Serial.write(col + row*64 + 128);    //position
  delay(LCDdelay);
}
void clearLCD(){
  Serial.write(0xFE);   //command flag
  Serial.write(0x01);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //turns on the backlight
  Serial.write(0x7C);   //command flag for backlight stuff
  Serial.write(157);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  Serial.write(0x7C);   //command flag for backlight stuff
  Serial.write(128);     //light level for off.
  delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.write(0xFE);
}

void setup()
{
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  clearLCD();
  goTo(0,0);
  LCD.print("Test String");
}

void loop()
{
}

This now compiles and uploads, but theres clearly something wrong with my changes because it doesn't clear the display and goTo(0,0); doesnt work, however the "Test String" text is displayed.

Any ideas please?

Thanks in advice smiley
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you writing to the serial port, and expecting the LCD to react, when it is not connected to the serial port?
Logged

Cwmbran, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I modified this code:

Code:
#include <SoftwareSerial.h>

#define txPin 2

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

// wbp: goto with row & column
void goTo(int row, int col) {
  LCD.print(0xFE, BYTE);   //command flag
  LCD.print((col + row*64 + 128), BYTE);    //position
  delay(LCDdelay);
}
void clearLCD(){
  LCD.print(0xFE, BYTE);   //command flag
  LCD.print(0x01, BYTE);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //turns on the backlight
  LCD.print(0x7C, BYTE);   //command flag for backlight stuff
  LCD.print(157, BYTE);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  LCD.print(0x7C, BYTE);   //command flag for backlight stuff
  LCD.print(128, BYTE);     //light level for off.
   delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  LCD.print(0xFE, BYTE);
}

void setup()
{
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  clearLCD();
  goTo(0,0);
  LCD.print("Hello world!");
}

void loop()
{
}

Which I found on this page: http://www.arduino.cc/playground/Learning/SparkFunSerLCD
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, all the Serial.write()s should be LCD.write()s.
Logged

Cwmbran, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That just produces an "'LCD' was not declared in this scope." error.

Before changing that the code was making the screen display the text but the "control codes" for the LCD weren't working correctly.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
SoftwareSerial LCD = SoftwareSerial(0, txPin);
This is a global variable.

Quote
That just produces an "'LCD' was not declared in this scope." error.
Show the code and the exact error message, specifically, the line number.
Logged

Cwmbran, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code following your changes reads:

Code:
#include <SoftwareSerial.h>

#define txPin 2

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

// wbp: goto with row & column
void goTo(int row, int col) {
  lcd.write(0xFE);   //command flag
  lcd.write(col + row*64 + 128);    //position
  delay(LCDdelay);
}
void clearLCD(){
  lcd.write(0xFE);   //command flag
  lcd.write(0x01);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //turns on the backlight
  lcd.write(0x7C);   //command flag for backlight stuff
  lcd.write(157);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  lcd.write(0x7C);   //command flag for backlight stuff
  lcd.write(128);     //light level for off.
  delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.write(0xFE);
}

void setup()
{
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  clearLCD();
  goTo(0,0);
  LCD.print("Mrs Janet Long!");
}

void loop()
{
}

And the error messages created are:

Code:
serLCD_Test.cpp: In function 'void goTo(int, int)':
serLCD_Test:10: error: 'lcd' was not declared in this scope
serLCD_Test.cpp: In function 'void clearLCD()':
serLCD_Test:15: error: 'lcd' was not declared in this scope
serLCD_Test.cpp: In function 'void backlightOn()':
serLCD_Test:20: error: 'lcd' was not declared in this scope
serLCD_Test.cpp: In function 'void backlightOff()':
serLCD_Test:25: error: 'lcd' was not declared in this scope
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So, all the Serial.write()s should be LCD.write()s.
So, you made them lcd.write()s, instead. Why?

Case matters!
Logged

Cwmbran, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok thanks for the help smiley

Working fine now smiley
Logged

Pages: [1]   Go Up
Jump to: