Hello.
A couple of days ago I tried to realize a little idea of mine...
I used 2 standalone Atmega328 on a breadboard: the first one runs a sketch that uses the PS2Keyboard lib to read the input from a PS2 keyboard, the second one has a sketch inside che reads the input from the first Atmega and then sends the output on the TV.
But I'm having a strange problem: keys that I see on the TV are different from the ones I press on the keyboard.... I.E. I get [ESC] from "h" or "3[ESC]" from "7" etc...
Strange because if I connect the first Atmega to an Arduino and send the keys I read from the keyboard to a serial terminal open under the Arduino IDE I can see the correct keys (i.e. if I digit "h"-"e"-"l-"l"-"o" I see "hello"), so I can say for sure that the connection of the keyboard is OK. It seems that "pollserial" doesn't read the correct datas.
I connected the 2 Atmega using pins 2 and 3 (RX & TX): of course, 2->3 and 3->2.
This is the sketch on the first Atmega:
/* PS2Keyboard library example*/
#include <PS2Keyboard.h>
const int DataPin = 2;
const int IRQpin = 3;
PS2Keyboard keyboard;
void setup() {
delay(2000);
keyboard.begin(DataPin, IRQpin);
Serial.begin(9600);
}
void loop() {
if (keyboard.available()) {
// read the next key
char c = keyboard.read();
// check for some of the special keys
if (c == PS2_ENTER) {
Serial.println();
} else if (c == PS2_TAB) {
Serial.print("[Tab]");
} else if (c == PS2_ESC) {
Serial.print("[ESC]");
} else if (c == PS2_PAGEDOWN) {
Serial.print("[PgDn]");
} else if (c == PS2_PAGEUP) {
Serial.print("[PgUp]");
} else if (c == PS2_LEFTARROW) {
Serial.print("[Left]");
} else if (c == PS2_RIGHTARROW) {
Serial.print("[Right]");
} else if (c == PS2_UPARROW) {
Serial.print("[Up]");
} else if (c == PS2_DOWNARROW) {
Serial.print("[Down]");
} else if (c == PS2_DELETE) {
Serial.print("[Del]");
} else {
// otherwise, just print all normal characters
Serial.print(c);
}
}
}
This is the sketch that is running on the second Atmega:
#include <TVout.h>
#include <pollserial.h>
#include <fontALL.h>
TVout TV;
pollserial pserial;
void setup() {
TV.begin(_PAL,120,96);
TV.select_font(font6x8);
TV.println("Terminale seriale");
TV.println("-- Versione 0.1 --");
TV.set_hbi_hook(pserial.begin(9600));
}
void loop() {
if (pserial.available()) {
TV.print((char)pserial.read());
}
}