I want to know if it is possible to do a direct comunication between computer and arduino, for axample if I press the arrow key then a sorvo motor will move
At present, the only means of communication between Arduino and PC-based user is the Serial Monitor of the IDE.
You can enter/type "moveF" in the InputBox of the Serial Monitor, press the Send Button; the Arduino will receive the message, decode the message, and then will command the motor to move in the forward direction.
If you want to communicate with the Arduino directly from the Keyboard of the PC and NOT using the Serial Monitor, you have to develop a separate Application Package.
The PC can send commands to the Arduino via the serial port.
For the example you gave, a program running on the PC would read the keyboard and send the appropriate command. See the Serial Input Basics tutorial on this forum for examples.
Not true - anything that can access the serial port can use it to communicate with a connected Arduino.
EDIT: But only 1 thing at a time can use the serial port!
On Arduinos with native USB, other types of communication are possible; eg, HID.
And, of course, there's Bluetooth, WiFi, etc ...
Yes.
That would require software on both the PC and the Arduino:
- On the PC, to recognise the arrow key and send a message/command to the Arduino;
- On the Arduino, to receive the message/command and act upon it.
Arduino, by default, includes a Serial port named "Serial," which is accessible through the Serial Monitor for achieving your objectives. Typically, this "Serial" port is primarily used for debugging output. However, in certain cases, you may repurpose it for keyboard input or controlling devices like motors. Nevertheless, this practice is not recommended.
The common practice, though, is to employ a second Serial Port known as "Serial1" and utilize it in conjunction with an external USB to Serial converter. These converters come in various types.
If you opt for the second approach, you can utilize Serial software applications such as SerialTool (recommended as it is multiplatform www.serialtool.com) or RealTerm (for Windows only RealTerm: Serial/TCP Terminal download | SourceForge.net) to transmit packets and ensure that your application functions as intended. It's essential to implement a read loop to retrieve the packets periodically and respond accordingly to meet your specific requirements.
Make sure you connect and the Serial1 Pins accordingly to your board
This is a simple code snippet with Serial1.
#define SERIAL_BUFFER_LEN 1024 // Define your buffer
void setup ()
{
// ... your code here ...
Serial1.setTimeout (50); // Set your timeout
Serial1.begin(115200); // Set your bitrate
Serial1.println("I am Serial1"); // Print the Hello World message
// ... your code here ...
}
void loop ()
{
char SerialBuffer [SERIAL_BUFFER_LEN];
int iResult;
// ... your code here ...
// Read from Serial1
if (Serial1.available())
{
memset (SerialBuffer, 0, sizeof(SerialBuffer));
iResult = Serial1.readBytes(SerialBuffer, SERIAL_BUFFER_LEN);
if (iResult > 0){
// Parse your Serial1 Buffer as you wish.
// Here you can send the command you want to execute on your motor application
}
}
}
If default Arduino refers to Arduino UNO, then there is no Serial1 Port. Can software UART Port be used?
I only have UNO. I have another question, I think it would be cool to run on the comuter a hand tracking program and then make the servo move when I do somthing with my hand
Of course - bearing in mind its limitations.
EDIT
Sorry, I think I may have misinterpreted your question.
Yes, that could be cool - but what was your question?
That would seem like quite a good division of labour - with the computer doing the data & processing intensive stuff, and the Arduino doing the low-level control stuff.
This plays to the strengths of each system.
Fine you could do that.
However, what language are you programming your computer in? It is unlikely that any app you down load to it would be able to communicate with the serial port. At some stage you would have to use your own code. The Processing language is popular for that, it is free and runs on Mac, Win-dose, and Linux.
What is your experience level at writing code?
I know a few languages. what do I need to know if I have windows?
Is LabView Linx still available?
https://www.labviewmakerhub.com/doku.php?id=libraries:linx:start
This was easy to use once you understood LabView
Probably not, given the
This site was deprecated on August 1, 2020
banner.
I presume LabVIEW itself is still going, though I haven't looked since I left the industry. The cost to play was extremely high unless you were doing continuous development, and my employer insisted on having dozens of staff doing LabVIEW work - individually, none of them did more than a month or two yearly, each with a license sitting unused the rest of the time; then, management complained about the 'huge investment in LabVIEW', but couldn't see that they were squandering the investment in their people. Very strange.
NI offers a free, watered down version of LabView. I was asking about Linx.
You can piece a vi together using the VISA serial functions but linx made it intuitively simple
It is still going on, my son uses it a lot in his work as a test engineer. He has even taken qualifications in it form LabView courses.
I used to teach it at University when it was black and white version 1 and only ran on a Mac, in the late 80s.
This doesn't help OP, however
I used the awful LabWindows in the 80s developing test beds and was introduced to LabView on the Mac in '92. I have the free version on my personal laptop.
Now back to the question of how to write code to develop a GUI on your PC to communicate to an Arduino, Linx made it easy. The only other way I've experienced is with VB 6.0 and Visual C++. VB is no longer available and VC++ is not for a beginner.
Also as I said Processing is the way I would go. It is a Java like language with a C syntax. Which @ratmanzorry should be familiar with as he/she programs on an Arduino.
any PC software with functionality to access serial interfaces, , e.g. Visual C++, C#, VB.NET, Python, Java, Matlab, GNU Octave, etc etc
I tend to use Jave as it is cross platform
You want to access the PC COM Ports. Python and Processing do that.
Try using a terminal to connect, feed arduino file data while capturing returns.
Processing is what Arduino came out of as an example of Wiring.
The book is Processing and Wiring about connecting MCU's to PC's.