I am trying to interface a OV5640 camera module to Arduino Mega 2560 in Eclipse IDE using C language . However I am not able to figure out the registers that need to be initialised , for the camera to start capturing pictures .

There are Arduino libraries to deal with setup and image transfer , however I do not wish to use them . I would like to code in C , without using any library . I just need to know which registers need to be accessed and modified to get the camera working .

For reference - I am trying to create a CCTV based system that will record picture based on intruder presence . The entire project is written in C language without any libraries .

Data sheet for OV5640 -https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf

Take a look in this link to get an idea about the kind of program it'll be.
How to get 38 Khz clock from Timer 0/2 in Arduino Mega 2560?

  • Tackling this kind of project usually requires learning how to read data sheets for yourself. Failing that, study the libraries until you understand what they are doing well enough to make a simpler version in plain C and change whatever else you may not like about them. Strictly speaking, the goal of plain C development without libraries is off topic here, because "Arduino" is primarily a library-centric approach to C++ development. Commented Jun 17, 2017 at 22:15

1 Answer 1


Arducam gives you all the info you need on the necessary register settings. The register values for each color space and resolution are defined in this header while the initialization sequence, image format selection and image capture process among other stuff, are implemented here and documented if you look closely at the variable names and compiler directives.

EDIT: More details

Lines 327 - 372 contain the relevant initialization sequence for this specific camera. For instance, assuming you want JPG images, line 335 marks the start of the needed settings:

wrSensorReg16_8(0x3103, 0x11);
wrSensorReg16_8(0x3008, 0x82); delay(100);
wrSensorRegs16_8(OV5640YUV_Sensor_Dvp_Init); delay(500);
wrSensorReg16_8(0x4407, 0x0C);  # assuming you arent using the Arducam shield or OV5640 5MP Plus

What wrSensorReg16_8 does is pretty obvious: write the 8-bit 2nd argument into the register specified in the 16-bit 1st argument. wrSensorRegs16_8 merely does the same thing for multiple register-value pairs passed into it. OV5640YUV_Sensor_Dvp_Init, OV5640_JPEG_QSXGA and OV5640_QSXGA2QVGA are all structs defined in the header I mentioned earlier; they contain the rest of the register-value pairs you need to know about. Ultimately, these settings should give you 320x240 JPEG, I think.

You can't use the start_capture method since you don't have the ArduCAM FIFO so you'll have to start grabbing frames yourself (and buffering them somewhere very quickly; transmitting the bytes as you read them is out of the question) by paying attention to VSYNC, HREF and PCLK. Look at the timing diagrams in the datasheet. I assume you'll only be taking frames occasionally since a Mega won't do for video. If you're very lucky, you'll get a nice image on your first try but on the whole, be ready to spend serious time studying the datasheet, ArduCAM code and other 0V5640-related code on the web or just go with the OV7670 which has more examples/tutorials.

  • @TisteAndil thank you for those links. I could gather some idea about the required registers .however it would be nice , if you can list them in order . I'm new to embedded programming and seeing the list of registers , I feel I am gonna miss out some important register settings. So it'll be helpful if you can make a list out of those entire register set that needs to be set . thanks Commented Jun 16, 2017 at 4:20
  • @BoudhayanDev Edited my answer. Commented Jun 17, 2017 at 21:44
  • thanks a lot . I guess you are right . Even with these setup configuration , clicking the image and getting the data will turn out to be seriously difficult . If you have solution for that please add it in your answer . If not it's alright . Thanks for your answer. Commented Jun 18, 2017 at 10:10
  • @BoudhayanDev You just need more experience before working on a project of this complexity. You can either work with a ready-made solution like the ArduCAM or just go ahead with your current plan, no matter how long it takes. Commented Jun 18, 2017 at 18:21
  • Thanks . You are right. I'll need to know a bit more in detail before I can succeed with this project. One last question - which camera do you suggest ? Should I go for the 2640 ,5640 or 7640 variant ? I will be also interfacing a SD card with it to store the captured image . Which camera module is relatively simpler to work with for a beginner? @TisteAndii Commented Jun 18, 2017 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.