Techniques for UNO to laptop program comms?

I have an UNO R3. I want to be able to write software that executes in the micro and comminicates (sensor commnds annd feedback) with a program executing in a laptop. Let's assume we use the USB port for the data exchange. What are the typical techniques to do this this? I'm not even sure of the terms so as to ask questions.

louarnold:
I have an UNO R3. I want to be able to write software that executes in the micro and comminicates (sensor commnds annd feedback) with a program executing in a laptop. Let’s assume we use the USB port for the data exchange. What are the typical techniques to do this this? I’m not even sure of the terms so as to ask questions.

On my Linux system, I can do the following:
cat /dev/ttyACM0

which copies the characters written via the Serial function in the Arduino to the standard output. I could just use a program that reads the input, looking for appropriate output. This is what the serial monitor does in the IDE, and you can send data from the PC to the Arduino as well. In both cases, it is just text, and you would need to parse it. I would imagine that a similar method would work under Windows or Mac, but the details of which filename to use is different.

For example, a program like:

const int sensor = A0;

void setup (void)
{
    Serial.begin (9600);
    Serial.println ("Starting arduino");
    pinMode (sensor, INPUT);
}

void loop (void)
{
    int value = analogRead (sensor);
    Serial.print ("Sensor is ");
    Serial.println (value);
    delay (10000);                                           // delay 10 seconds
}

Would read the analog sensor on pin A0 every 10 seconds, and tell the PC about it. You could just use the Serial monitor while you are debugging the Arduino part of the package.

[edit]
I should mention, it won’t affect the OP since he has an UNO, but I believe the Leonardo is somewhat different in that doesn’t have a second processor to handle the USB, and when you reset the board, the name can be changed because the main processor closes and reopens the connection.

louarnold: I want to be able to write software that executes in the micro and comminicates with a program executing in a laptop.

What operating system is the laptop running?

Is the application something that exists, or something that you're proposing to write? The Arduino USB drivers present the serial stream to/from the Arduino at a virtual serial port (i.e. a COM port if you're running MS Windows) and there are lots of languages that can be used to read/write from a serial port. (In Windows it's easy with VB, Java, C, C++, C#, Processing etc.)

If you are using windows, you may find interesting this post I wrote a while back:

http://timewitharduino.blogspot.ca/2009/05/getting-arduino-to-write-to-or-read.html

Hahahaha. Yes, I ran that program already and it worked fine. But the goal was not to talk to the serial monitor, but rather to a standalone program running in the laptop. And then you have to send something in the reverse direction. ASCII wouldn't necessarily be fast or conevnient. The question is: How is is that typically done?

PeterH: What operating system is the laptop running?

Is the application something that exists, or something that you're proposing to write? The Arduino USB drivers present the serial stream to/from the Arduino at a virtual serial port (i.e. a COM port if you're running MS Windows) and there are lots of languages that can be used to read/write from a serial port. (In Windows it's easy with VB, Java, C, C++, C#, Processing etc.)

I'm running Windows XP on the desktop and Vista in the laptop. I know about the comm ports in Arduino IDEs. I guess I will have to look up the methods for Windows. The applications don't yet exist. But, for eample, I may want get a message to the laptop that something's in front and then stop a motor.

florinc: If you are using windows, you may find interesting this post I wrote a while back:

http://timewitharduino.blogspot.ca/2009/05/getting-arduino-to-write-to-or-read.html

Yep, that shows how easy it is to write from the laptop to the Arduino. So really any IDE for VB, C#, C, C++ will do to write that program.

OK, thanks.

For low data rates sending messages in text format works fine, and makes it easy to test and see what’s going on. If the data rate is so high that you need a more efficient encoding scheme you can use a binary message format.

louarnold: Hahahaha. Yes, I ran that program already and it worked fine. But the goal was not to talk to the serial monitor, but rather to a standalone program running in the laptop. And then you have to send something in the reverse direction. ASCII wouldn't necessarily be fast or conevnient. The question is: How is is that typically done?

Well the serial monitor channel exists, and comes with the development chips. If you have your own AVR, it may or may not have the serial monitor builtin, or you may have to use a programmer.

Beyond using the serial monitor connection, you could:

  • Get a bluetooth shield and possibly a bluetooth dongle on the PC, and open up a serial conversation
  • Get an ethernet shield and get an IP address, and do normal socket level communication with the PC
  • Get a wifi-shield and communicate via radio waves to the PC
  • Make the arduino act like a USB device using a separate channel (perhaps easier on Leonardo)

Basically there are a lot of ways to communicate, but many of them involve more expense and/or programming to do the job. So it is a cost/benefit tradeoff, whether you want to use the serial monitor channel (and not have it for debugging), or write your own communication path.

MichaelMeissner: Well the serial monitor channel exists, and comes with the development chips. If you have your own AVR, it may or may not have the serial monitor builtin, or you may have to use a programmer.

So its the serial channel with ASCII data. Its probably good with tags that are easily parsed. OK. I get it.

You made a point, I think: the "serial monitor" is part of the bootloader?

the "serial monitor" is part of the bootloader?

No. The serial monitor is an application supplied with the IDE. It's just a very cut-down terminal program.

dxw00d:

the "serial monitor" is part of the bootloader?

No. The serial monitor is an application supplied with the IDE. It's just a very cut-down terminal program.

Yes, of course, dumb on my part. The "listening" code in the micro is part of what I program that communicates with the serial monitor.