Many are accustomed to the erroneous stereotype that on an eight-bit microcontroller it is impossible to do something more complicated than a weather station. And indeed, most projects on Arduino do not go beyond connecting primitive and annoying sensors to everyone, the potential of the controller is not revealed, so we decided to destroy this stereotype. No, we will not run Linux on the AVR, as we have already done, but in our today’s article, we will look at connecting a real digital camera to ours.
Our hero today is the OV7670 camera module. Briefly – resolution up to 640 × 480 px, up to 30 frames per second, several coding standards.
An interface similar to I2C is used for configuration and communication, and an eight-bit parallel bus is used to directly transfer pixel color data. It would be better to take the Arduino Mega 2560, but for it, there are no ready-made solutions yet, and the circuitry becomes more complicated – you need to add 2 level converters. Therefore, in the example, we will use Arduino Uno. Unfortunately, her memory is not enough to assemble the frame, and there are not enough pins to connect the display, so the computer will collect the image for us.
2 resistors with 4.7 … 10 kΩ are needed for tightening I2C lines and two resistors with 4.7 k for dividing the voltage of the clock signal.
CONNECTING TO ARDUINO IDE
Due to the specifics and the required speed of work, the configuration and work are written without the use of Arduino libraries, in “pure” C. Code to work with the camera:
It is suitable for all Arduino, based on the ATMega328P (Nano, Uno, Pro Mini 328 and clones).
In our example, the Arduino Uno connects to the COM9 port, requests a picture and saves it. Variable addresses and port numbers are specified in the code, if you do not want to bother, it is easier to change the port number in the Device Manager.
For a successful photo, you need to put the desired object in the camera focus and do not move it, since the image is transmitted on the fly and distortions can be made to the frame due to the transmission speed. This can be avoided by taking, for example, Arduino Due. Then there will be enough pins for connecting the display and for a modem to send an image via email. Dare and you will succeed!