OV7670, Generic STM32F103RC and ILI9341 display

What are you developing?
Post Reply
User avatar
RogerClark
Posts: 7481
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

OV7670, Generic STM32F103RC and ILI9341 display

Post by RogerClark » Mon Apr 27, 2015 12:33 pm

Guys,

Just to get the ball rolling..

One project I have been working on, is trying to get an OV7670 camera working with a STM32 board

I've had the OV7670 camera board for at least a year, but I found that it was almost unusable on the Uno or Mega Arduino, because the processor speed (16Mhz) is too low on those AVR boards and they don't have enough RAM to hold a useful image

The other problem with using an AVR Arduino with those camera modules, is that the Non-FIFO module requires an external clock of at least 10Mhz (I think some people manage to get them to work at 8MHz, but I think this is lower than the spec allows)

I know that it is possible to get the AVR's to output a clock, but one method requires special fuses to be blown in the chip to facilitate this, so its hard to just use the Arduino IDE to do this

The STM32 boards look a much better option for connection to the camera, because the bigger processors have up to 64k RAM, which is plenty to store a reasonable resolution frame, they can also generate the 10Mhz (or higher clock) just using PWM, and of course the processor speed of 72Mhz on all the STM32F103 also allow them to read and process the image data more easily that is possible on a 16Mhz AVR board.


Anyway, so much for the theory.

So far, I have managed to generate the clock, and also communicate with the camera via its SCCB bus (a derivation of I2C), however I have had less luck reading an image.

I will post code and an update on this when I have more time.

aasakti
Posts: 1
Joined: Wed Jun 24, 2015 5:30 am

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by aasakti » Tue Jul 07, 2015 6:19 am

Hi roger, I conduct similar project like yours, but I don't know where to start. I want to grab one frame raw rgb format from ov7670 with mini maple clone from baite, and directly send all data to computer via serial. I'm using code from arduino forum, I tried to get response from I2C but nothing happen. Do you have some advices for me? Or do you know another camera with raw rgb output format?

User avatar
RogerClark
Posts: 7481
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by RogerClark » Tue Jul 07, 2015 6:23 am

I have some code, I will try to find it.

OV7670 I2C is non standard, it wont run at the speed of the I2C that the STM32 uses (250kbps)

So I had to slow it down.

I found the code I was messing around with, and it does communicate via Wire aka SCCB to the camera, but I've no idea what setup is being sent to the camera, as I just took some example code, and the camera has hundreds of registers that need to be setup correctly for it to work well.

Also the pixel grabbing code is too slow, even for the STM32 running at 72Mhz, having to monitor the HREF and VSYNC pins as well as waiting for the rising edge of the pixel clock doesnt really work.

In the code I posted, it doesnt even grab the pixel, if you see on line 392 its just incrementing the pixel counter, but this is where you need to put the code to read the pixel.

i.e I never get a consistent pixel count.

I think what MrArduino does its not to bother checking HREF, all he does is wait for VSYNC then count the number of rising edges on the pixel clock (as just looking for rising edges and incrementing or decrementing a counter is possible even on a 16Mhz AVR board.

Really what we need to do is use a Timer input and the DMA to get the data every rising edge of the pixel clock, but I've not had time to work out how to setup both a Timer channel and also a DMA channel to do this.

I know Victor_pv is busy with other DMA and Timer related stuff, but when he's finished with that, he may be able have some ideas on how to setup the code to do the pixel grabbing in DMA,

BTW. To grab the pixels effeciently, you need all 8 bits of the pixel on the same port e.g. PA or PB or PC etc
So I ended up using a STM32F103RCT board, as this has 8 GPIO's on one of the ports

Anyway,

At least you may be able to communiucate over SCCB with your camera

PS. It won't communicate over SCCB unless you supply it with the 10Mhz clock

My code outputs the clock, but I've not looked it it for months, so I can't remember which pin its on.

So you'll need to read the code to work it out
Attachments
ov7670_tests.zip
(27.38 KiB) Downloaded 667 times

stevestrong
Posts: 1827
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by stevestrong » Wed Nov 04, 2015 1:42 pm

Hi Roger,
this would be one of my future projects. I had one Pro Mini working with the camera (w/o FIFO), I could really read pixels showing a real picture!
In that setup I just pushed the pixel data over UART->WiFi bridge to a PHP script (Apache server) which than processed further the image.
Unfortunately, the data link was not always reliable, and the speed awfully slow.
This time I will try to read only a subset of the whole image so that it fits in RAM. Alternatively, I could also use my external 64Mbit SRAM over SPI to temporarily store image data.
Btw, is there any external SRAM lib available for STM32? Maybe even with DMA transfer?
I will test you code and let you know if I can get some usable results.
Cheers,
Steve

stevestrong
Posts: 1827
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by stevestrong » Sun Mar 13, 2016 5:43 pm

Hi all,
I finally managed to get an image from OV7670 camera chip.
I used the SW from Roger as starting point. However, the camera settings won't do the right thing.
I had another project based on ATmega328P pro mini which worked, and I imported those settings.
And also reworked the I2C part which didn't work at the beginning (i don't know exactly why...).
My requirements were:
- use only gray scale 8 bit
- use lowest resolution to fit data into RAM
- use maximum pixel clock speed which still enables SW polling of PCLK.
So I came up to this attached version. The pinning is documented in the INO file.
The image data is sent out to serial port. To visualize it, first copied the serial output to Notepad++, then used the plugin converter HEX->ASCII. Saved the data as img.raw.
Then I used ImageJ (http://imagej.nih.gov/ij/download/win32 ... re8-64.zip), File->Import->RAW, 80(lines)x160(pixels), 8 bit.
I also attached a recorded picture in the package for reference.

Have fun!

ps. next step will be to OCR the picture on STM32 :)
Attachments
STM32_OV7670.7z
STM32_OV7670.INO+ov7670+img1.raw
(13.73 KiB) Downloaded 511 times

User avatar
RogerClark
Posts: 7481
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by RogerClark » Sun Mar 13, 2016 9:40 pm

Thanks Steve

I know the getting the settings right seems to need some sort of Voodoo magic ;-)
( because there are so many of them)

I'm sure that it would be possible for the STM32 to DMA the image from the camera, but I never got around to figuring out how to setup all the regsiters that would be needed do that

But its good you have got something working.

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by zoomx » Mon Mar 14, 2016 9:06 am

Irfanview works too!
The image seems to be 160x80, not 80x160. My brain OCR output is 3487!
Maybe you can drop a passage outputting binary on serial instead of ASCII hex.

User avatar
ahull
Posts: 1657
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by ahull » Mon Mar 14, 2016 9:15 am

You could spit out .ppm which is a simple uncooked image format, that a lot of image editors support, or if you simply need to ASCII-fie it, then simply covert each value to hex first (half the speed or thereabouts of raw though over serial).

More info here.
- Andy Hull -

stevestrong
Posts: 1827
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by stevestrong » Mon Mar 14, 2016 9:43 am

@ahull - thanks, it looks like PGM format would be a real alternative. The serial data amount would be slightly larger, this is nevertheless not relevant, because the serial data is sent after the image was first recorded in an internal buffer array.

@zoomx - the used camera setting allows 160 (pixels) x 120 (lines), out of which I only use the first 80 lines, the resulting image geometry fits to my need.

@Roger - I also made thoughts about to use DMA, but as long as don't need high frame rate (only one steady picture), I finally implemented the simplest solution.
Anyway, to use DMA doesn't seem to be much complicated (theoretically), the trick is to set up a timer in slave trigger mode (i think) to generate the interrupt for DMA as PCLK rising edges are detected. For this, the camera should be set to generate PCLK only when HREF is active (I have the respective line commented out in the INO file).
Last edited by stevestrong on Mon Mar 14, 2016 9:55 am, edited 2 times in total.

User avatar
RogerClark
Posts: 7481
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: OV7670, Generic STM32F103RC and ILI9341 display

Post by RogerClark » Mon Mar 14, 2016 9:45 am

stevestrong wrote: For this, the camera should be set to generate PCLK only when HREF is active.
Umm

Interesting

Is this the normal mode of operation? I think perhaps it is, because a lot of the AVR code ignores HREF etc and just counts pixels

Post Reply