PDA

View Full Version : Sending Variables to PC/another App - Arduino/



nagmier
08-09-2009, 12:01 AM
Here is my problem:

I want to control 3 "Sensor Arrays"

each one containing a pan servo, IR sensor and a Sonar Sensor

i want to basically just take my sensor values and servo position and send
it over serial to a C++ program to use. I'm trying to figure out the best way
to do this but I guess its to just get my readings and send them out with a
Serial.print(xxxx); I guess I'm looking for a way to pass a variable but I don't
guess thats possible. Let me know if I am barking up the wrong tree here.

jes1510
08-09-2009, 12:13 AM
Something like this may be what you are looking for:



Serial.print(irReading);
Serial.print(",");
Serial.print(sonarReading);
Serial.print(",");
Serial.println(panServo);
That will print out all of your sensor readings separated by commas followed by a new-line ("/n").

nagmier
08-09-2009, 12:14 AM
Yeah that is what I was afraid I was going to have to do, messy :( but oh well I understand the limits I just wanted to make sure I wasn't missing something since I'm no micro guru. Thanks Jes!

Adrenalynn
08-09-2009, 01:24 AM
You could use sprintf(); and it would look prettier, but sprintf(); is an ugly dangerous memory-hogging function. I'd rather use a method that didn't look as clean but was internally cleaner.

lnxfergy
08-09-2009, 01:47 AM
You might also look around the Playground on Arduino.cc, there are a number of nearly turn-key PC<-->Arduino examples/libraries, several of which implement handshaking and error-recovery. Not sure that any use C++ for the PC though, since most of the examples are designed for cross-platform compatibility

-Fergs

Adrenalynn
08-09-2009, 01:50 AM
Yeah, Wiring <-> Processing is the classic way to implement the exchange and get a nice plotting engine in the process. The vast majority of samples will probably be Wiring <-> Processing

nagmier
08-09-2009, 10:15 AM
Thanks guys I looked at the processing stuff a little bit but I couldn't really wrap my head around it, I will take a little bit more in depth look, Thanks again for pointing me in the right direction everyone.

lnxfergy
08-09-2009, 12:02 PM
Thanks guys I looked at the processing stuff a little bit but I couldn't really wrap my head around it, I will take a little bit more in depth look, Thanks again for pointing me in the right direction everyone.

Processing is basically Java, with some simple extensions for graphics and opening serial ports. In theory, the syntax shouldn't be that far off of C++, if you can replace the serial/graphics stuff with suitable libraries.

-Fergs

Adrenalynn
08-09-2009, 12:05 PM
Nod. And obviously, you can send and receive packets in any language that can open a serial port, don't have to be tied to Processing - that's just where the largest chunk of sample code is going to come from.