Question about LCD interfacing

Discussion about my Wifi Radio project at http://mightyohm.com/wifiradio/ or my WL-520gU talk at NOTACON.
Post Reply
Evil Potato
Posts: 3
Joined: Tue Apr 14, 2009 9:49 am

Question about LCD interfacing

Post by Evil Potato »

Hey guys!

Let me start off by thanking Jeff for taking the time to post this project. I have been having a lot of fun setting it up and messing around with the router! I have deviated from his original plans and have used a Boarduino to control my parallel LCD. I am running into a problem, however, when receiving playlist info - the LCD spits out all the info on 1 line, then when it reaches 40 characters, it pumps the remaining info on the second line. I've been stuck on this for 3 weeks and I've tried looking everywhere for an answer to this question;

Does the serial output a carriage return character, and if so, how can I read it as a carriage return?

If you'd like, I'll paste my sketch up so you can have a better idea of what I'm working with. I'll also paste it once I get it working, for all the others who have opted for the Arduino setup.

Thanks for any help you can provide!
User avatar
mightyohm
Site Admin
Posts: 1064
Joined: Fri Apr 03, 2009 10:29 pm
Location: Seattle, WA
Contact:

Re: Question about LCD interfacing

Post by mightyohm »

Evil Potato -

The serial data doesn't contain formatting specific to the LCD. The serial output of the router is something like:

Name: Slay Radio
Title: Some Artist - Some Song Name

Each line has a newline character at the end, but it's up to the microcontroller driving the LCD display to figure out how to best display the data. On my ATmega I have some code that figures out what will fit on the display, and if the line is longer than the display width, it tries to put the newline in a semi-intelligent place that avoids wrapping words. If the line is really long, ie. > 2x display width, then it prints beyond the visible area of the LCD and uses the LCD scroll function to shift the display left and right so you can see the whole line, as shown in the video on my blog.

Does that make sense? Unfortunately it means more work for you but I don't think its good to put formatting into the serial data in case different people have different display sizes, etc.
Evil Potato
Posts: 3
Joined: Tue Apr 14, 2009 9:49 am

Re: Question about LCD interfacing

Post by Evil Potato »

Hey Guys;

I've made some headway on the arduino interface for your display script. I am still running into a problem while trying to display to text, however. My code is posted below, (I know it may be messy - I'm still learning :))

Code: Select all

#include <LCD4Bit.h>
#include <WString.h>

#define CMD_NOWRAP 0x44
//#define CMD_SHIFTLEFT 0x18

LCD4Bit lcd = LCD4Bit(2);   // set the number of Displays lines

char data1;
String topData;
String topFir;

char data2;
String botData;
String botFir;

String welcome= " -=[::WiFi::]=-";

void setup() {
  lcd.commandWrite(CMD_NOWRAP);
  Serial.begin(9600);         // set the baudrate
  lcd.init();                 // initialize
  lcd.clear();                // clear the screen
  lcd.printIn(welcome);   // display something
}

void loop()
{
  //lcd.clear();
  //lcd.printIn("   waiting    ");
  int i=0;
  int o=0;
  if (Serial.available()) {        //something's coming
    delay(900);                                                                   //wait for it
    lcd.clear();                                                                   //clear the old junk
    while (Serial.available()) {  
      data1 = Serial.read();                                               //import a letter at a time
      topData.append(data1);
      if (data1 == '\n'){                                                     //encounters a carriage return
        while (Serial.available() && data2!='\n') {               //break if I get a \n on the second line
          data2 = Serial.read();                                         //save line 2 data
          botData.append(data2);
          o++;                                                                  //get the next letter
        }
      }
      i++;                           //get the next letter
    }
  }
  //int p=0;                       //init stuff
  int t=0;
  int b=0;
  int big=0;
  int count=0;
  if (i>o){                          //find out what string is longest
    big=i;
  }
  else {
    big=o;
  }
  if (i!=0){                                                            //if data received through Serial input
    for(count=0;count<big;count++){                      //do this until the end of the longest string
      for(t=0;t<15;t++){                                         //set the temp display lines up 16 chars at a time
        topFir.setCharAt(t, topData.charAt(t));        //top line
        botFir.setCharAt(t, botData.charAt(t));       //bottom line
      }
      lcd.cursorTo(1,0);                                        //start from 1
      lcd.printIn(topFir);                                       //display most recent 16 chars
      lcd.cursorTo(2,0);                                        //jump to 2
      lcd.printIn(botFir);                                       //""
      for(t=0;t<big;t++){                                       //time to shift the input data over 1 char at a time
        topData.setCharAt(t, topData.charAt(t+1));
        botData.setCharAt(t, botData.charAt(t+1));
      }
      delay(500);                                                 //psuedo-scroll
      lcd.clear();                                                 //don't blink!
      delay(500);                                                //probably don't need this
    }
  }
  topData=0;                                                   //clear cache out
  botData=0;
  topFir=0;
  botFir=0;
  i=0;
  o=0;
  t=0;
  count=0;
}

I'm trying to defeat to 40 character max by re-writing the data strings grabbed from each line of the serial output to something that is 16 characters at a time, then clearing the LCD cache and printing the new strings for a scroll 'effect'. For some reason, the lcd doesn't display any text input [edit]whatsoever[/edit] it displays the welcome string. :cry:

Any thoughts?
NelsonPJ
Posts: 13
Joined: Sun Jun 28, 2009 7:31 am

Re: Question about LCD interfacing

Post by NelsonPJ »

Did you ever get your Arduino working with this project? Just yesterday I got my router playing music with mpc/mpd (woo hoo!) and last winter I successfully interfaced a 16x2 LCD to an Arduino and managed to display "Hello World". I haven't linked the two together yet, so I was wondering if somebody's already got code they could share. From reading your post above, it sounds like the code you posted didn't quite work? Did you ever figure it out?
Post Reply