I got an Arduino UNO board and I've just begun to learn about Arduino.
This a some code I copied from the forum to test reading computer inputs;
char incomingByte; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(13,OUTPUT);
digitalWrite(13, LOW);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
if (incomingByte == 'h' || incomingByte == 'H')
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
My question is. Where can I press "H"?
I'm monitoring the serial monitor, but no matter where I press H, nothing happens.
Is there a special software I need to send serial inputs to the Arduino?
Thank you for your help!
---------------edit------------------
And just when I wrote the thread I found one answer:
Sorry!
Anyway,
Is there any alternative ways of sending serials?
Like, can I make my computer send serials "whenever" I press a button, without the serial monitor window?
If I would like to add two LED lights (or maybe even a servo in the future), how could I control them from my computer by simply pressing a button on my keyboard? What if I press 2 buttons simultaniously? Is this possible?
CtrlAltElite:
You can use a terminal emulator, like PuTTY, or Hyperterm
Tried PuTTY, works great! Thank you!
BUT! Apparently it can't handle 2 inputs simultainously. It just keeps sending the last input I pressed, so I can't light 2 LED:s simultainously by pressing H and A at the same time.
KeyPressed looks like it involves using a separate keyboard connected to the due? Not what you want.
Serial.read() works great.
If you need more automation on PC side, you can write applications in any language to interact with serial ports (it's pretty easy in python) - examples abound.
The word SERIAL implies sequential communications.
So sending two characters (HA) at the same moment is unlikely...
BUT, it’s pretty fast (I doubt you’ll see any gap!), so you can build a message with two characters, or just type them sequentially and read them in the Arduino when you’re ready.
On the Arduino side, you need to be expecting one or more nominated characters in a single ‘message’. Then act on them in much the same way as you do now.
Work up to it, there are many examples in the forum.
Try searching for serial multiple LEDs ... that might do it.
What is sent to your Arduino over the serial port when you press two keys on the keyboard of your computer is entirely up to the computer, not the Arduino.
Try this experiment, open a text editor (or word processor) and press two keyboard keys at the same time. What do you see? Press return once or more to get a new line. Press and hold two keyboard keys at the same time. What do you see?
What you see for both of the questions in the above paragraph is what your terminal emulator (PuTTY, RealTerm, etc (NOT HyperTerm unless you are masochistic)) will send to your Arduino. Computer keyboards aren't designed for multiple button presses like game controllers are.