Keyboard and Symbols

Hello,

I'm trying to write symbols from my arduino to my screen, but it doesn't work like intended.

Using this code:

void setup()
{
  Keyboard.begin();
  delay(3000);
  Keyboard.print("!\"#¤%&/()=?");
  for(int i = 'A'; i < 'Z'; i++)
    Keyboard.write(i);
  for(int i = 'a'; i < 'z'; i++)
    Keyboard.write(i);
}

void loop() {}

I get written to my screen:

!Ä#y%/-)=ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy

The letters are printed out like they should, but only some of the symbols are right. My first guess was some error with the keyboard layout, but I'm using a swedish layout, so it would either have been in swedish (right) or english (wrong), but it wouldn't have included an Ä (swedish letter) if it would have been english.

Any ideas?

I'm not entirely sure this is the right forum, as I don't know if it's a problem with my code or with Arduino.

Jan

Answering my own question:

I had to change the keyboard layout on my computer to English (US). There perhaps should be a note about this somewhere.

Jan

EDIT: Ok, that was only half of the truth, looking through the arduino sources I can confirm that it's a US keyboard (as far as I can understand it), but it seems I'm using the wrong model of keyboard. I've tried Generic 101/102/104/105-key, but they all have the same problem (y instead of ¤ and : instead of ; ). Anybody who knows which model of keyboard works best with the Arduino?

To check, try printing the ascii code of the character being sent by the Arduino.

? The ascii of ; (¤ doesn't seem to exist, so it's ok about that one) is 59, but I get 58 (:slight_smile:

Is this printing on serial monitor or processing or what?

The ascii code is the underlying data of a character. What gets printed depends on the font selected in the displaying program.

This is supposed to write to the screen of a Raspberry Pi (no gui, only console = no special font)

Also: I know what ASCII is :wink:

Then you know you can program the ascii values as integers and have them sent as chars. Did you work out why you are sending 59 and getting 58?

You also know the character you see in the IDE, programmed into your Arduino is not a character, but an ascii code - an 8 bit integer value, being displayed depending on the font selected in the IDE.

So the fact that it does not appear on the Pi screen has nothing to do with symbols, or the keyboard, but the character set enabled in the Pi.

You mean I should try Keyboard.write(59) instead of Keyboard.write(';')? If it's that (I may have missunderstood): I really don't think there's a bug like that in the AVR compiler...

Nope. I mean when you send your funny character, you are sending an ascii code. Do you know what ascii code it is?

The letters are printed out like they should, but only some of the symbols are right.

ASCII is a scheme for mapping numbers <-> characters, yes I know I'm sending an ASCII code.

Also, for some reason Keyboard.write(';') writes an ; now, using my Arduino program that is controlled via another program (on the RPi), it doesn't. I have confirmed that it's a ; that is sent (if(data == ';') digitalWrite(13, !digitalRead(13));), but it still outputs a :

What is the ascii code of the symbols that do not display properly? ( I asked "do you know what ascii code it is", not "do you know what ascii code is"). A subtle but important difference :wink: I know you know what ascii code is. I am asking what is the ascii code of the symbols.

If the ; --> : then it's possible the symbols are doing a similar thing. Or does nothing print at all?

I found out what the problem was:

Typing ; on my swedish keyboard requried me to type Shift + ,
I then sent ; to the arduino, but ; + Shift equaled :, so that's why I got an :
This means I have to remove the Shift and only send ;

Thanks for the help,

Jan