Arduino Forum

Using Arduino => Project Guidance => Topic started by: O_rly on Aug 28, 2016, 07:41 pm

Title: Taking board inputs
Post by: O_rly on Aug 28, 2016, 07:41 pm
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 :)
Title: Re: Taking board inputs
Post by: OldSteve on Aug 28, 2016, 07:48 pm
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?
Title: Re: Taking board inputs
Post by: PieterP on Aug 28, 2016, 08:15 pm
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 (https://processing.org/).
Title: Re: Taking board inputs
Post by: sterretje on Aug 28, 2016, 08:26 pm
Or use a decent terminal program ;)
Title: Re: Taking board inputs
Post by: MarkT on Aug 28, 2016, 08:27 pm
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.
Title: Re: Taking board inputs
Post by: PieterP on Aug 28, 2016, 08:29 pm
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.
Title: Re: Taking board inputs
Post by: OldSteve on Aug 28, 2016, 08:41 pm
Indeed, but if you want, you can write a simple program to send the keystrokes directly, using Processing (https://processing.org/).
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.
Title: Re: Taking board inputs
Post by: larryd on Aug 28, 2016, 09:59 pm
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.


.
Title: Re: Taking board inputs
Post by: INTP on Aug 29, 2016, 05:43 pm
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.