Pages: [1]   Go Down
Author Topic: LCD4884 and serial communication.  (Read 3197 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm newbie in arduino and my first project I'm alredy stuck, so my question is:

How can I display the letters on my display when I use serial com.
I want to display the letters that I type in the serial monitor to show on my display.
I already managed to display the numeric code (100 = d (ascii)) but i want to display the “d” and not the corresponding number.

see the code I've inserted with this post.

Thanks
Code:
#include "LCD4884.h"

int val = 0;
char string[10];

void setup() {
  lcd.LCD_init();
  lcd.LCD_clear();
  lcd.backlight(OFF);
  Serial.begin(9600);
}

void loop () {
    while (Serial.available() == 0);
    val = Serial.read();
    Serial.println(val);
    itoa(val, string, 10);
    
    lcd.LCD_write_string(0, 0, string, MENU_NORMAL);

  delay(100);
}
« Last Edit: April 21, 2012, 02:52:08 am by nend » Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1524
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

U8g has such an example:
http://code.google.com/p/u8glib/source/browse/sys/arduino/Console/Console.pde

I think u8g will also support your PCD8544 based display. Please check http://code.google.com/p/u8glib/wiki/device.

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@olikraus,

I've looked at it but it wasn't made for my lcd (LCD4884).
And it's way to difficult to adjust it for me (newbie).
The only thing I need a answer to how to convert it to a asccii character (so if the arduino received 65 that it display a “a”)
I can make a large switch case loop but I think that there is already a function for that. 
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1524
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh, i understand. I am not an expert on println, but maybe "println((char)val)" helps.

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Oliver,

Thanks for the reply.
just one step closer to the sollution.
serial monitor mirrors now the good charater but how do I get this to get it works with the lcd?
See the code
Code:
#include "LCD4884.h"

int val = 0;
char string[10];
char teststring;

void setup() {
  lcd.LCD_init();
  lcd.LCD_clear();
  lcd.backlight(OFF);
  Serial.begin(9600);
}

void loop () {
    while (Serial.available() == 0);
    val = Serial.read();
    Serial.println((char)val);
    itoa(val, string, 10);
    
    lcd.LCD_write_string(0, 0, string, MENU_NORMAL);
  delay(100);
}
« Last Edit: April 24, 2012, 03:15:42 am by nend » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Know one knows the answer to it??

It's just a simple conversion problem (it's just that I don't have enough knowledge of 'c')

The problem is when I type a “d” in the “serial monitor” I get return a “d” but in the diplay I get a “100”
How do I convert the ascii to a letter??
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1524
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

instead of
Code:
itoa(val, string, 10);
use
Code:
string[0] = val;
string[1] = '\0';

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Oliver,

YES!!!
finaly i"m trying this for about 6 hours to get it work.
Thanks for the solution.

Greet Dave
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

So I am very new to Arduino and a beginner programmer at best.  That said, I am having a similar problem nend in the original post.

My setup:
  -Arduino Mega 2560
  -LCD 4884
  -I/O Expansion shield, for Serial-RS485 communication
  -Displacement Laser, communicates of RS485
  -SD Card Logger Shield

What I am trying to do:

  -Send a command over RS485 to the Displacement Laser asking for a measurement, this is working already. Nine (9) characters and a carriage return.
        Should (and does) look like this:  %01#RMD**\r

  -Receive the measurement (a character string) from the Displacement Laser, again over RS485, I am not sure if this is working yet.  Seventeen (17) characters and a carriage return.
        Should look something like this:  %01$RMD-0142901**

  -Display the measurement optimally as just a number and not the character string (I am willing to take baby steps) onto the LCD 4884.
        On the screen it should look something like:  -14.2901 mm or %01$RMD-0142901** would be acceptable
        So far all the screen displays is:  ~'
        I know how to display text and a regular variable, but apparently its not the same as a serially read variable

  -Write/append each new measurement value to a file on the SD card/Logger Shield.  Have not yet gotten this far.


My Code (partly self written, partly from examples far-and-wide on the Internet, partly from this forum post (nend and olikraus), I am ignoring the SD card for the meantime:

Code:
int EN = 20; //RS485 TX/RX enable pin
int x = 0;
char string[10];
char inputStr = 0;

//Included files for LCD4884
#include "LCD4884.h"


void setup()
{
  pinMode(EN, OUTPUT);
  Serial1.begin(9600);
  lcd.LCD_init(); // creates instance of LCD
  lcd.LCD_clear(); // blanks the display
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
}

void loop()
{
 
    // Enable Data Transfer
    digitalWrite(EN, HIGH);
   
    delay(16);
 
    // Ask for Displacement over RS485 (Serial1)
    Serial1.print("%01#RMD**\r");
   
    delay(12);
   
    // Enable Data Recieve
    digitalWrite(EN, LOW);
   
    delay(16);
   
    // Recieve Value over RS485 (Serial)
    inputStr = Serial1.read();
   
    // Convert Serial1 Value
    string[0] = inputStr;
    string[1] = '\0';

    delay(16);
   
    // Display Serial1 Value on LCD4884
    lcd.LCD_write_string(0,1,string,MENU_NORMAL);
   
    delay(16);
   


}

Help is much appreciated!

-Glenn
« Last Edit: July 26, 2012, 10:47:46 am by gelno » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you're only reading one character.

Try:
  char mystring[25];
  int cnt = 0;

  while(Serial.available())   
  {
    mystring[cnt++] = Serial.read(); // receive a byte as character
  };
 
  strncpy(string, mystring, cnt);
  lcd.LCD_write_string(0,1,string,MENU_NORMAL);
Logged

Pages: [1]   Go Up
Jump to: