Offline
Newbie
Karma: 0
Posts: 12
|
 |
« on: October 03, 2012, 09:30:28 am » |
Hi there,
I'm currently working on a AGV with Arduino Duemilanove + CMUcam 2 and am having some hard time trying to read serial data sent by the CMUcam. I succesfully managed to send serial data from the Arduino to the CMU-CAM, but reading is really hard. The camera sends back a data packet of this type: "T mx my x1 y1 x2 y2 pixels confidence\r", where "mx, my" and the rest are some numbers with informations I need to process.
The problem is: how do I isolate what I need in that packet and store them into variables? In my case, I need to get only the "mx" and "my" values, but the serial sends everything altogether.
Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35532
Seattle, WA USA
|
 |
« Reply #1 on: October 03, 2012, 09:36:49 am » |
In my case, I need to get only the "mx" and "my" values, but the serial sends everything altogether. The "serial" doesn't send anything. The camera does. It sends a stream of characters that presumably mean something to the receiver. How are you reading/capturing that data now? The answer to that has a lot to do with how you then parse the data. If you are doing it right, storing the data in a char array, the strtok() and atoi() or atof() functions might be worth looking into.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #2 on: October 03, 2012, 09:52:14 am » |
Yeah, I know the serial doesn't send anything, but you got my point, hehe.
Right now I'm just storing the whole packet in a variable, but what I need is to 'filter' the packet and store only what I need, that is, the 'mx' and 'my' values. How can I get only these values and store 'em into separate buffers?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35532
Seattle, WA USA
|
 |
« Reply #3 on: October 03, 2012, 10:08:44 am » |
Right now I'm just storing the whole packet in a variable, but what I need is to 'filter' the packet and store only what I need, that is, the 'mx' and 'my' values. How can I get only these values and store 'em into separate buffers? That depends on the type of the variable that you are currently storing the data in.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 2
Posts: 212
|
 |
« Reply #4 on: October 03, 2012, 10:29:06 am » |
Just curious how do you want to store a RGB like image of a cam on a arduino, or what would you like to do with the received data. Because I mean even a small cam lets say (800 x 600 pixels x 3 colors) requires 1.44 Mb thats more then a arduino has.
( i'm curious since i had been thinking of using cams with arduino to, and then abandoned the idea in favor of a cheap ITX motherboard )
|
|
|
|
« Last Edit: October 03, 2012, 10:30:41 am by PGTBOOS »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #5 on: October 03, 2012, 10:46:34 am » |
@PaulS
I'm storing to a string variable. I need to get only those information I need and possibly convert to integer.
@PGTBOOS
I'm not storing images on the Arduino. The CMUcam tracks pre-determined colors and sends back information such as the X and Y values of the middle of the mass.
|
|
|
|
|
Logged
|
|
|
|
|
California
Offline
Edison Member
Karma: 41
Posts: 1872
|
 |
« Reply #6 on: October 03, 2012, 10:53:43 am » |
I'm storing to a string variable. I need to get only those information I need and possibly convert to integer.
string or String? It would be much easier if you just posted your code.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #7 on: October 03, 2012, 11:02:37 am » |
This code is from the Arduino site, I only added the command to print data to a LCD. String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete
void loop() { // print the string when a newline arrives: if (stringComplete) { lcd.clear(); lcd.print(inputString); //prints the string on a LCD // clear the string: inputString = ""; stringComplete = false; }
}
void serialEvent(){ while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35532
Seattle, WA USA
|
 |
« Reply #8 on: October 03, 2012, 11:09:27 am » |
So, look at the String class. Look at methods for finding characters, like the comma that separates values. Look at methods for extracting parts of the String as a substring. Look for methods for converting a (sub)String to an int.
The needed methods all exist. You just need to call them in the right order.
Or, better, ditch the String class, use a char array and strtok() and atoi().
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #9 on: October 03, 2012, 11:16:18 am » |
Ok, I think I got it. I'll try out. Thanks!
Now, another doubt.. on the CMUcam manual, it's said that the packet sent back comes in ASCII viewable format. On the LCD, for example, it comes as something like "T 23 12 52 42 ..". But, how does it arrives to the Arduino? Is it in Decimal, Hex? I can't monitor it on the Serial Monitor, because Duemilanove has only one Serial Port.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35532
Seattle, WA USA
|
 |
« Reply #10 on: October 03, 2012, 11:25:42 am » |
I can't monitor it on the Serial Monitor, because Duemilanove has only one Serial Port. You could connect the camera to other pins, and use SoftwareSerial to talk to it. You are using the lcd to print the data from the camera. Can't you see what form the data is in from that?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: October 03, 2012, 11:26:19 am » |
But, how does it arrives to the Arduino? ASCII, by the look of it.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #12 on: October 03, 2012, 11:30:29 am » |
If I use the SoftwareSerial, than the RxTx for USB comm is going to be available? Because when I plugged the RxTx pins for the camera, I could not connect the Arduino to my PC. Guess I'll have to try it out.
With the LCD I can see that it comes as 'the real values', but I fear that the Arduino may read it as Decimal or even Hex, not the real thing.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35532
Seattle, WA USA
|
 |
« Reply #13 on: October 03, 2012, 11:31:38 am » |
but I fear that the Arduino may read it as Decimal or even Hex, not the real thing. Well, it had to read it as "the real thing" in order to print it on the LCD.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #14 on: October 03, 2012, 11:37:01 am » |
By "the real thing" I mean understandable content, hehe.
|
|
|
|
|
Logged
|
|
|
|
|
|