I simply need to take "char c = keyboard.read();" and make it into an array reading the bytes from the keyboard and sending the array across the serial port when I press enter. I need to do this to avoid the serial time out. I will send a string like this 12.900.14.14 then when I press enter it sends it as one string across the serial port.
please help me finish this project
thanks
doulos
// arduino serial terminal
#include <PS2Keyboard.h>
#include "Wire.h"
#include "LiquidCrystal.h"
LiquidCrystal lcd(0);
int reset_pin = 13;
const int DataPin = 3;
const int IRQpin = 2;
PS2Keyboard keyboard;
void setup() {
pinMode(reset_pin, OUTPUT);
digitalWrite(reset_pin, LOW);
delay(1000);
keyboard.begin(DataPin, IRQpin);
Serial.begin(9600);
delay(1000);
lcd.begin(16, 2);
lcd.setBacklight(HIGH);
lcd.setCursor(0, 0);
lcd.print(":");
}
void loop() {
if (keyboard.available(){
char c = keyboard.read(); // I need to make char c an array
lcd.print (c); // and i also need to print char c= keyboard.read(); one char at a time on the lcd
if (c == PS2_ENTER) {
//then send the array accross the serial port here to avoid serial timeout
Serial.println();
delay(20);
lcd.clear();
delay(10);
lcd.print(":");
} else if (c == PS2_DELETE) { // this is using pin 13 to reset another arduino
lcd.print("reset");
digitalWrite(reset_pin , LOW);
delay(2000);
digitalWrite(reset_pin , HIGH);
lcd.clear();
} else {
}
}
}
yes I was and that part of the code works the whole thing works as it reads single chars and prints them, but I need to store keyboard.read(); as an Array and send it in 1 chunk when it sees 'PS2_ENTER' and I don't know how to do that. If I just stream my input the Serial port pings and I have 4 seconds to enter my string. I even know the max buffer I'll use as it is a 16 char display so char line [17]
I understand the concept I just don't know how to impliment it.
I need to have storage for the max array something like
char line [17] ; // max array length above void setup
int count = 0 ; // a counter above void setup
Ok then think of it like this. You want to enter an array of chars and send it when you press enter, so if the incoming chars are NOT "!=" EQUAL to "enter", store it, else print / write it.
doulos24:
yes I was and that part of the code works the whole thing works as it reads single chars and prints them, but I need to store keyboard.read(); as an Array and send it in 1 chunk when it sees 'PS2_ENTER' and I don't know how to do that. If I just stream my input the Serial port pings and I have 4 seconds to enter my string. I even know the max buffer I'll use as it is a 16 char display so char line [17]
I understand the concept I just don't know how to impliment it.
char line [17] ; // max array length above void setup
int count = 0 ; // a counter above void setup
//then something like
//in the void loop
/*
void loop() {
if keyboard.available () > 0 {
line[count] == (char)keyboard.read();
if (line[count++] == 'PS2_ENTER'
line[count] = '\0'; // zero-terminate
Serial.print(line); // print array
delay(20);
count =0; // reset counter
}
}
//but this doesn't work so can I get some help?
*/
I can read my PC keyboard through serial monitor while in the IDE, or hyperterminal which I can copy content from. On Arduino I read that through Serial as in Serial.begin(), Serial.available() and Serial.Read. Some terminals send keys as hit and some send whole lines when enter is hit.
What keyboard you got? What Arduino are you using?
I dont think the serial terminal is important the point is I'm making my own terminal this is not connected to a computer at all the concept is this using two arduinos 1 freeduino and 1 arduino mega.
read the PS2 keyboard.read(); as an array // on the freeduino
read the keyboard.read(); input to a lcd screen as well // on the freeduino
when PS2_ENTER is read
send the array to the mega via hardware serial pins 0 and 1
or even software pins 10 and 11
or even i2c
whatever works
read the serial stream on the mega
say 12.900.12.12
parse the input
and run the code on the mega
in a perfect world I'd like to get back the mega data on the uno lcd
but I can deal with 2 lcd screens using i2c no big deal there
Ok then, lets start from what you are able to get. BTW, your lcd address should not be just 0, it should be something like 0x20 or 0x??, otherwise it won't show anything.
doulos24:
I dont think the serial terminal is important the point is I'm making my own terminal this is not connected to a computer at all the concept is this using two arduinos 1 freeduino and 1 arduino mega.
read the PS2 keyboard.read(); as an array // on the freeduino
read the keyboard.read(); input to a lcd screen as well // on the freeduino
when PS2_ENTER is read
send the array to the mega via hardware serial pins 0 and 1
or even software pins 10 and 11
or even i2c
whatever works
read the serial stream on the mega
say 12.900.12.12
parse the input
and run the code on the mega
in a perfect world I'd like to get back the mega data on the uno lcd
but I can deal with 2 lcd screens using i2c no big deal there
Do you think that you could convert code that processes commands on Serial to use your devices instead? There's free examples of things like that for Serial.
Ok then, lets start from what you are able to get. BTW, your lcd address should not be just 0, it should be something like 0x20 or 0x??, otherwise it won't show anything.
Bed now, see you in 8 hours.
your somehow asuming this code doesn't work it does
this is just I2C address stating this is the first lcd screen on the i2c
it works fine. i.e. // Connect via i2c, default address #0 (A0-A2 not jumpered)
from Adafruits liquid crystal library
Do you think that you could convert code that processes commands on Serial to use your devices instead? There's free examples of things like that for Serial.
no sorry it needs to be stand alone all this crap is controlling another pc already that is running code and autohotkey scripts. The purpose of the terminal is to eliminate having to enter a serial terminal to send this which already works to avoid hardware timeouts on another microprocessor device.
So when you press a key, your able to see its value on the lcd? Ok, so then store it in an array, and keep storing the chars until enter is pressed.
void loop() {
if (keyboard.available () > 0) {
KB_chars = keyboard.read(); // new variable "KB_chars", instead of "c". Better name.
if ( KB_chars != PS2_ENTER){ //If the key(s) pressed is not PS2_ENTER, then store chars in array
line[count++] = KB_chars;
Serial.print(line[count]); // show chars being entered.
}
else { // If PS2_ENTER is pressed, print them.
line[count++] = '\0'; // once enter is pressed, count +1 then add zero-terminate
Serial.print(line); // Not sure if it will work like this, might need to convert it to a string first. I'll double check. print array
//delay(20);
count = 0; // reset counter
}
}
}
here is the example code stripped Ill re add my code wen this works!
/* PS2Keyboard library example
PS2Keyboard now requries both pins specified for begin()
keyboard.begin(data_pin, irq_pin);
Valid irq pins:
Arduino: 2, 3
Arduino Mega: 2, 3, 18, 19, 20, 21
Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16
Teensy 2.0: 5, 6, 7, 8
Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
Sanguino: 2, 10, 11
for more information you can read the original wiki in arduino.cc
at http://www.arduino.cc/playground/Main/PS2Keyboard
or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
Like the Original library and example this is under LGPL license.
Modified by Cuninganreset@gmail.com on 2010-03-22
Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
#include <PS2Keyboard.h>
const int DataPin = 3;
const int IRQpin = 2;
PS2Keyboard keyboard;
void setup() {
delay(1000);
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_DELETE) {
Serial.print("[Del]");
} else {
// otherwise, just print all normal characters
Serial.print(c);
}
}
}