Tuesday, July 9, 2013

In Search of a Better Serial Camera Module

So I've been looking everywhere for a cheap serial camera to use in my projects, preferably with some basic image processing, like object or motion detection etc.. The cheapest one I could find that barely meets my needs is sold on adafruit for $35, it has a 640x480 pixels sensor and can do some motion detection but nothing more. Then there is the more expensive modules which cost around $40 that do nothing at all and finally there's the CMUcam, which has some really nice features, but way too big and expensive (costs $100) for my needs...

So I decided to make my own serial camera, keeping in mind the basic set of features that I want:
  • Low cost
  • Small form
  • Basic image processing
  • Open source (duh!)
First, I had to choose an image sensor to use, I was inclined to use the TCM8230MD, which I'm familiar with, however, the sensor alone costs $10 and I can't seem to find it any where else other than sparkfun. So, I've decided to try the Omnivision sensors, the cheapest one I could find is the OV9650 (1280x1024 pixels) sold on ebay for $2... The nice thing about this sensors is that it connects to the board with an FPC cable (that flexible yellow cable), which means it's possible to replace it later with another one (assuming it has the same pinout) and it also has a higher resolution than the TCM8230MD. The downside with this particular sensor is that it doesn't have JPEG compression, but I could live with RGB/RAW output, after all I plan to use it mainly for image processing, or I could try to implement the JPEG compression on the micro.

Moving on to the microcontroller, a powerful micro is needed to interface with this sensor, preferably with a DCMI hardware interface, I implemented a DCMI before in software with an LPC1768/TCM8230MD and it could barely keep up, so I decided to go with something faster. 

Fortunately, I had a couple of STM32F4 micros laying around, which seemed perfect for the job since it  runs at 168MHz, has a hardware DCMI (should make it a lot easier to interface the camera) and as an added bonus, it has a floating point unit and vector processing (SIMD), making it perfect for image processing... Unfortunately, the DCMI only comes with the LQFP-100 package, so I couldn't use a smaller one. 

I started working on the PCB, first, I made a footprint for the sensor and its connector, which seems to fit nicely:
And then I moved to the layout, however, shortly after that, I realized that it's impossible to fit the sensor and micro (let alone the debugging header and interface) on a 2 layer PCB, which is what I had in mind initially to reduce the costs. So a 4 layer PCB seemed inevitable If I wanted to make it as small as possible, there's also some inherit benefits to the extra layers such as better power planes and decoupling, easier routing etc... Anyway, the first version of the PCB (25x37mm) costs around $5


The board has a triple output LDO 3.3v/2.5v/1.5v (the one I had at hand came in a QFN package) and a micro USB connector, which can be used to power the board or update the firmware with DFU. The  SWD pins are broken out for debugging (I'm currently working on a JTAG debugger too) I also throw in an RGB led (not sure if it's too close to the sensor to be visible or not)

The STM32F4 micro costs $11.79 per one, and $7.31 per 500, this adds up to around $20 for one piece and could go as low as $15 for 500 pieces,  it's much higher than I expected, but It should make up for it with some cool image processing, and still almost $15 cheaper than the adafruit camera :)

I still haven't received the PCBs yet, will post an update when I do and when I get it working I will release all the sources. I'm also giving away one for free, leave a comment if you're interested :)

39 comments:

  1. What a find!!

    Here I am, searching for some good info on the TCM8230MD that I've just found on robotshop.com, only to find your blog entry, from yesterday, with a better, cheaper camera...

    I'd love some more instructions on how to set it up or even video? :)

    Thanks!
    Best wishes,
    Matt

    ReplyDelete
    Replies
    1. I made a few breakouts for the TCM8230MD and you can find the source code here. As for the OV9650 sensor, I haven't received the PCBs yet, will post an update when I do :)...

      Delete
  2. Have you considered MT9D111/MT9M112/MT9T112, OV7670, OV2640, OV3640 or even OV5640/OV5640 - most of them cost near 10$ and have FPC or breakout version. You can find them here or here for example.

    Nice article! Keep going, man!

    ReplyDelete
    Replies
    1. you can take raw PLCC24 package of OV3640 (1600x1200) for only 9$, or OV2640 (1600x1200) in FPC version for just 7$, anyway it will beat crappy adafruit camera (640x480)

      Delete
    2. yes but I wanted to make it as cheap as possible, OV9650 costs $1.9 :) and I think 1280x1024 is acceptable for now, I will check the other modules and see if they have the same pinout. Thanks !

      Delete
  3. Definitely interested. Looking forward to hearing about how your board turns out ;)

    ReplyDelete
  4. Have you seen this project? - www.kickstarter.com/projects/254449872/pixy-cmucam5-a-fast-easy-to-use-vision-sensor

    ReplyDelete
    Replies
    1. no, haven't seen it before, but it looks great ! I'm going for something like that but much simpler for sure..

      Delete
  5. I read in your other comments that you are from Egypt. Hope you are safe,

    -Tony

    ReplyDelete
    Replies
    1. Yes, the mail is taking longer than expected, but other than that everything is okay... thanks for asking :)

      Delete
  6. Hello, nice post! I have a question regarding the camera connector, do you have the part number?

    Thank you,
    Walter.-

    ReplyDelete
    Replies
    1. yes I used this one: "SFV24R-2STE1HLF", it's a 24 contacts 0.50mm pitch connector.

      Delete
    2. actually, that's not the right connector, the contacts are on the wrong side.. don't use that.

      Delete
  7. This looks like fun. Obviously a free one would be lovely, but would you be willing to sell any?

    ReplyDelete
    Replies
    1. I have just one extra camera which I don't mind giving away for free :) you'd have to do some testing and/or write some code maybe, but that's not the issue, I'm still having trouble with the sensor, all I have so far is a YUV image which doesn't even look right.. So I may change the sensor if I can't find a complete/working register set soon, when I get it working I will post another update, let me know if you still want one then..

      Delete
  8. This is awesome. I am doing some projects that need to look for colored objects (like a red laser dot) and it looks like this is just the thing I was looking for. I am very very interested in it and would be very interested in testing it... or simply buying one if you ever decide to sell them (please?)

    ReplyDelete
  9. How many fps would you expect to analyse?

    ReplyDelete
    Replies
    1. I'm not sure, I guess that depends on the algorithm, I will do some testing anyway and get back to you.

      Delete
  10. Incredibly cool project, I've wondered about how to do this sort of stuff but don't have that kind of skill myself.

    ReplyDelete
  11. This is an awesome project. I just wish phone camera modules had better datasheets so that those removable camera modules from cell phones would be more useful. I"m really interested to see how much progress this thing makes!

    ReplyDelete
  12. Could be quite good as a smart mocap sensor - threshholding and then returning the center of bright dots and their 'roundness' as a serial stream. per frame time.

    ReplyDelete
  13. Saw this a few days ago but didn't get a chance to comment. Saw again in HaD. Nice work!

    I recall first seeing your Toshiba cam breakout. I did my own based on yours and was all gung ho to do my own budget cam. How many years ago was that? lol

    Glad you kept at it. The solution looks great. The STM32F4 DCMI caught my attention (maybe because of your blog I forget)

    Any thought to selling this on Tindie.com? Do a fundraiser on there and see if you can get interest for a couple hundred? Or alternatively, posting your design there and letting someone (me) sell 'em and kick back a part of the proceeds? :)

    Between DCMI and DMA I would expect that one could do quite a bit with this thing. Can you control the effective resolution of the camera for sake of performance?

    Just plain color blob detection would easily do 30fps on modest resolution given that a 16MHz ATmega8 was doing multi-object, multi-color blob tracking on the AVRcam years ago.

    Would love to take a crack at helping with firmware at some point...

    ReplyDelete
    Replies
    1. Hey Michael, yes it has been a few years since the first generation haha :) ...anyway, first, as far as the processing goes, yes I can control the resoultion and framerate, the camera is currently configured for a 120x160 pixels frame (QQVGA) @ 30FPS that's the lowest resoultion, the DCMI can handle more of course (54Mbps) so it could easily read 30FPS, I process the entire frame by converting pixels from RGB565 to HSV and then using a threshold to detect a red color, this way I get 15-16 frames per second, if I skip a byte when a color is detect I get the full 30FPS, maybe there's a better way to do it?

      Secondly, I would love to sell those on Tindie with your help, and there seems to be some interest in this projects, I also have a few ideas for the camera and would love to hear yours, I will contact you via email later.
      Thanks.

      Delete
    2. Any update? Can't wait... :-)

      Delete
    3. yes I will post another update soon :)

      Delete
  14. Hey, this project looks awesome. Just an idea if you decide to respin the boards, I noticed you have a little room at the top of the board. You could put two white/IR LEDs on either side of the sensor and break the pair out to act as a light.

    ReplyDelete
    Replies
    1. That's a great idea, I might do that next revision, thanks :)

      Delete
  15. would love to own one of these little things. I am a novice, but I would like a camera for RC cars and I would also like a camera for a night-vision HUD on glasses....kinda like Google Glass :)

    ReplyDelete
  16. Hi everybody,

    I have configured my ov7670 to work with stm32f4. I achive the snapshot images QVGA (320x240).
    Could enybody tell me how to compress such image to jpg image on the stm32f4 uC ?

    Ted

    ReplyDelete
    Replies
    1. I was looking for a lightweight jpeg encoder myself, something that I could easily port to STM32, the only one I found (jpec) which looks great, only works with grayscale, so please let me know if you find anything, also I'm interested to know how you store the QVGA frame ? do you use multiple DMA buffers and swap them ?

      Delete
  17. Just started reading your blog on this, great stuff.

    I'm glad you don't have mjpeg capability on that camera, as mjpeg introduces artifacts to every image that make processing very difficult.

    Dave

    ReplyDelete
    Replies
    1. Thanks, JPEG is a lossy compression so it's supposed to lose some details for smaller sizes, I'm actually going for a sensor that has both JPEG and raw output, JPEG will be used when sending images, and raw RGB/YUV for processing.

      Delete
  18. Hello! I have been wanting to get into cameras for embedded projects but i find it extremely difficult and undocumented... What i found is using SoCs like TI's DaVinci.. Can this camera record video?

    ReplyDelete
    Replies
    1. No, those sensors output raw, RGB or compressed images, video encoding is typically done on the SoC.

      Delete
    2. Thanks! Can i ask, what sensor and chips do you suggest for video recording embedded projects? I mean there has got to be a way! You can find chinese spy cams on pens with 5 dollars on ebay

      Delete
    3. There are so many ways to do this, it really depends on your application (for example, the video encoding you want) and cost.

      Delete
    4. The only option i know (ti's davinci), supports csi camera sensors. Is this interface the only available option? Do csi camera sensors exist in the market for hobbyists? Thanks a lot!

      Delete
  19. Video encoding is hd for example h.264. Are there available socs for the hobbyist, or only companies selling to existing companies? Where can i get info on the available socs?

    ReplyDelete