Society of Robots - Robot Forum

Software => Software => Topic started by: spizzak on July 29, 2009, 09:27:08 PM

Title: Serial LCD with ATMega8
Post by: spizzak on July 29, 2009, 09:27:08 PM
I am having trouble getting my LCD to work properly. This is the code im giving it (the analog sensor is the SharpIR).


Code: [Select]
while(1)
{

delay_cycles(23000);
ledon();
delay_cycles(23000);

sensorx=a2dConvert8bit(5);

delay_cycles(23000);
ledoff();
delay_cycles(23000);

rprintf("THE VALUE IS:  %d\r\n", sensorx);



delay_cycles(23000);

}

And this is what its giving:

Can anyone give any ideas what the extra characters might be? Are they missing from my numbers or should my numbers be the ones I'm getting and the characters are just extra? Any ideas?
Title: Re: Serial LCD with ATMega8
Post by: Webbot on July 30, 2009, 01:02:47 PM
Its not clear what your problem is. You mention 'extra characters' but don't say what they are.
Title: Re: Serial LCD with ATMega8
Post by: spizzak on July 30, 2009, 01:27:07 PM
In the attached picture you can see "VALUE IS: 52###" The ### is where the weird characters are..
Title: Re: Serial LCD with ATMega8
Post by: guncha on July 30, 2009, 08:45:51 PM
It could be any number of things. Try printing just the number or just the text, like so rprintf("WAKAWAKA\r\n"); or maybe it's that you don't need both \r and \n. Who knows..
Title: Re: Serial LCD with ATMega8
Post by: spizzak on July 31, 2009, 08:00:14 AM
The other thing is, whenever I try sending any special commands like to clear the screen or reset the cursor location the LCD freezes.. I can write plain text to it no problem but when I send those it freezes until i reboot it... any ideas on what could be causing that? Is there a really simple program that I can use to test the LCD without using all the libraries?
Title: Re: Serial LCD with ATMega8
Post by: Stephanie on July 31, 2009, 02:16:14 PM
The weird characters seem to be extra.

Try this (don't change anything in the rprintf statements, there are extra and missing whitespaces on purpose):
Code: [Select]
while(1)
{

delay_cycles(23000);
ledon();
delay_cycles(23000);

sensorx=a2dConvert8bit(5);

delay_cycles(23000);
ledoff();
delay_cycles(23000);

if (sensorx < 10) {
rprintf("SHARP IR READING:  %d\r\n", sensorx); //19 fixed characters, 1 for variable
} else if (sensorx < 100) {
rprintf("SHARP IR READING: %d\r\n", sensorx); //18 fixed characters, 2 for variable
} else {
rprintf("SHARPIR READING: %d\r\n", sensorx); //17 fixed characters, 3 for variable
}


delay_cycles(23000);

}
Let me know if it works.
Title: Re: Serial LCD with ATMega8
Post by: spizzak on August 03, 2009, 04:34:04 PM
If I remove the \r\n it prints just the number like I wanted it to. But I still cant get it to print any of the special commands.
Title: Re: Serial LCD with ATMega8
Post by: Webbot on August 03, 2009, 06:31:31 PM
Hi spizzak
We've already covered this in another thread.
Did you try using hypertimal or realterm to make sure your serial output is as expected?
Title: Re: Serial LCD with ATMega8
Post by: spizzak on August 03, 2009, 08:03:56 PM
I dont have the required hardware to use Hyperterminal
Title: Re: Serial LCD with ATMega8
Post by: Webbot on August 04, 2009, 07:43:46 PM
You really need to get a level shifter ie from TTL levels to RS232 or UART. Or make your own using Max232 etc. Depending on whether your PC has serial port and/or only UART.

Or if you can afford the extra bucks then a wireless link back to your PC.

This is a fundamental debugging kit. Without it then its hard to tell if your code is wrong, mis-behaving, or whether it is something else.

Ok its yet another 'one off cost' and you were probably hoping to use the LCD for debugging output instead. Which is fine once you get the LCD working (chicken and egg!)

The only other suggestion I can make in the interim, without a pc connection) is to go back to Sparkfun (where you bought the LCD) and see whats on their support forums.

Title: Re: Serial LCD with ATMega8
Post by: flimflap on August 06, 2009, 07:41:12 AM
I always used a usb -> ttl converter chip. Same chip sparkfun used in:
http://www.sparkfun.com/commerce/product_info.php?products_id=718