1

I'm working on an embedded home surveillance system. I want to interface a couple of serial-enabled JPEG capture cameras, maybe a couple of door sensors, etc. Problem is, I can't for the life of me figure out how to interface a camera to a microcontroller. Stills, streaming video, it doesn't matter - I can't find any how-to documentation on this.

I understand serial communications, and most of the camera documentation I've found out there describes the protocol necessary to instruct the camera to send the datastream down to the uC for capture. What they don't show is what you're supposed to do with the data once you get it.

Here's an example.

They show a great little video, and the datasheet describes which bytes must be sent to the camera to retrieve the image. What I need is an example or tutorial of some sort that will explain what to do with the stream of bytes that make up the image itself. How do I arrange those bytes into an image and save it as a file?

I've looked all over the place for a tutorial of some sort, but have come up dry. I'm not sure which processor I'll use for this project just yet, but this question isn't really processor-dependent. All I need is the algorithm, maybe a peek at a library, if one exists. I'll take that process and adapt it to my hardware, I just can't seem to find a place to get started.

Have any of you done this?

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
Glenn
  • 3,338
  • 3
  • 20
  • 14
  • That's a badly written data sheet! "Package size must not be odd or multiple of 16" and then states limits of 64 and 512 that are multiples of 16, so probably they mean should. And package is probably a mistranslation of packet... Anyway, if you re-assemble the "packages" and write them out as a file, do you by chance get a valid jpeg? You could at least look for a jpeg header in there. Decoding their raw image may be harder, but you may get somewhere with a structured scene (vertical or horizontal white/black split) and a hex dump... – Chris Stratton Jan 29 '11 at 02:59
  • If you're sure your received bytestream contains the image, why don't you save it as a binary file and share it with us? It would be easier for those without a camera to help you. – mpenkov Jan 29 '11 at 03:03
  • @ Chris - I'm glad to hear you thought it was a bad datasheet, I certainly didn't get much out of it. @ misha - Therein lies the issue: I don't have the camera yet. I'm looking to _design_ the system, but I don't even know what I need. What I'm hoping for is some sort of tutorial that will show me what to expect from the different types of cameras, and what to do with the data they send me. I don't necessarily expect you guys to write such a tutorial, I'm hoping one has already been written and I just haven't been able to find it. Do you know of any documentation like that? – Glenn Jan 29 '11 at 18:47
  • I'm not really aware of anything for serial type cameras. There are a lot of drivers out there for USB-type webcams, but I don't think you want to get into those unless you are using an embedded version of a desktop operating system on your device (such as embedded linux) since trying to port USB drivers to a new OS or bare USB functionality is likely to be far more painful than working with this serial device. – Chris Stratton Jan 30 '11 at 23:13

2 Answers2

3

I think the details are pretty clear in page 10 inside this document:

http://www.4dsystems.com.au/downloads/micro-CAM/Docs/uCAM-DS-rev4.pdf

First, one package is between 64 to 512 bytes - flexibly defined by the programmer. Image size is the actual JPEG image itself....nothing more or less....just pure JPEG image. So the equation to calculate the number of package based on image_size / package_size is given in page 10.

Next, is that (package_size - 6) is to be consistently used everywhere, because 6 bytes are used up for non-data purpose, so (package_size - 6) will be just the data - but u have to reassemble it yourself.

To assemble the data from the package, u have to strip the 4 byte header + 2 byte trailer and concatenate all these from all the package sequentially one after another.

Other facts:

a. "Set Package Size" command must be sent from host to CAM - before "SNAPSHOT" command, which capture the image from the camera into the CAM memory buffer.

b. Next is to send "SNAPSHOT" command to capture the image into memory buffer.

c. Last is to send "GET PICTURE" command (only one time, but data will come back multiple times - see diagram in page 15) to extract out all the images....and it will come back in the form of "package" as we have defined the size earlier in "set package size". Since u have calculate the formula u will know when to stop asking for the next package. And there is a verification byte - u have to used that to make sure data is correct.

Peter Teoh
  • 6,337
  • 4
  • 42
  • 58
  • 1
    That about matches what I concluded by trying to translate the mis-statements in the data sheet back to their probable intent - but also be careful of that warning about needing to reset the thing after certain size packets. This is about as far as you can go without buying the device and trying it. At which point, if it's a non-hobby project, developer time contemplating it has already added up to more than the hardware cost. – Chris Stratton Jan 30 '11 at 23:09
  • This probably doesn't need mentioning, but it's likely going to be a lot easier to do the initial testing using a PC rather than an embedded platform; a small amount of time invested in writing wrapper functions for the PC OS's serial interface and the embedded system's can make the functional logic essentially portable between the two. – Chris Stratton Jan 30 '11 at 23:17
  • Thanks everyone. This is very much a hobby project, so it's just something I'm tinkering with. I just haven't been able to get off the ground with the right algorithm. This is a great place to start. Also, Chris: Great suggestion about using the PC for prototyping and initial testing. – Glenn Jan 31 '11 at 04:08
0

I have not used this camera but looks like it works exactly the same is a camera (C328) I have used. Send an image resolution/colour command. When you want get an image send an image capture command. The camera responds by sending a binary file over the serial link.

Gerhard
  • 6,850
  • 8
  • 51
  • 81