Using Unsigned Chars in Arduino

Hi folks,
I'm starting to get into the Arduino world, and stumbled across an interesting issue I can't seem to find an answer for.

I'm writing a software that receives Char arrays from the computer, and writes them to an LCD (currently digole, will be switched over to u8glib once the hardware gets here).

un-fortunatly they data structure is such, that I need to box out specific letters in the string.
transferring two 130 byte arrays and iterrating over them to mark the correct chars is very cycle costly.
to save that, I've decided to create a custom font that has the highlighted chars as such in the first place (i.e, data only contains capital letters, so lower case is now a mirror image font of the uppercase). but data also contains other chars that need highlighting, (asterisks, numbers, punctuation marks etc.) I've put all those into an 128 char num offset compated to the real char. (i.e space is 32, invertspace is 160). and as ASCII is 127 chars (7 bit) I can use 8 bits instead (255 chars, which is more then enough).

but when I try and print the data (byte, unsigned char or uint8_t) in only prints out char number or just throws an exception as Strings cannot contain unsigned chars.
before I go over the code and try and compress everything into 7 bits (not sure it's even possible, as I cannot print control chars in a string, even with custom font), is there a method that I've missed to handle more then 127 chars on arduino?

I get the impression that for every 7 bit ascii character you have a matching 8 bit character - for example 0x41 and 0xC1 both give A.

If that is correct you could convert both of them to 0x41 by masking off the high bit myVal= myVal &= B01111111

Of course I may have the wrong end of the stick altogether.

...R

Your concern seems misconceived.

I don't believe your claim that "strings can only contain unsigned chars". Many character sets allocate characters to the single byte values 0x80 to 0xFF,

just throws an exception

on an arduino ?

as Strings cannot contain unsigned chars.

Do you mean Strings or do you mean strings ?

I suspect the OPs problem is that Serial.print(byte) produces the ascii value whereas Serial.print(char) produces the character. And since he wants to use bytes (unsigned chars) using the high byte he can't get them to print the way he wants.

Actually the answer is probably to use Serial.write(byte) rather than Serial.print()

...R

UKHeliBob:

as Strings cannot contain unsigned chars.

Do you mean Strings or do you mean strings ?

Now the Noob is asking,
is there a difference?

AFAIK, I'm sending over a full byte of data for each char. containing the high bit to allow the 128-255 range

Robin2:
I get the impression that for every 7 bit ascii character you have a matching 8 bit character - for example 0x41 and 0xC1 both give A.

If that is correct you could convert both of them to 0x41 by masking off the high bit myVal= myVal &= B01111111

Of course I may have the wrong end of the stick altogether.

...R

This is somewhat correct, but on on that specific example.

for each sign I have two versions. one the basic is Black on white background (i.e the letter pixals are 1).
the other version is the inverse. i.e White letter on black background.
for all letters, the inverse is assigned to the lower case, which works perfectly.

numbers of example are a problem,
'0' is 0X30 so I've put the inverted '0' on 0xb0 (which is the degree sign in extended ascii)
but I can't call it.

I'm re-arraging the font now, it will add more complexity (no more the equivalent of "(char)+128)"), but I have an issue that strings (Strings?) in Arduino (or is it just the Digole Library) does not print the ASCII control characters (char < 32) - or at least the few I tested.

Robin2:
I suspect the OPs problem is that Serial.print(byte) produces the ascii value whereas Serial.print(char) produces the character. And since he wants to use bytes (unsigned chars) using the high byte he can't get them to print the way he wants.

Actually the answer is probably to use Serial.write(byte) rather than Serial.print()

...R

Hi Robin,
it's more complex, I use Serial.readBytes, which works just fine. problem is that I'm not doing serial transmission, the next hop is to a SPI display, where the library cant print the higher chars, and there is not "write" equiv that I know of.

Is my problem is clearer now?

Strings are things that are represented by a Class in C++ and which use complex memory management which doesn't work well in the small memory of an Arduino - don't use them.

strings (small s) are just arrays of bytes or chars with a 0 byte at the end to indicate the end of the string.

Byte arrays can obvously hold any byte value.

The problem seems to be how the value is interpreted for output to the display device.

What methods are available in your SPI library? Is it only limited to working with 128 characters? If it can work with 256 characters then it must be able to use byte values to index the characters.

...R

sorry for popping up the thread.
I've managed to narrow down my problem to the data transfer protocol, it seems that I've sent the data in some malformed way causing display issues.
Thank you all for your help.