Go Down

Topic: Taking board inputs (Read 814 times) previous topic - next topic

O_rly

Hello everyone, i am 17 and new to learning arduino. I have a project in mind i will be really glad if you can resolve some of my queries.
How do i move my servos in a specific way on pressing a key from my computer's keyboard.
For instance, if i press the 'A' key, Servo 1 should move 20 degrees clockwise, Servo 2 should move 20 degrees anti clockwise. Please help me on how can i take input from the keyboard in such a fashion.
Thank you :)

OldSteve

#1
Aug 28, 2016, 07:48 pm Last Edit: Aug 28, 2016, 07:49 pm by OldSteve
It doesn't quite work like that.

You need to open the serial monitor, enter characters in the input text box, then press [Send] or your keyboard's [Enter] key. This will send the character(s) serially to the Arduino, where the data can be accessed using 'Serial.read()' and the related functions.

Then you can use 'Servo.write()' to move the servo to a particular position, based on the serial input.

Have you written any basic code for controlling servos yet?
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

PieterP

It doesn't quite work like that.

You need to open the serial monitor, enter characters in the input text box, then press [Send] or your keyboard's [Enter] key. This will send the character(s) serially to the Arduino, where the data can be accessed using 'Serial.read()' and the related functions.
Indeed, but if you want, you can write a simple program to send the keystrokes directly, using Processing.

sterretje

Or use a decent terminal program ;)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

MarkT

Split the task into two parts - figure out how to control servos, using code based on the examples,
then figure out how to handle serial input and the various options on your computer for handling
a serial connection.

Only then put the two things together - by then it will make sense, and you are much less likely
to get completely stuck, because you will have an understanding of both aspects already.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

PieterP

Or use a decent terminal program ;)
Indeed, shame I didn't think of that, it's much easier.
However, if you wanted to add clickable buttons to control the motors, you could use Processing.

OldSteve

#6
Aug 28, 2016, 08:41 pm Last Edit: Aug 28, 2016, 08:41 pm by OldSteve
Indeed, but if you want, you can write a simple program to send the keystrokes directly, using Processing.
True, or a C++ app, VB app, etc etc
I regularly write small C++ Windows programs to send/receive serial to/from an Arduino or PIC using a USB to TTL converter, either directly or via an RF transceiver.
What I really meant, but didn't say, was that it can't be done without additional software running on the PC.

Edit: Including terminal program that sends key presses directly, without having to press [Enter], as sterretje implies.

But if all you have is the IDE and an Arduino board, the serial monitor is the only option.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

larryd

#7
Aug 28, 2016, 09:59 pm Last Edit: Aug 28, 2016, 09:59 pm by LarryD
You may want to disconnect from the PC and use push button switches, IR remote or a keypad connected directly to the Arduino.
This way you have a self contained project.


.
No technical PMs.
The last thing you did is where you should start looking.

INTP

Do you already have an Arduino? If not, there are many simple PC USB servo control boards out there that might be easier to work with.

Go Up