input variables - communicate with arduino through PC

I was thinking today of making a program for the arduino where I could input variables from my PC and run them through the program and send back the results as a pulse width or other results.

I know this would have to be done through the serial interface, right?

I have already input variables through a keypad, etc. so I am guessing its just a matter of getting the pc to speak the correct language I need to the arduino.
I was thinking of using hyperterminal - is this the right track?

I have most the basics down with the programming already. But I am very new to serial communication.

Anyone know where i should start, or how i could get the computer to input even one variable to the arduino? Is it going to be a handshake type of operation? Would it be better to use a ethernet shield or just stick with serial?
There are some tutorials on serial comm with a PC, but I havent seen one yet where you input the variable from your PC. And most of the tutorials are a bit vague.

I am wondering if this is even possible, and if i am getting over my head before I get started?
Although I am fairly new to this, I feel it is a good place to broaden and further my understanding.
Any help or advice is greatly appreciated.

Even if you tell me im stupid for trying to do this.....

I was thinking today of making a program for the arduino where I could input variables from my PC and run them through the program and send back the results as a pulse width or other results.

What is the PC going to do with a pulse width? What do you mean by a pulse width? Pulse width is generally a measure of how long an incoming pulse was HIGH, or the time between pulse HIGH to LOW to HIGH again.

I know this would have to be done through the serial interface, right?

Communication between the PC and the Arduino is via the serial port, yes.

I have already input variables through a keypad, etc. so I am guessing its just a matter of getting the pc to speak the correct language I need to the arduino.
I was thinking of using hyperterminal - is this the right track?

No need to guess. But, it was a reasonable conclusion to leap to. Hyperterminal is how YOU, not the PC, communicate with the serial port.

Anyone know where i should start, or how i could get the computer to input even one variable to the arduino?

The computer won't be inputting variables to the Arduino. It will be sending values to the Arduino. Big difference. The playground has a section on communicating with the Arduino, using lots of different programming languages. Personally, I think C# makes the process the easiest. YMMV.

Would it be better to use a ethernet shield or just stick with serial?

Get the communications part working using serial, first. Then, if you want, you can replace the application on the PC with a web interface, and have the Arduino with ethernet shield serve up/respond to a web page.

Is it going to be a handshake type of operation?

That's up to you.

There are some tutorials on serial comm with a PC, but I havent seen one yet where you input the variable from your PC. And most of the tutorials are a bit vague.

Tutorials are guides - not hand-holding.

I am wondering if this is even possible, and if i am getting over my head before I get started?

Yes it is, and that depends on your programming skills, understanding of communications between processes/computers, and commitment. I'd have it done in a couple of hours. You might, too, or you might take two weeks. We're here to help.

Even if you tell me im stupid for trying to do this.....

Stupid would be throwing up your hands and not even starting.

I undertsand they are guides. But some of them are just not well explained or documented as i would expect of a tutorial.

What I mean by using a variable for pulse width is this:
use a variable for on time, off time, and frequency. then the arduino would comm with the PC and ask the user for the three variables they wish to input. Then finally another variable for the number of pulses they wish to run - continuous which would run forever unless the user presses a hotkey, the other options would be 1-1024 pulses.

I have made a basic flowchart on how i would like it to work. Basically I just need a few tips on how I might get started. Im not looking for someone to write the code for me. I want to be able to learn from it; I know it will be challenging. But I feel if i only write basic code - I feel I will learn nothing from this awesome microcontroller.

I should at least be able to write the most basic code I need this weekend. I was just looking for some direction before I get started.

(and yes I meant to say the computer would OUTPUT variables to the arduino - I would be INPUTTING them) Sorry

The reason I mentioned I havent seen a bit of code where the user inputs variables from the PC is because I wanted an original project. And also wondering if it hasnt been done because it is not possible?
Thanks for confirming it is possible.

then the arduino would comm with the PC and ask the user for the three variables they wish to input.

You may just be having a hard time explaining to us what is very clear in your mind, but it is best to think of the Arduino as an idiot that needs to be told exactly what to do.

The Arduino should not be asking the PC what to do. The PC should tell the Arduino what to do.

So, you need to develop an application for the PC (as I mentioned earlier, I like C# for this, and it is free from Microsoft, now) that interacts with the user, and sends directives to the Arduino.

The application could have fields where the user keys in data, or some more idiot-proof method. For instance, if you want to collect on time, you could present a text field, where the user could type 3 (for three seconds) or three or -4 or forever or banana.

Now some of the input makes sense, and some does not. Alternatively, you could use a slider that had a lower limit of 0 and an upper limit of whatever seems reasonable. With that, the user can't enter an invalid value. Pretty hard to drag the slider so that the value is banana.

Pulse count could be done the same way. 0 would mean forever. Any other value would mean a discrete number of times.

Once you know what data you want to send to the Arduino, the next step is to figure out how. The choices are ASCII and binary. Binary is easy when the values are byte sized, but more difficult when the values are ints or floats.

If you go with ASCII (and I'd recommend that to start with), you need to use start and end of packet markers, so the Arduino knows when a whole message has been received. For instance, you might send "<12, 10, 100>" to tell the Arduino to generate 12 pulses, with 10 millisecond on time and 100 millisecond off time.

I have made a basic flowchart on how i would like it to work.

Excellent first step. Sharing it would be step 2.

Basically I just need a few tips on how I might get started. Im not looking for someone to write the code for me. I want to be able to learn from it; I know it will be challenging. But I feel if i only write basic code - I feel I will learn nothing from this awesome microcontroller.

Getting two computers to talk to each other, to share data, and to act appropriately with that shared data is never a trivial task. So, you WILL learn (or re-learn) something.

Your attitude seems right to get this project done.

Break the project into steps, and work the steps one at a time. On the PC:
Create a form to collect the data from the user.
Connect to the serial port.
Format the data to send to the serial port.
Send the data to the serial port.
Read the response, if any.
Show the response to the user.

On the Arduino:
Check for serial data to read.
If any, read and store the serial data, if there is room. As each character is read, see if it is a start marker, and end marker, or something else.
Do different things with the start marker (initialize the array, initialize the index, and set a started flag and clear the ended flag), the end marker (set the ended flag and break out of the while loop), or other character (store it in the next position in an array, increment the index, and append a NULL, if there is room).

When the started and ended flags are true, parse the data.

When you have some data, do the appropriate stuff with that data.

I have a C# application that talks to an Arduino that you could use as a starting point. If you are interested, PM me with an e-mail address, and I'll send it to you.

Thank you PaulS. I really appreciate your advice. I am interested in your program. I will send you a PM tomorrow once I have some extra time. I have a few refinements to my flowchart. Will also send you that once I get the flow refined.

Dont hold back on criticism either. I wont get mad and its the only way i will learn - by critique from more advanced users.

Thanks again. I will send you a PM tomorrow when I am off work. :slight_smile:

Dont hold back on criticism either. I wont get mad and its the only way i will learn - by critique from more advanced users.

There is a difference between critique (I think that this code could be improved by...) and criticism (you idiot, can't you do anything right).

I'll keep with the critiquing and try to cut down on the criticizing.

Incidentally, I have an Arduino Mega, and I have written code to interface between a computer and a board in C#.
If you have any more questions that have not yet been answered, I would also be happy to help.

If you are looking into a easy to learn computer side language, processing is pretty cool
Its what the arduino language is based off so its simple to adjust to
Its basically the same with more commands, it also makes visual programs nice and simple
serial control is pretty easy with processing , I made a program that has classes for buttons, sliders, etc to control my mega
you can even export it to an executable, with processing
A simple and short program <2k on the arduino parsed it and worked perfect

An easy parseing method I've found is simply to ignore the non essential ascii and interpret a set ammount of characters at a time, with a timeout to set back to one
Like for example
13OA125 would set pin 13 output analogwrite(125)

Once you start to play around with serial you will realize how easy (and fun) it can be,

Its what the arduino language is based off so its simple to adjust to

No, it isn't. Processing and Arduino share a similar user interface. The programming language is completely different. Arduino uses C++, while Processing uses Java.

Yeah but because they share the interface, its very similiar to make programs, the compiler does all the java/c coding, all we see is the simplicity

the compiler does all the java/c coding

Can you send my your compiler? Mine keeps insisting that I do the coding.

Lol
I've not coded in java or strictly c before, so idk how close they are but processing seems easy to me