typing EXTENDED ascii characters using arduino micro as a HID

Concise description of problem:

I am attempting to use an Arduino Micro to print an extended ascii character (Â) in notepad on a windows computer. (The symbol  is ascii decimal character 0194.)

Using a regular, physical PC keyboard this can be accomplished by pressing and holding the right alt key and then pressing and releasing consecutively 0 then 1 then 9 then 4 ON THE KEYPAD AT THE RIGHT OF PC KEYBOARDS then releasing the right alt key. Upon releasing the alt key the symbol  appears on screen. This process does NOT work if you try using the numbers on the TOP of your keyboard.

For example;

Keyboard.press ('9');
Keyboard.release ('9');

This code will print into notepad the number 9 but not using the numbers from the keypad to the right.

Therefore the following code does NOT produce the symbol Â:

char altKey = KEY_RIGHT_ALT;

void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);

// attempt to print ascii character decimal 0194
Keyboard.press(altKey);
delay(100);
Keyboard.press('0');
delay(100);
Keyboard.release('0');
delay(100);
Keyboard.press('1');
delay(100);
Keyboard.release('1');
delay (100);
Keyboard.press('9');
delay(100);
Keyboard.release('9');
delay (100);
Keyboard.press('4');
delay(100);
Keyboard.release('4');
delay (100);
Keyboard.release(altKey);

delay(1000);
}

If you know how to print the symbol  using an arduino micro by some verified method please help me.

Hello and welcome :slight_smile:

Have you tried with Keyboard.write?

I can't verify this because I never used a keyboard with an arduino.

if you want to write to text editor the character , can you test the following code for me since i do not own an compatible device for that library, and tell the results?

void setup() {
Keyboard.begin();

}

void loop() {

Keyboard.print("Â");
delay(1000);

Keyboard.press(altKey);
delay(100);
Keyboard.print('0194');
delay (100);
Keyboard.release(altKey);
delay(1000);
}

edit also check the other funcitons on the keyboard library;
http://arduino.cc/en/Reference/MouseKeyboard

The following code based on your suggestion also does not work:

char altKey = KEY_RIGHT_ALT;

void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);

// print ascii character decimal 194
Keyboard.press(altKey);

Keyboard.write ('0');
Keyboard.write ('1');
Keyboard.write ('9');
Keyboard.write ('4');

Keyboard.release(altKey);

delay(1000);
}

The following three techniques don't work:

1.)

Keyboard.print("Â");

2.)

Keyboard.print('Â');

3.)

Keyboard.press(altKey);
delay(100);
Keyboard.press('0194');
delay (100);
Keyboard.release(altKey);
delay(1000);

I meant

Keyboard.write( 'Â' );

Also try

Keyboard.press( altKey );
Keyboard.print( "0194" );
Keyboard.release( altKey );

//or
Keyboard.print( "\u1EA6" );

//or
Keyboard.write( 0xC3 );
Keyboard.write( 0x82 );

And instead of saying "it doesn't work", give more details... Does it print nothing in your file, or does it print other character(s) and if yes, which one(s)?

please note that i had eddited my post, sorry for that, try this agian;

Keyboard.press(altKey);
delay(100);
Keyboard.print('0194');
delay (100);
Keyboard.release(altKey);
delay(1000);

edit; i see that Guix post covered this aswell now :smiley:

nick

guix:
I meant

Keyboard.write( 'Â' );

Also try

Keyboard.press( altKey );

Keyboard.print( "0194" );
Keyboard.release( altKey );

//or
Keyboard.print( "\u1EA6" );

//or
Keyboard.write( 0xC3 );
Keyboard.write( 0x82 );




And instead of saying "it doesn't work", give more details... Does it print nothing in your file, or does it print other character(s) and if yes, which one(s)?

Technique 1 and 2 do nothing discernable

Keyboard.print( "\u1EA6" ); produces an output 1\1

Technique 4 causes the menu header to be highlighted as if alt were pressed

Sorry that was the wrong code, try

Keyboard.print( "\u00C2" );

If it doesn't work, then I'm out of ideas. Maybe it's just impossible to do.

well, the library reference does state this:
Note: Not every possible ASCII character, particularly the non-printing ones, can be sent with the Keyboard library.

i think you should proceseed this diffrently and try serial library, emulate arduino as a keyboard, and than try printing the character as the serial library has more potential on the software-end. what i mean is, you could try write a driver of some sort listening to the com port your arduino is on, and use the driver to print/write the characters.

nick

i know that the serial monitor can render  with the code:

Serial.println("\xc2"); // where xc2 is the numerical HTML encoding of the Unicode character

It is not apparent how I how can use this fact to print an extended ascii character to a window.

i am not saying to simply use print(); or println();

i mean this process:

program: start ->> program: bind to window ->> *avr:*start serial ->> program: listen to com1 ->>
avr: Serial.print("0194"); ->> com port 1 ->> program: read 0194 on com1 ->> program: print "Â" to binded window ->> result as you wanted?

where
program= the program running on the computer written in a different compiler (for example c++ compilers)
avr = the arduino device you are using
com port 1 = the usb port your arduino is connected to

nick

The USB key codes for the numeric keypad are 89 through 98 (1-9 and 0). To get a raw USB keycode through Keyboard.press(), Keyboard.write(), or Keyboard.release() you have to add the magic number 136 to it.

Try this:

const byte Keypad_1 = 225;
const byte Keypad_2 = 226;
const byte Keypad_3 = 227;
const byte Keypad_4 = 228;
const byte Keypad_5 = 229;
const byte Keypad_6 = 230;
const byte Keypad_7 = 231;
const byte Keypad_8 = 232;
const byte Keypad_9 = 233;
const byte Keypad_0 = 234;

 Keyboard.press(KEY_RIGHT_ALT);
 Keyboard.write (Keypad_0);
 Keyboard.write (Keypad_1);
 Keyboard.write (Keypad_9);
 Keyboard.write (Keypad_4);
 Keyboard.release(KEY_RIGHT_ALT);

For other keys, see this table:

USB CODE	Keyboard()	Key Location on US-en Keyboard
========	==========	==============================
0	0x00				Reserved (no event indicated) *9
1	0x01				Keyboard ErrorRollOver *9 
2	0x02				Keyboard POSTFail *9 
3	0x03				Keyboard ErrorUndefined *9 
4	0x04	140	0x8C	Keyboard a and A *4 
5	0x05	141	0x8D	Keyboard b and B 
6	0x06	142	0x8E	Keyboard c and C *4 
7	0x07	143	0x8F	Keyboard d and D 
8	0x08	144	0x90	Keyboard e and E 
9	0x09	145	0x91	Keyboard f and F 
10	0x0A	146	0x92	Keyboard g and G 
11	0x0B	147	0x93	Keyboard h and H 
12	0x0C	148	0x94	Keyboard i and I 
13	0x0D	149	0x95	Keyboard j and J 
14	0x0E	150	0x96	Keyboard k and K 
15	0x0F	151	0x97	Keyboard l and L 
16	0x10	152	0x98	Keyboard m and M *4 
17	0x11	153	0x99	Keyboard n and N 
18	0x12	154	0x9A	Keyboard o and O *4 
19	0x13	155	0x9B	Keyboard p and P *4 
20	0x14	156	0x9C	Keyboard q and Q *4
21	0x15	157	0x9D	Keyboard r and R
22	0x16	158	0x9E	Keyboard s and S *4
23	0x17	159	0x9F	Keyboard t and T
24	0x18	160	0xA0	Keyboard u and U
25	0x19	161	0xA1	Keyboard v and V
26	0x1A	162	0xA2	Keyboard w and W *4
27	0x1B	163	0xA3	Keyboard x and X *4
28	0x1C	164	0xA4	Keyboard y and Y *4
29	0x1D	165	0xA5	Keyboard z and Z *4
30	0x1E	166	0xA6	Keyboard 1 and ! *4
31	0x1F	167	0xA7	Keyboard 2 and @ *4
32	0x20	168	0xA8	Keyboard 3 and # *4
33	0x21	169	0xA9	Keyboard 4 and $ *4
34	0x22	170	0xAA	Keyboard 5 and % *4
35	0x23	171	0xAB	Keyboard 6 and ^ *4
36	0x24	172	0xAC	Keyboard 7 and & *4
37	0x25	173	0xAD	Keyboard 8 and * *4
38	0x26	174	0xAE	Keyboard 9 and ( *4
39	0x27	175	0xAF	Keyboard 0 and ) *4
40	0x28	176	0xB0	Keyboard Return (ENTER) *5 
41	0x29	177	0xB1	Keyboard ESCAPE
42	0x2A	178	0xB2	Keyboard DELETE (Backspace) *13 
43	0x2B	179	0xB3	Keyboard Tab
44	0x2C	180	0xB4	Keyboard Spacebar
45	0x2D	181	0xB5	Keyboard - and (underscore) *4 
46	0x2E	182	0xB6	Keyboard = and + *4
47	0x2F	183	0xB7	Keyboard [ and { *4
48	0x30	184	0xB8	Keyboard ] and } *4
49	0x31	185	0xB9	Keyboard \ and |
50	0x32	186	0xBA	Keyboard Non-US # and ~ *2 
51	0x33	187	0xBB	Keyboard ; and : *4
52	0x34	188	0xBC	Keyboard ‘ and “ *4
53	0x35	189	0xBD	Keyboard Grave Accent and Tilde *4 
54	0x36	190	0xBE	Keyboard , and < *4
55	0x37	191	0xBF	Keyboard . and > *4
56	0x38	192	0xC0	Keyboard / and ? *4
57	0x39	193	0xC1	Keyboard Caps Lock *11
58	0x3A	194	0xC2	Keyboard F1
59	0x3B	195	0xC3	Keyboard F2
60	0x3C	196	0xC4	Keyboard F3
61	0x3D	197	0xC5	Keyboard F4
62	0x3E	198	0xC6	Keyboard F5
63	0x3F	199	0xC7	Keyboard F6
64	0x40	200	0xC8	Keyboard F7
65	0x41	201	0xC9	Keyboard F8
66	0x42	202	0xCA	Keyboard F9
67	0x43	203	0xCB	Keyboard F10
68	0x44	204	0xCC	Keyboard F11
69	0x45	205	0xCD	Keyboard F12
70	0x46	206	0xCE	Keyboard PrintScreen *1 
71	0x47	207	0xCF	Keyboard Scroll Lock *11 
72	0x48	208	0xD0	Keyboard Pause *1
73	0x49	209	0xD1	Keyboard Insert *1
74	0x4A	210	0xD2	Keyboard Home *1
75	0x4B	211	0xD3	Keyboard PageUp *1 
76	0x4C	212	0xD4	Keyboard Delete Forward *1;*14 
77	0x4D	213	0xD5	Keyboard End *1
78	0x4E	214	0xD6	Keyboard PageDown *1 
79	0x4F	215	0xD7	Keyboard RightArrow *1 
80	0x50	216	0xD8	Keyboard LeftArrow *1 
81	0x51	217	0xD9	Keyboard DownArrow *1 
82	0x52	218	0xDA	Keyboard UpArrow *1
83	0x53	219	0xDB	Keypad Num Lock and Clear *11 
84	0x54	220	0xDC	Keypad / *1
85	0x55	221	0xDD	Keypad * 
86	0x56	222	0xDE	Keypad - 
87	0x57	223	0xDF	Keypad + 
88	0x58	224	0xE0	Keypad ENTER *5
89	0x59	225	0xE1	Keypad 1 and End
90	0x5A	226	0xE2	Keypad 2 and Down Arrow
91	0x5B	227	0xE3	Keypad 3 and PageDn
92	0x5C	228	0xE4	Keypad 4 and Left Arrow
93	0x5D	229	0xE5	Keypad 5 
94	0x5E	230	0xE6	Keypad 6 and Right Arrow
95	0x5F	231	0xE7	Keypad 7 and Home
96	0x60	232	0xE8	Keypad 8 and Up Arrow
97	0x61	233	0xE9	Keypad 9 and PageUp
98	0x62	234	0xEA	Keypad 0 and Insert 
99	0x63	235	0xEB	Keypad . and Delete
100	0x64	236	0xEC	Keyboard Non-US \ and | *3;*6
101	0x65	237	0xED	Application *10
102	0x66	238	0xEE	Keyboard Power *9
103	0x67	239	0xEF	Keypad =
104	0x68	240	0xF0	Keyboard F13
105	0x69	241	0xF1	Keyboard F14
106	0x6A	242	0xF2	Keyboard F15
107	0x6B	243	0xF3	Keyboard F16
108	0x6C	244	0xF4	Keyboard F17
109	0x6D	245	0xF5	Keyboard F18
110	0x6E	246	0xF6	Keyboard F19
111	0x6F	247	0xF7	Keyboard F20
112	0x70	248	0xF8	Keyboard F21
113	0x71	249	0xF9	Keyboard F22
114	0x72	250	0xFA	Keyboard F23
115	0x73	251	0xFB	Keyboard F24
116	0x74	252	0xFC	Keyboard Execute
117	0x75	253	0xFD	Keyboard Help
118	0x76	254	0xFE	Keyboard Menu
119	0x77	255	0xFF	Keyboard Select  




(END OF CODES REACHABLE FROM Keyboard.write)