Go Down

Topic: Nokia LCD display shield question (Read 5220 times) previous topic - next topic

StuHooper

Hi all,
I'm under the impression that the sparkfun color LCD shield doesn't work with liquidcrystal library.
I understand that it comes with it's own library that does lots of fancy stuff in the demos.
None of the example codes seems to tell me how to use it to print serial information.

All I need it for is to display the serial so I don't have to plug the arduino into a pc.

Does anyone know where to find a demonstration, or can you provide a demonstration of how to print serial data to the LCD shield and not have it stack letters up (when using print(F("word"));, not print blabla, all the problems I've hit already.
Visual learner, could do with a demo.

Far-seeker

From the tutorial at Sparkfun.com...

Quote

One final feature of the library allows you to add text to the LCD. There's the setChar function, which allows you to place one, and only one, character at specified coordinates. Then there's the setStr function, which will place a string of characters on the screen.


Scroll down a little over half-way and you'll see the above text, after it will be a screenshoot of example code in the Arduino IDE.  If you can convert the data you want to display into characters or strings this should work for you.

olikraus

I guess you mean something like a terminal emulator for an LCD screen (http://en.wikipedia.org/wiki/Terminal_emulator). I did something very simple in that direction here: http://code.google.com/p/u8glib/source/browse/sys/arduino/Console/Console.pde. It takes input from serial and outputs it on the LCD. Maybe a starting point for you.

Oliver

StuHooper


From the tutorial at Sparkfun.com...

Quote

One final feature of the library allows you to add text to the LCD. There's the setChar function, which allows you to place one, and only one, character at specified coordinates. Then there's the setStr function, which will place a string of characters on the screen.


Scroll down a little over half-way and you'll see the above text, after it will be a screenshoot of example code in the Arduino IDE.  If you can convert the data you want to display into characters or strings this should work for you.


I think that will work and possibly look better than a scrolling serial data actually.

Thanks for both responses. Very helpful.

Far-seeker


StuHooper

Hi Again,
I just ran a quick test to get everything laid out properly and I hit a problem while integrating it into my main sketch.

This worked fine
Code: [Select]
#include <gLCD.h>

const char RST = 8;
const char CS = 9;
const char Clk = 13;
const char Data = 11;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

char wt[] = "LOW";

void setup() { 
graphic.begin(0,2,0,PHILLIPS_1);
graphic.setBackColour(1,1,1);
graphic.Box(0,0,6100,6100,4);
   graphic.setFont(0);

}
void loop() {
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:"); //Normal sized text, no background. Hello and World will be printed on seperate lines
  //resp
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured Blue
  graphic.print("TRUE"); //Normal
 
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,20);
  graphic.print("Standards:"); //Normal
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Blue
  graphic.print(wt); //Normal
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,40);
  graphic.print("Burgervan tadpole?:"); //Normal
  //resp
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Blue
  graphic.print("Maybe"); //Normal
}





But the second I slot it into my code, it doesn't print the text. Just the stuff in the initial setup.

Code: [Select]
// Include description files for other libraries used (if any)
#include <Twitter.h>
#include <gLCD.h>
#include <Ethernet.h>
#include <SPI.h>
#include <EthernetUdp.h>
#include <PString.h>

// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  80

const char RST = 8;
const char CS = 9;
const char Clk = 13;
const char Data = 11;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

// Setup vars
char tagStr[MAX_STRING_LEN] = ""; //to contain the XML tags for comparison
char dataStr[MAX_STRING_LEN] = ""; //to store information between hashtags
char tmpStr[MAX_STRING_LEN] = ""; //temporary string for something.. I dunno
char prevStr[MAX_STRING_LEN] = ""; //to compare tweets to their previous, stops repeat functions
char buffer[MAX_STRING_LEN] = ""; // for PString... maybe Concatenate if it still jams up.
char endTag[3] = {'<', '/', '\0'};  //to recognise the ends of chars, XML tags and strings
char makeCoffee[] = "make me coffee"; // trigger text for incoming tweets
boolean firstTweetRead = false;  //to stop make() on first tweet read
PString tweetString(buffer, sizeof(buffer)); //contains the tweet
long randNumber; //to make the tweets unique
int len;               //No idea
int totalCount = 1;  //to count connect attempts
int ledPin = 3;      //to control the relay


// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;     
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x13, 0x1D };  //Arduino MAC
byte ip[] = {78,147,235,111 };                        //My home IP
byte server[] = { 199,59,149,232 }; // Twitter IP
Twitter twitter("794475482-XuCh0IVm8nTRcTAxkV6Gpx6VkdElWsww1Ns11n8x");


// Start ethernet client
EthernetClient client;

void setup()
{
graphic.begin(0,2,0,PHILLIPS_1);
graphic.setBackColour(1,1,1);
graphic.Box(0,0,6100,6100,4);
graphic.setFont(0);
   
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
 
  Serial.begin(9600);
  //Ethernet Client
  // attempt a DHCP connection:
  Serial.println(F("setup"));
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println(F("failed, trying manually"));
    Ethernet.begin(mac, ip);
  }
 

connectToServer();
}

void loop() {
 
    screen();

    while (client.connected()) {
    while (client.available()) {

    serialEvent();
        screen();

    }
  }

  if (!client.connected()) {

    Serial.println();
    Serial.println(F("=========Disconnected=========="));
    Serial.println("");
    client.stop();
    client.flush();
        screen();

    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 30; t++) {
      delay(1000); // 1/2 minute
    }
        screen();
connectToServer();
}

}



void screen(){
 


  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:"); //Normal sized text, no background. Hello and World will be printed on seperate lines
  //resp
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured Blue
  graphic.print("TRUE"); //Normal
 
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,20);
  graphic.print("Water Level:"); //Normal
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Blue
  graphic.print("LOW"); //Normal
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,40);
  graphic.print("Making Coffee:"); //Normal
  //resp
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Blue
  graphic.print("FALSE"); //Normal
}


Why is this?

StuHooper

is it a possibility that the color LCD shield is clashing with the Ethernet shield? I can't see why it wouldn't work unless the shield needs the entire loop function to itself.

Tom Carpenter

#7
Oct 07, 2012, 05:17 pm Last Edit: Oct 07, 2012, 05:24 pm by Tom Carpenter Reason: 1
Just so you know, this:
Code: [Select]
graphic.Box(0,0,6100,6100,4);
Will take an awfully long time to execute as the display is only 128x128 and you are trying to print a box 6101 pixels square (starting at (0,0) ending at (6100,6100)).
If you just want to clear the screen, you can use this:
Code: [Select]
graphic.Clear();
Which will set all pixels to be the background colour

Secondly, and most importantly, the Ethernet sheild uses pin 13 and pin 11.
What I did with my LCD shield is to cut the traces going to these pins and added jumper wires to pin 7 and pin 6. The you would just have to change your code to be:
const char Clk = 7;
const char Data = 6;
I found sparkfuns choice to use the SPI pins for this display rather unhelpful as we cant use the hardware SPI for it anyway (it uses a funny 9 bit SPI communication).


--------------------------------------------
As a couple of side notes, but not related to your problem:

You can get rid of that White bar at the top of the screen by correctly setting the screen offset coordinate. The begin function is specified as: begin(xOffset, yOffset, InvertColour, Driver);
So by the looks of things, your screen (unlike mine) is perfectly aligned at the origin, so to get rid of those two pixels, change this:
Code: [Select]
graphic.begin(0,2,0,PHILLIPS_1);
Changes to:
Code: [Select]
graphic.begin(0,0,0,PHILLIPS_1);

You can also now use predefined colours for easy reading:
Code: [Select]
graphic.setForeColour(15,15,15); //While this is perfectly acceptable...
graphic.setForeColour(GLCD_WHITE); //This does the same thing, but is easier to follow

You don't have to use these colours and the way you are doing it will work absolutely fine, but based on the the comments next to setting colours in your code, it may be easier to read.
This is a full list of colours defined in the header file.
Code: [Select]
#define GLCD_WHITE 0x0F0F0F
#define GLCD_BLACK 0x000000
#define GLCD_GREEN 0x000F00
#define GLCD_LIME 0x080F00
#define GLCD_BLUE 0x00000F
#define GLCD_RED 0x0F0000
#define GLCD_GREY 0x080808
#define GLCD_ORANGE 0x0F0800
#define GLCD_CYAN 0x000F0F
#define GLCD_YELLOW 0x0F0F00
#define GLCD_LEMON 0x0F0F08
#define GLCD_MAGENTA 0x0F000F
#define GLCD_PINK 0x0F0808
~Tom~

StuHooper

Thanks Tom,
That's a lot of help. I'll set it up as you say tomorrow and see if it works with the Ethernet shield.

I was wondering about the pixel lines at the top. There are three different libraries suggested for this shield. gLCD seemed to be best but it left the lines at the top. I guess I overlooked comparing gLCD with the others.

I've just ordered another LCD off of ebay. I hope this works though. It would give me something to do tomorrow. If there is one thing I've learned about dabbling, it's that it's good to have parts lying around everywhere.

Regards

Stu

StuHooper

Is there something I am missing when it comes to re-printing information to the screen?
When the server is disconnected I want the void screen(); to run again replacing the TRUE with a FALSE.
This doesn't work.

Code: [Select]
// Include description files for other libraries used (if any)
#include <Twitter.h>
#include <gLCD.h>
#include <Ethernet.h>
#include <SPI.h>
#include <EthernetUdp.h>
#include <PString.h>



// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  80

const char RST = 8;
const char CS = 9;
const char Clk = 7;
const char Data = 6;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

boolean cts;
boolean mknc;

// Setup vars
char tagStr[MAX_STRING_LEN] = ""; //to contain the XML tags for comparison
char dataStr[MAX_STRING_LEN] = ""; //to store information between hashtags
char tmpStr[MAX_STRING_LEN] = ""; //temporary string for something.. I dunno
char prevStr[MAX_STRING_LEN] = ""; //to compare tweets to their previous, stops repeat functions
char buffer[MAX_STRING_LEN] = ""; // for PString... maybe Concatenate if it still jams up.
char endTag[3] = {'<', '/', '\0'};  //to recognise the ends of chars, XML tags and strings
char makeCoffee[] = "make me coffee"; // trigger text for incoming tweets
boolean firstTweetRead = false;  //to stop make() on first tweet read
PString tweetString(buffer, sizeof(buffer)); //contains the tweet
long randNumber; //to make the tweets unique
int len;               //No idea
int totalCount = 1;  //to count connect attempts
int ledPin = 3;      //to control the relay


// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;     
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x13, 0x1D };  //Arduino MAC
byte ip[] = {78,147,235,111 };                        //My home IP
byte server[] = { 199,59,149,232 }; // Twitter IP
Twitter twitter("794475482-XuCh0IVm8nTRcTAxkV6Gpx6VkdElWsww1Ns11n8x");


// Start ethernet client
EthernetClient client;

void setup()
{
graphic.begin(0,0,0,PHILLIPS_1);
graphic.setBackColour(GLCD_BLACK);
graphic.Clear();
graphic.setFont(0);

cts = false;
mknc = false;
screen();

   
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
 
  Serial.begin(9600);
  //Ethernet Client
  // attempt a DHCP connection:
  Serial.println(F("setup"));
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println(F("failed, trying manually"));
    Ethernet.begin(mac, ip);
  }
 
   connectToServer();
}

void loop() {
    while (client.connected()) {
    while (client.available()) {
    cts = true;
    serialEvent();
    }
  }

  if (!client.connected()) {
    Serial.println();
    cts = false;     // This should trigger.....
    Serial.println(F("=========Disconnected=========="));
    screen();     //THIS to change TRUE to FALSE  but it doesn't.  :(
    Serial.println("");
    client.stop();
    client.flush();
    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 30; t++) {
      delay(1000); // 1/2 minute
    }
connectToServer();
}
screen();

}



void screen(){
  graphic.Clear();
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:");
  //resp


  if (cts = true){
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured green
  graphic.print("TRUE");
  }
 
  if (cts = false){
  graphic.setCoordinate(1,10);
  graphic.setForeColour(15,0,0); //Text is coloured green
  graphic.print("False");
  }
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,20);
  graphic.print("Water Level:");
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Red
  graphic.print("LOW");
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,40);
  graphic.print("Making Coffee:");
  //resp
 
  if (mknc = false){
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Purple
  graphic.print("FALSE");
  }
 
  else if (mknc = true){
  graphic.setCoordinate(1,50);
  graphic.setForeColour(GLCD_LEMON); //Text is coloured lemon
  graphic.print("True"); //This keeps displaying even though it is false
  }
}


I don't get why these Booleans aren't working with this shield.
I know another method would be to replace sections of the screen with black and then write on top of them but that's a bit messy isn't it?

StuHooper

PS, the jumpers work just fine. Thanks


StuHooper

Never mind. I'm going to do away with the void and call it all when I need it like this

Code: [Select]


    graphic.Box (1,10,128,19,0);
    graphic.setCoordinate(1,10);
    graphic.setForeColour(15,0,0); //Text is coloured Red
    graphic.print("False"); //Normal   

Tom Carpenter

#12
Oct 08, 2012, 02:50 pm Last Edit: Oct 08, 2012, 02:54 pm by Tom Carpenter Reason: 1
If you go through that function and find stuff like this:
Code: [Select]
if (cts = true){
//always called as assignment returns true
}

if (cts = false){
//neve called as assignment returns true
}

It is wrong. It should be like this:
Code: [Select]
if (cts == true){
//called when cts is true
}

if (cts == false){
//called when cts is false
}


Can you see the difference?

Your code is using an assignment (set cts to equal true) which regardless of the math you do always returns true.
The second code block is using an equality operator - the statement is true if this IS EQUAL to that, else it is false.


For cases where you are checking if something is true or false, you are best using this:
Code: [Select]
if (cts){
//called when cts is true
}

if (!cts){
  //called when cts is NOT true, i.e. false
}

This is important as when something returns true you can't guarantee that it is == to 0x01 (which is what true is defined as). In the world of C/C++, boolean true is anything which is not 0.
~Tom~

StuHooper

That makes a lot of sense. I knew it ffs. I just keep forgetting. 

Another issue, If I need to display 140 characters on one line, how do I make it scroll across the screen?
Is it a case of wiping the screen, deleting the first char and repeating until the message has gone?

Tom Carpenter

Yep. there is no funtion buoy in to do that so you will have to do it manually. I have some code from a previous project which I can find for you if you would like.
~Tom~

Go Up