Reading in user input over USB?

Hey all. I've never worked with an Arduino or other MCU stuff before, but I've been reading a whole lot and I have an idea for a project. (Sorry if this post turns out a little tangential; my mind is racing right now.)

Basically, I'm wondering what it would take to read in a user's input. I was envisioning a program with a command prompt-like window open and a person could hit a key and the unit would respond immediately. Or maybe I have some sort of sequence loaded into a file, and then the program reads the file in and executes it on my keystroke.

I'm going to use the default IDE and everything like that. But I watched a basic video on the Arduino, and in it, they said that you push code to it, and after ten seconds it puts the code into effect. But if that's true, then how would you take input over USB? Do you use the Serial class? And is possible to build that sort of prompt in the Arduino language?

Is this sort of thing possible, or am I thinking too far ahead? Could I do this over the default USB interface built onto the board (I've got the new Duemilanove in mind) or would I have to add another USB adapter onto the RxTx and toss a keyboard on there?

Any help or ideas are much appreciated. Thanks~

The usb port is used for programming the arduino. Once the arduino has been programmed the serial port is released for other serial communication.

The arduino IDE has a serial monitor which can be used for sending and recieving data. However, that is all it does! If you want something to happen on your computer when you press a button, you will need to use another programming language. If your new to programming then Processing would probably be a good start as the arduino language evolved from that!

The only thing you need to worry about is that you close the serial port in the programm on your p.c before you attempt to programm the arduino!

Once the Arduino IDE is finished uploading a new sketch (program) into the Arduino board it closes the USB comm port. You are then free to use any PC program that can communicate over the USB comm port to send or receive characters to the attached Arduino board.

The Arduino IDE itself also has a build in serial interface called serial monitor that you can use to send and receive simple characters over the comm link from the Arduino board.

Edit: phill beat me to it I see :wink:

Lefty

Ahh, okay, I see. Thanks for the quick responses!

I've done a bunch of serial programming in Java before using a class I found somewhere (I'm a developer by trade, BTW) so I was thinking of using Java. Or maybe I'll take a look at Processing.

But... if I want everything that happens to be controlled by user input, then it seems like maybe I wouldn't even need to push any sketches to the Arduino..? Or maybe I'd need to write a simple sketch to just loop and wait for input?

Like, let's say I have a bunch of RGBLEDs attached to the Arduino, and I want to dynamically change their color based on user input. Couldn't all that be done through an outside language?

Couldn't all that be done through an outside language?

It would take both a PC based language program and a uploaded Arduino program. The Arduino AVR processor chip's I/O pins cannot be controlled without some kind of uploaded program to read the serial communications commands, interpret them and perform the wanted functions.

Lefty

you would need some kind of program on the arduino to open the serial port, and some kind of protocal.

..... but it only needs to be simple, something to pass the inputs to the pc, and the outputs to the arduino. All other processing can be done on the p.c.

If timing is critical, your best programming the arduino, but for more processor intensive stuff, your p.c would be an obvious choice.

Wouldn't Firmata allow him to control the Arduino directly from JAVA?

It would take both a PC based language program and a uploaded Arduino program. The Arduino AVR processor chip's I/O pins cannot be controlled without some kind of uploaded program to read the serial communications commands, interpret them and perform the wanted functions.

Hm, alright. So would you do this, by like... having a switch() statement and interpreting the inputs like that? For example, if I have the Java send a capital A, the switch will read that and know that it needs to, say, raise the brightness from 0 to 255 on a certain light? I guess it would basically have to be some sort of way of wrapping the pinMode and digitalWrite functions. Does that sound at all right?

Edit:

Wouldn't Firmata allow him to control the Arduino directly from JAVA?

I saw Firmata before but didn't really read into it. Looking at it now, something like sendDigitalPortPair(byte pin, int value) might be what I'm looking for..

This all sounds like a job for Bitlash: "Bitlash is an open source interpreted language shell for the Arduino serial port. It runs on the Arduino and interprets commands that you type in a terminal window or send programmatically."

Confession: I didn't search previous posts before I posted my "Driving Arduino from PC" post... and the tread I am putting this reply in was next door when I looked to see that my post had gone up!

My other post is asking for the same sort of thing that is discussed here... but it does start from an understanding of some of the basic points. Those of you who knew something of the "answers" might find my offer to pay for development of a product (described at...

... of interest?