Tuesday, January 29, 2013

Demo: STM32F4 + OV7670 + qSerialTerm

Yup, that mess of wires actually works.

In this post I'll cover 3 basic demo programs for the STM32F4 to interface the OV7670. Additionally, I've use qSerialTerm to receive data from the uC and display it in a human readable form.

I assume you know how the OV7670 works and have some knowledge about common peripherals found in uC (GPIO, USART, DMA, etc).

The board used in this demo was the custom development board: F4Dev. The STM32F4DISCOVERY wasn't used and can't be used because the Digital Camera Interface (DCMI) peripheral pins are not fully available in that development board.

I've used bareCortexM, an Eclipse based IDE, and libstm32pp, a template peripheral library, to develop these demos for the STM32F4.

The following configuration applies to all the demos:
  • The STM32F4 operated at 42 MHz, the system clock, the AHB clock, the APB1 clock and the APB2 clock, all of them operated at this frequency.
  • This 42 MHz frequency was obtained from the uC High Speed Internal (HSI) oscillator, which runs at 16 MHz, after scaling up the frequency using the uC internal PLL.
  • The MCO1 pin was configured to output the HSI clock (16 MHz) and this output was used to drive the OV7670 XCLK.

Demo 1: Scanning the SCCB bus (Code)


In this first demo, the STM32F4 will interface the OV7670 using a bit bang implementation of the SCCB protocol.

The uC will wait until the letter 'S' is received on the USART1 interface. Upon receiving this signal, the uC will read all the internal registers of the OV7670 using the SCCB interface.

After scanning all the OV7670 registers. The uC will report the address and values of the registers via the USART1 in a human readable format.

Default values of the internal registers of the OV7670

You can find the log file of the uC output here.

Under the hood details: The formatting was done using the printf function.

Demo 2: Reading a frame and visualizing the data in hex format (Code)


In this second demo, the STM32F4 will interface the OV7670 using the Digital Camera Module Interface (DCMI) to grab a frame from the OV7670 and then display the data in hexadecimal format.

The uC will wait until the letter 'S' is received on the USART1 interface. Upon receiving this signal, the uC will use the DCMI in single shot mode to grab one frame from the OV7670.

After capturing the frame, the uC will send all the data via the USART1 interface in a human readable hexadecimal format.

Frame taken in a pitch black environment. Data in hex format.

You can get the full log file here.

Under the hood details: The DCMI peripheral works hand to hand with the DMA peripheral. The data that is captured by the DCMI is moved by the DMA to a predetermined memory address without intervention of the uP. The formatting was done using the printf function.

Demo 3: Reading a frame and visualizing the data as an image (Code)

The last demo is pretty similar to the second demo. The difference is that the uC reports the frame data in binary form. On the PC side, this binary data is parsed and displayed in qSerialTerm.

Frames captured by the OV7670. Left: A electrical tape. Right: Pitch black image.

Under the hood details: After capturing the frame, the data was sent through the USART interface using the DMA peripheral.

That's it. You have access to my full code, both the STM32F4 firmware and the qSerialTerm are fully available to you. I hope this information will help you in projects that involve the OV7670.

72 comments:

  1. Thank you!
    It's midnight so I'll check it out tomorrow but I've been looking for this :-)

    Cat

    ReplyDelete
  2. Dear Jorge!
    Do you think, I can use the same camera module, with STM32F103 microcontroller? It doesn't have DCMI.

    ReplyDelete
    Replies
    1. Yeah, it can be done. I did it with STM32F103. But you cannot get higher frame rates. then I moved to stm32F4 discovery board. It was success, now I can get images upto 30 fps.

      Delete
  3. hi

    you said in your tutorial that stm32f4discovery can not be used, but according to its datasheet it has dcmi so what is the problem with stm32f4discovery?

    i have both stm32f4discovery and linksprite jpeg camera and is it possible to capture frames with them and send pictures to PCs monitor?

    thanks for your answer that would be appreciated.

    ReplyDelete
    Replies
    1. Hi Tolga,

      I mentioned that, because on the STM32F4DISCOVERY board has the DCMI pins connected to other ICs in the board, and I think that might distort the OV7670 signals and corrupt image data or even stop the DCMI interface from working.

      However on the comments of my post 'Hacking the OV7670', Austin Ciambriello claims that he has managed to get the STM32F4DISCOVERY working with the OV7670.

      So, in the end, it might be possible, I can't assure you that because I haven't tried that combination (STM32F4DISCOVERY + OV7670)

      Regards

      Delete
    2. thank you jorge, i will try my linksprite cam with stm32f4discovery, hope it would work :)

      Delete
    3. Hi Tolga,

      did you manage to make that setup working ?

      Delete
  4. I need qSerial to display image. Can you give me it. It is very neccesary for me. Thanks! My email is tvden018@student.ctu.edu.vn

    ReplyDelete
    Replies
    1. Hi Den,

      The qSerialTerm code is among my github projects. Go look for it (hint: top right of this page), modify and build it to yours needs.

      And please don't spam post the same comment in other blog entries.

      Delete
  5. Hi yoman, yes you can interface ov7725 with stm32f1 , i've already tried , it works and im even processing 320x240 data.i suppose that this is also truth for ov7670
    Hi Jorge, i've just realized the existence of the DCMI on stm32f4, can you tell the advantages of DCMI, and overall advantages in image adquisition on stm32f4 over stm32f1

    ReplyDelete
  6. Hello,
    I currently have the problem of the camera (OV7670) via Ethernet (UDP) to stream.

    I currently use the demo software and a simple UDP connection (server) to build, now I want to send the camera data in JPEG format.

    Can you please help me? I uploaded the demo software on Dropbox ->
    ETH + DCMI Demo Project

    How can I read the data from the camera and send via UDP?

    I would be very happy if you can help me?

    Thank you very much

    ReplyDelete
    Replies
    1. Demo Projekt -> https://www.dropbox.com/sh/x74c963dkxyct74/3oCAFAA8dq?v=0mcn

      Delete
  7. Hi Jorge

    I'm trying to run first demo on STM32F4DISCOVERY, but in fuction readSlaveRegister, function getByte always return false and I don't know why. Have you got any idea? I will be very appreciate for help.

    Regards,
    Wojtek

    ReplyDelete
    Replies
    1. Did you manage STM32F4DISCOVERY working with the cam ?

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Hi all,
    I'd like to ask you about DMA_BufferSize.
    DMA_InitStructure.DMA_BufferSize = picture_x * picture_y * 2 / 4;
    Why did you use "*2/4" here?

    ReplyDelete
  10. Why do you use bit bang i2c? I used the hardware i2c and it works just fine. The trick to getting it working is to use a 10k pullup resistor. It appears that using a resistor with too low of a resistance and it won't work.

    ReplyDelete
  11. Acetech have many years of experience in custom software development. Find out more about custom software development at http://www.acetechindia.com

    ReplyDelete
  12. Congrats about the post!
    Very Nice!
    I'm in a project with OV7670, I research a lot, but I don't know what is the black strip in the left of the images, you know?

    ReplyDelete
    Replies
    1. haii have you done that project

      Delete
    2. Hi
      can i use this type of camera with a cubsat to control the water of earth with an altittude of 500KM
      and thx.

      Delete
  13. will it work with hyper terminal or teraterm ???

    ReplyDelete
  14. Congratulations for getting it work and a brilliant walk-through post. I know its based on Qt, but is there any alternate utility for plotting images received over serial port on windows XP platform?

    Thanks,
    Prasad. (logging to gmail is banned in the company, so have to comment as anonymous user)

    ReplyDelete
  15. This blog explains the details of most popular technological details. This helps to learn about what are all the different method is there. And the working methods all of that are explained here. Informative blog
    PHP Training in Chennai

    ReplyDelete
  16. hi, I've just started started my project on this topic, mostly emage processing and i found useful info from your project.I am starting with arduino uno, do you have any guidline for me, i appreciate your help.

    ReplyDelete
  17. how to use it without DCMI. i am using STM32f30k6 M0 board.

    ReplyDelete
  18. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  19. Do you have an advice for using STM32 with a OV7670 with FIFO? Specially what settings I should use. (Now I am not getting a good image). The clock is set to 24MHz by an external oscillator

    ReplyDelete
  20. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my
    vision, keep sharing..
    Android App Development Company

    ReplyDelete
  21. This article is very much helpful and i hope this will be an useful information for the needed one.Keep on updating these kinds of informative things...
    iOS App Development Company
    iOS App Development Company

    ReplyDelete
  22. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text

    ReplyDelete
  23. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    www.mcdonaldsgutscheine.net/ | www.startlr.com/ | www.saludlimpia.com/

    ReplyDelete
  24. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Texting API
    Text message marketing
    Digital Mobile Marketing
    Mobile Marketing Services
    Mobile marketing companies
    Fitness SMS

    ReplyDelete
  25. Hi
    can i use this type of camera with a cubsat to control the water of earth with an altittude of 500KM
    and thx.

    ReplyDelete

  26. Thanks for sharing helpful information, I really like your all post. I will bookmark your blog for future updates.
    Click Here : Crawler dozers for sale Cat D5KXL KWW00358

    ReplyDelete
  27. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    rpa training in chennai
    rpa training in bangalore
    rpa course in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete

  28. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Advanced AWS Interview Questions And Answers, Top 250+AWS Interviews Questions and Answers 2018
    Advanced AWS Interview questions and answers | Top 110 AWS Interview Question and Answers
    Advanced AWS Training in Bangalore | Best Amazon Web Services Training in Bangalore
    Advanced AWS Training in Pune | Best Amazon Web Services Training in Pune
    Advanced AWS Online Training | Best Online AWS Certification Course in india

    ReplyDelete
  29. I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
    python training in chennai
    python course in chennai
    python training in bangalore

    ReplyDelete
  30. The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more content.
    Brand Development Company | Travel Portal Solution | Software Development Solution | Web Design Company in India | Mobile App Development Noida

    ReplyDelete
  31. You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
    python course institute in bangalore
    python Course in bangalore
    python training institute in bangalore

    ReplyDelete
  32. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  33. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog.

    rpa training in chennai |rpa course in chennai|
    rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training

    ReplyDelete
  34. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  35. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.

    Java Training in Chennai

    ReplyDelete
  36. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    Best AWS Training in Chennai | Amazon Web Services Training Institute in Chennai Velachery, Tambaram, OMR
    Advanced AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTMLA ,Marathahalli

    ReplyDelete
  37. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    Best AWS Training in Chennai | Amazon Web Services Training Institute in Chennai Velachery, Tambaram, OMR
    Advanced AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTMLA ,Marathahalli

    ReplyDelete
  38. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS TRAINING IN BANGALORE|NO.1AWS TRAINING INSTITUTES IN BANGALORE

    ReplyDelete
  39. It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium training in bangalore


    ReplyDelete
  40. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

    DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    Good to learn about DevOps at this time.


    devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai | trending technologies list 2018

    ReplyDelete
  41. Thanks for sharing such a wonderful blog on Machine learning.This blog contains so much data about Machine learning ,like if anyone who is searching for the Machine learning data will easily grab the knowledge of Machine learning from this .Requested you to please keep sharing these type of useful content so that other can get benefit from your shared content.
    Thanks and Regards,
    Top institutes for machine learning in chennai
    best machine learning institute in chennai
    artificial intelligence and machine learning course in chennai

    ReplyDelete
  42. Wow!! Really a nice Article. Thank you so much for your efforts. Definitely, it will be helpful for others. I would like to follow your blog..Artificial Intelligence Training in Bangalore. Keep sharing your information regularly for my future reference. Thanks Again.

    ReplyDelete
  43. Great post. I was once checking constantly this weblog and I'm impressed! Extremely useful information specially the closing part. I maintain such information much. I was once seeking this specific information for a very long time. Many thanks and best of luck.
    mi service center in chennai
    redmi service center in chennai
    xiaomi service centre chennai
    redmi service center
    mi service center

    ReplyDelete
  44. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,

    Regards,
    Ramya

    azure training in chennai
    azure training center in chennai
    best azure training in chennai
    azure devops training in chenna
    azure training institute in chennai

    ReplyDelete

  45. Thank you for such a sweet tutorial - all this time later, I've found it and love the end result. I appreciate the time you spent sharing your skills.
    Best Ice Fishing Gloves Best Ice Fishing Gloves Best Ice Fishing Gloves

    ReplyDelete
  46. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.

    Check out : big data training in velachery
    big data hadoop training cost in chennai
    big data training in chennai omr
    big data training in chennai velachery

    ReplyDelete
  47. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai

    ReplyDelete
  48. Really Happy to say your post is very interesting. Keep sharing your information regularly for my future reference. Thanks Again.

    Check Out:
    big data training in chennai chennai tamil nadu
    big data training in velachery
    big data hadoop training in velachery

    ReplyDelete