PRECISION Manual for CMOS CAMERA MODULE INTERFACE WITH ARDUINO BOARDS FOR ROBOTICS VISION ( Sr. No:............................) AIM: To study the CMOS Camera interface to ARDUINO UNO and display the image in TFT LCD Display. ARDUINO: Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.. You can tinker with your Uno without worrying too much about doing something wrong, worst case scenario you can replace the chip for a few dollars and start over again. The Arduino UNO is the best board to get started with electronics and coding. If this is your first experience tinkering with the platform, the UNO is the most robust board you can start playing with. The UNO is the most used and documented board of the whole Arduino family. Getting started The Getting Started with Arduino Uno page contains all the information you need to configure your board, use the Arduino Software (IDE), and start tinkering with coding and electronics. From the Tutorials section you can find examples from libraries and built-in sketches as well other useful information to expand your knowledge of the Arduino hardware and software. Tech specs Microcontroller Operating Voltage Input Voltage (recommended) Input Voltage (limit) Digital I/O Pins PWM Digital I/O Pins Analog Input Pins DC Current per I/O Pin DC Current for 3.3V Pin Flash Memory SRAM EEPROM Clock Speed LED_BUILTIN Length Width ATmega328P 5V 7-12V 6-20V 14 (of which 6 provide PWM output) 6 6 20 mA 50 mA 32 KB (ATmega328P) of which 0.5 KB used by bootloader 2 KB (ATmega328P) 1 KB (ATmega328P) 16 MHz 13 68.6 mm 53.4 mm Getting Started with Arduino UNO This document explains how to connect your Uno board to the computer and upload your first sketch. The Arduino Uno is programmed using the Arduino Software (IDE), our Integrated Development Environment common to all our boards and running both online and offline. For more information on how to get started with the Arduino Software visit the Getting Started page. Use your Arduino Uno on the Arduino Web IDE All Arduino boards, including this one, work out-of-the-box on the Arduino Web Editor, you only need to install Arduino Create Agent to get started. The Arduino Web Editor is hosted online, therefore it will always be up-to-date with the latest features and support for all boards. Follow this simple guide to start coding on the browser and upload your sketches onto your board. Use your Arduino Uno on the Arduino Desktop IDE If you want to program your Arduino Uno while offline you need to install the Arduino Desktop IDE The Uno is programmed using the Arduino Software (IDE), our Integrated Development Environment common to all our boards. Before you can move on, you must have installed the Arduino Software (IDE) on your PC, as explained in the home page of our Getting Started. Connect your Uno board with an A B USB cable; sometimes this cable is called a USB printer cable The USB connection with the PC is necessary to program the board and not just to power it up. The Uno automatically draw power from either the USB or an external power supply. Connect the board to your computer using the USB cable. The green power LED (labelled PWR) should go on. Install the board drivers If you used the Installer, Windows - from XP up to 10 - will install drivers automatically as soon as you connect your board. If you downloaded and expanded the Zip package or, for some reason, the board wasn't properly recognized, please follow the procedure below. Click on the Start Menu, and open up the Control Panel. While in the Control Panel, navigate to System and Security. Next, click on System. Once the System window is up, open the Device Manager. Look under Ports (COM & LPT). You should see an open port named "Arduino UNO (COMxx)". If there is no COM & LPT section, look under "Other Devices" for "Unknown Device". Right click on the "Arduino UNO (COmxx)" port and choose the "Update Driver Software" option. Next, choose the "Browse my computer for Driver software" option. Finally, navigate to and select the driver file named "arduino.inf", located in the "Drivers" folder of the Arduino Software download (not the "FTDI USB Drivers" sub-directory). If you are using an old version of the IDE (1.0.3 or older), choose the Uno driver file named "Arduino UNO.inf" Windows will finish up the driver installation from there. See also: step-by-step screenshots for installing the Uno under Windows XP. Open your first sketch Open the LED blink example sketch: File > Examples >01.Basics > Blink. Open the LED blink example sketch: File > Examples >01.Basics > Blink. UNO Load Blink Select your board type and port You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino board. UNO BoardType Select the serial device of the board from the Tools | Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port. Upload the program Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar. UNO Upload A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! You've gotten Arduino up-and-running. If you have problems, please see the troubleshooting suggestions. Learn more on the Desktop IDE See this tutorial for a generic guide on the Arduino IDE with a few more infos on the Preferences, the Board Manager, and the Library Manager. The OV7670 Camera Module This module allows you to capture images in VGA format (640x480). It can perform some initial processing and transfer the images to microcontrollers, such as the Arduino, via the SCCB interface. The camera unit allows you to form images in other formats like CIF (352x240) and others. Manual adjustments up to 40x30 are also possible. The maximum image transfer rate (VGA) can reach 30 frames per second. The camera also performs pre-processing of images, such as exposure control, amplification, white balance, and more. Also supported are various image encoding options (YUV, various types of RGB). Data transfer is carried out using the SCCB protocol. OV7670 Specs VGA resolution (640 x 480) QVGA (320 x 240) CIF (352 x 240) QCIF (176 × 144); Transmission speed up to 30 fps, several ways to encode the image RAW RGB, RGB 565/555, YUV / YCbCr 4: 2: 2 Connections Between the OV7670 and Arduino Uno OV7670 VSYNC XCLCK PCLCK SIOD SIOC DO D3 D4 D7 3.3V RESET GND PWDN Arduino uno PIN2 PIN3(must be level shifted from 5V => 3.3V) PIN12 A4 (I2C data) A5 (I2C clock) A0.. A3 (pixel data bits 0..3) PIN4..PIN7 (pixel data bits 4..7) 3.3V 3.3V GND GND Connections Between the TFT Display and Arduino uno DC CS RESET SPI data SPI clock VCC BL GND PIN 8 (5V => 3.3V) PIN 9 (5V => 3.3V) PIN 10 (5V => 3.3V) PIN 11 (5V => 3.3V) PIN 13 (5V => 3.3V) 5V/3.3V (depending on jumper position on the TFT board) 3.3V GND Interfacing OV7670 digital camera with arduino uno: capturing video and displaying it on TFT Lcd For this project i am using OV7670 lower power camera module with 0.3 MP resolution. Lcd is 2.8 inch TFT lcd with 240×320 pixels on screen. Arduino uno is used in the project but other arduino boards can also be used with little modification in the code. Important: Both the OV7670 camera module and 2.8 inch TFT graphic lcd are working on 3.3v power supply where as my arduino is working on 5v. So i used level shifters in my project for interfacing arduino with camera and tft. I advise you to use arduino powered on 3.3v power supply or better to used arduino nano whose 3.3v operating board is perfect for our project, this will reduce extra level shifter hardware from project. I found a pretty neat and clean circuit on internet which i used to build my project. You can replace level shifter ics with normal level shift resistor circuit. OV7670 camera with arduino and 2.8 inch tft LCD Interfacing a 2.8 inch SPI TFT that has a ILI9341 chip to an Arduino Uno. All you need is eight 1K resistors. Most people use a 4050 IC. Images of 2.8' TFT SPI 240*320 Project code is too lengthy and complex for beginners. Its not easy to explain each and every statement here. You might need to add some libraries in your arduino library folder for succefully compiling the project code for example you might need LiveOV7670Library Adafruit_GFX_Library One just need to make the circuit. Burn the code in arduino and its all done. Your camera will start working. For future work one can interface an SD card with arduino and can save the camera feed in SD card to view latterly as video or image. The project can be used as security camera. // set EXAMPLE to EXAMPLE_TFT_BUFFERED in setup.h to activate #include "setup.h" #if EXAMPLE == 1 #include "Arduino.h" #include "Adafruit_ILI9341_mod.h" #include <BufferedCameraOV7670_QQVGA_10hz.h> #include <BufferedCameraOV7670_QQVGA.h> #include <BufferedCameraOV7670_QVGA.h> #include <BufferedCameraOV7670_QQVGA_10hz_Grayscale.h> #include "GrayScaleTable.h" uint8_t rotation=3; #define GRAYSCALE_PIXELS 0 #if GRAYSCALE_PIXELS == 1 BufferedCameraOV7670_QQVGA_10hz_Grayscale camera; #else BufferedCameraOV7670_QQVGA_10hz camera(CameraOV7670::PIXEL_RGB565); //BufferedCameraOV7670_QQVGA camera(CameraOV7670::PIXEL_RGB565, BufferedCameraOV7670_QQVGA::FPS_5_Hz); //BufferedCameraOV7670_QQVGA camera(CameraOV7670::PIXEL_RGB565, BufferedCameraOV7670_QQVGA::FPS_2_Hz); //BufferedCameraOV7670_QVGA camera(CameraOV7670::PIXEL_RGB565, BufferedCameraOV7670_QVGA::FPS_2p5_Hz); #endif #define TFT_CS 9 // TFT CS pin is connected to arduino pin 8 #define TFT_RST 10 // TFT RST pin is connected to arduino pin 9 #define TFT_DC 8 // TFT DC pin is connected to arduino pin 10 Adafruit_ILI9341_mod tft = Adafruit_ILI9341_mod(TFT_CS, TFT_DC, TFT_RST); // this is called in Arduino setup() function void initializeScreenAndCamera() { // bool cameraInitialized = camera.init(); // Serial.begin(9600); tft.begin(); tft.setRotation(rotation); tft.fillScreen(ILI9341_BLACK); tft.setCursor(15, 50); tft.setTextColor(ILI9341_RED); tft.setTextSize(2); tft.println("PRECISION INSTRUMENTS"); tft.setCursor(40, 70); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); tft.println("CHENNAI"); delay(3000); tft.setCursor(10, 100); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); tft.println("ARDUINO CAMERA"); // testText(); delay(5000); bool cameraInitialized = camera.init(); if (cameraInitialized) { // flash green screen if camera setup was successful tft.fillScreen(ILI9341_GREEN); delay(1000); tft.fillScreen(ILI9341_BLACK); } else { // red screen if failed to connect to camera tft.fillScreen(ILI9341_RED); delay(3000); } } inline void sendLineToDisplay() __attribute__((always_inline)); inline void screenLineStart(void) __attribute__((always_inline)); inline void screenLineEnd(void) __attribute__((always_inline)); inline void sendPixelByte(uint8_t byte) __attribute__((always_inline)); // Normally it is a portrait screen. Use it as landscape uint8_t screen_w = ILI9341_TFTWIDTH; uint8_t screen_h = ILI9341_TFTHEIGHT; uint8_t screenLineIndex; // this is called in Arduino loop() function void processFrame() { screenLineIndex = screen_h; noInterrupts(); camera.waitForVsync(); camera.ignoreVerticalPadding(); for (uint8_t i = 0; i < camera.getLineCount(); i++) { camera.readLine(); sendLineToDisplay(); } interrupts(); } static const uint16_t byteCountForDisplay = camera.getPixelBufferLength() < screen_w*2 ? camera.getPixelBufferLength() : screen_w*2; void sendLineToDisplay() { if (screenLineIndex > 0) { screenLineStart(); #if GRAYSCALE_PIXELS == 1 for (uint16_t i=0; i<camera.getLineLength(); i++) { sendPixelByte(graysScaleTableHigh[camera.getPixelByte(i)]); sendPixelByte(graysScaleTableLow[camera.getPixelByte(i)]); } #else for (uint16_t i=0; i<byteCountForDisplay; i++) { sendPixelByte(camera.getPixelByte(i)); } #endif screenLineEnd(); } } void screenLineStart() { if (screenLineIndex > 0) screenLineIndex--; tft.startAddrWindow(screenLineIndex, 0, screenLineIndex, screen_w-1); // tft.setAddrWindow(screenLineIndex, 0, screenLineIndex, screen_w-1); } void screenLineEnd() { tft.endAddrWindow(); } void sendPixelByte(uint8_t byte) { SPDR = byte; // tft.spiwrite(byte); //Serial.print(byte); // this must be adjusted if sending loop has more/less instructions asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); #if GRAYSCALE_PIXELS == 1 asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); #endif } #endif