Go Down

Topic: LCD4884 and serial communication. (Read 3455 times) previous topic - next topic

nend

Apr 21, 2012, 09:44 am Last Edit: Apr 21, 2012, 09:52 am by nend Reason: 1
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: [Select]
#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);
}

olikraus

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

nend

@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. 

olikraus

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

Oliver

nend

#4
Apr 21, 2012, 03:32 pm Last Edit: Apr 24, 2012, 10:15 am by nend Reason: 1
@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: [Select]
#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);
}

nend

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??

olikraus

instead of
Code: [Select]

itoa(val, string, 10);

use
Code: [Select]

string[0] = val;
string[1] = '\0';


Oliver

nend

@Oliver,

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

Greet Dave

gelno

#8
Jul 26, 2012, 05:45 pm Last Edit: Jul 26, 2012, 05:47 pm by gelno Reason: 1
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: [Select]

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

thoger

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);

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy