I've hooked up a linksprite webcam to an arduino (uno and mega), with moderate success, using the sample code from the sparkfun web site. With a bit of tinkering to update the code to compile on 1.0, I have images coming out of the camera and through the serial, to an app on the pc that displays the jpeg. All good so far, but the use of softwareserial is slow, so I hook it up to serial2 on the arduino mega.
Now this I'm having major issues with - it initially just seemed to stop responding, however with some digging I discovered I'm getting some data back through the serial connection multiple times. I get the command response, then rather than image data, I get the command response back again, followed by image data, and things end up out of sync.
Has anybody had any issue using the linksprite camera with hardware serial, or is aware of any hardware serial issues in general i should know?
In case anybody hits the same issue, turns out none of the example code waits for the 5 bytes at the end of image data. The examples all go:
request data
read 5 byte response
read rest of msg and take 32 bytes
What they don't make clear, and the manual is very subtle about is that the data will actually be in the form:
<5 byte response> <32 bytes image data> <5 byte response>
You get away with it on software serial, as it's slow enough for the 5 byte response to arrive and get flushed. However on hardware serial you need to make sure you wait for the full 42 bytes before moving onto the next msg.