u8glib question

Hi,

I'm learning how to use the u8glib with my A-MEGA2560 and a cheap oled display I got off ebay. Everything works great, I can draw and print to the display however I'm stuck on how to print/draw a char to the display. I can use u8g.print ( inByte, DEC ) and get the decimal ASCII number displayed or I can choose 'BIN' or 'HEX' to display the number in octal or hexadecimal. I can also use u8g.drawStr (x,y,str) to print a string or char.

My question is which function can I use to display an ascii number as a char? I know I can print a constant char or str but how do I go the other way? Casting other method?

For example consider this:

void loop() {
if (Serial1.available()) {
int inByte = Serial1.read();

Serial1.write( inByte ); // Echo char

u8g.firstPage();
do {
u8g.setFont(u8g_font_profont22);
u8g.setPrintPos ( 0, 16 );
u8g.print ( inByte, DEC ); // Displays the variable as a decimal ASCII
u8g.drawStr ( 100, 16, inByte ); // Error

} while( u8g.nextPage() );
}
}

When I get the byte from the serial port and display it I get the ASCII number not the char. Is there a serial.write() equivalent in u8glib?

tnx,

Hi

I think, this is more a programming question :wink:

I usually use this:

char s[2] = " ";    // a global or local variable, which will contain a blank (1st char) and a '\0'

s[0] = ascii_number;  // overwrite the blank with the desired ascii code
u8g.print(s);     // print the string

Oliver

Interesting and intelligent solution :slight_smile:

A one char null terminated string... never crossed my mind, I must be getting old :wink:

Thanks

robert