Printing Bytes to LCD

Hi,
I've been playing with the LCD functions, and noted that I can't print Bytes to the display, but instead can only print Int. Can anyone explain why this is?

lcd.print(k, BYTE);

:wink:

Thanks, I'll give that a try.

Should work...

If my code is

byte motor=0;
lcd.print(motor);

I get a character block displayed on the screen, where every second pixel line is a solid row of pixels

I also tried the suggestion
lcd.print(motor, BYTE);

but got the same block pattern.

If I change the variable type from byte to int, so that the code is

int motor=0;

Then the lcd.print(motor) command will show the value correctly.

Try motor as int but print as BYTE as mowcius said

int motor=0;
lcd.print(motor, BYTE);

If the variable is an "int" then there is no problem printing to the LCD, so don't need to change the print variable to BYTE. I'm more interested in why a BYTE variable doesn't print. Perhaps there is something in the library format that stops it

If xx is an int then lcd.print(xx) converts the int to (ASCII) chars and sends the chars to the lcd.

If xx is a char or a BYTE (unsigned char) then lcd.print(xx) sends the bits of that char to the lcd.

If you want to print the character value of the least significant eight bits of an int, you can use lcd.print(xx,BYTE);

If you want to print the decimal value of a char or a BYTE, then you can use lcd.print(xx,DEC);

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //Change this for your pins

void setup()
{
    lcd.begin(16, 2);
}

void loop()
{
    byte x = 65;
    int  i = 65;

    lcd.print("x = '");
    lcd.print(x);
    lcd.print("' = ");
    lcd.print(x, DEC);

    lcd.setCursor(0,1);
    lcd.print("i = '");
    lcd.print(i, BYTE);
    lcd.print("' = ");
    lcd.print(i);

    delay(2000);
    lcd.clear();
    delay(500);
}

Output:


x = 'A' = 65
i = 'A' = 65

If the value is not a printable ASCII character, the thing that appears between the quote marks on each line depends on the LCD controller.

For example, if I change the values from 65 to 5, on both lines I see a character with three columns of dots between the quote marks, followed by [i] = 5[/i]

Regards,

Dave

Thanks Dave,
That is a very helpful post. I appreciate your efforts to explain what happens. :slight_smile: