ArduCAM Shield Rev.B released, significant improvement!

Featured

Improved Features:

  • Provide two board options, ArduCAM-LF has both LCD and FIFO, ArduCAM-F only has FIFO
  • ArduCAM-LF provide live video and real time snapshot
  • Support both Arduino UNO and MEGA1280/2560 boards (but not limited to these boards)
  • 3Mbit memory space and support  the RAW RGB fromat resolution up to 640×600,
  • Support 2MP (1600×1200) JPEG image capture and storage
  • Various Arduino firmware application demonstrations  for IOT (Internet of things)
  • User can add their own camera modules to the ArduCAM library easily

Schematic :

Please download the schematic of ArduCAM Rev.B for connection and pin out.

How to Buy:

Please purchase the ArduCAM shield and camera modules from distributor UCTronics.

Demonstration Video:

 

 

ArduCAM – An Arduino Camera Shield

Featured

ArduCAM is Arduino based open source camera platform which is well mated to Arduino boards.  It now supports Arduino UNO board and we will add support Mega1280/2560 and new released Leonardo,  Maple and Chipkit are also in planning. 

Features:

  • 3.2 inch TFT LCD Screen 320×240 resolution
  • Support various of camera modules
  • Support larger than 8GB SD/TF card read and write
  • FAT filesystem support
  • 320×240 RGB565/RGB555 BMP file format capture and playback
  • Trigger in and trigger out events ability
  • GPIO expansion support
  • Well mated with Arduino board  

LCD Module

The TFT LCD is 3.2 inch QVGA ( 320×240 ) LCD, it use SSD1289 LCD controller and consists of up to 172,800 bytes (240 x 320 x 18 / 8) Graphic Display Data RAM (GDDRAM). It interfaces to Arduino with 8bit 8080 type bus interface. It is good to know that Henning Karlsen has already develop a open source library named UTFT for Arudino, it also support this LCD controller.

Camera Module

We will add support (already supported sensors are marked in red) to various of  camera module which use Omnivision and Aptina CMOS image sensor, something like

  • 0.3 Mega Pixel : OV7670, OV7675, OV7725
  • 1.3 Mega Pixel : OV9650, OV9655, MT9M111
  •  2   Mega Pixel : OV2640, MT9D111, MT9D112
  •  3   Mega Pixel : OV3640
  •  5   Mega Pixel : OV5642, MT9P111

MCU Platform

Two libraries are written for ArduCAM shield, one is UTFT library which is used for accessing the LCD screen, the other is ArduCAM library which supports different kind of camera modules registers configuration via I2C and accessing ArduChip internal control registers. ArduCAM library provide simple interface for sensor initialization, triggering a capture and read image data to external SD/TF card.

ArduChip

ArduCAM incorporate with a ArduChip, which used to do the DMA transfer between camera module and LCD internal GDDRAM, control the camera data stream timing and do the GPIO expansion.  When start the state machine will enter preview mode, the Chip DMA the camera data to LCD screen directly with frame rate upto 30fps. Once the capture button is pressed, the state machine will freeze the screen and enter capture mode,  the MCU will read the image data from LCD’s GDDRAM and save to SD/TF card.  

ArduCAM

Limitations

We can’t live without the LCD screen because we use the LCD GRAM as a frame buffer. The image resolution is limited by the LCD screen, so  it only supports  QVGA(320×240) preview  resolution or equivalent 150KB size (around SXGA 1280×1024) JPEG image. It is OK for machine vision and small applications.

Due to the speed limitation of AVR series MCU, and all the Read and Write access to LCD GRAM is emulated by IO operation, saving a 320×240 RGB555 BMP into SD/TF card will take up 10 seconds and transmit the image over bluetooth needs 15 seconds. It is OK for the demostration,  but I do think it will be resolved when we move to more powerful MCU platform like Maple and Chipkit.

Introduction

CMOS camera modules are widely used in mobile phones and web cameras, and the price is pretty low when in volume. Therefore it becomes the best choice for embedded applications.  However there is barrier in both hardware and software when using camera modules and block the hobbyists off. That why ArduCAM is born. ArduCAM is an open source project for CMOS camera modules, which hide the complexity of capturing high speed high resolution image data stream and provide the source code configuration for camera modules. User can freely control the ArduCAM shield to accomplish their different tasks. The first release of ArduCAM shield target for Arduino and its compatible platforms like Maple, Chipkit. And we plan to move to more powerful platform like Raspberry PI, Beagle board or Pandaboard.

 What ArduCAM can do

  • Take still image

Take BMP or JPEG image and save to SD/TF memory card

  • Real time preview on 3.2” LCD screen

Mounting with proper lenses, can be used as microscope or astronomical telescope

  • Wireless image transmission

Connected to extra Bluetooth or WiFi module, achieve wireless image transmission

  • Color and object recognition

With proper image processing algorithm,  simple image procesing algorithm can be achieved

What ArduCAM can’t do for now

  • Real time video recording

Arduino like platforms are too slow to catch up the 30fps video stream

  • Real time video processing

Arduino like platforms are too slow and has insufficient memory to do the video processing

How ArduCAM use external trigger from a sensor

The ArduCAM shield has 6 general purpose IOs which can be set as input or output and greatly extend the power for the Arduino board which has limited IO resources. The structure of the IOs in the ArduCAM shield is the same as the one in the AVR chip, it has a direction register(DDR), a input register(PIN) and output register(PORT). In this demonstration, we will illustrate how to set the GPIOs in the ArduCAM shield as an input and use a PIR sensor triggering the shield to start a capture.

PIR(Pyroelectric InfraRed sensors ) is a motion sensor for use in alarm burglar systems, visitor presence monitoring, light switches and robots. PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and don’t wear out. For that reason they are commonly found in appliances and gadgets used in homes or businesses. They are often referred to as PIR, “Passive Infrared”, “Pyroelectric”, or “IR motion” sensors.Power it up and wait 1-2 seconds for the sensor to get a snapshot of the still room. If anything moves after that period, the ‘alarm’ pin will go high. We can use the PIR sensor to trigger the ArduCAM shield to take a photo for the scene.

 

 

 Pin connection diagram between ArduCAM and PIR.In this demo we will use the IO0 connected to the PIR module.

 

Firmware guide:

In setup() routine we have to set the GPIOs to input like this

void setup()
{
  myCAM.write_reg( ARDUCHIP_DDR, 0x00);
}

 In the loop() routine we have to polling the status of the GPIOs and start to take a photo when the PIR triggered.

void loop()
{
...  
  while(1)
  {
    gpio_trig = myCAM.read_reg(ARDUCHIP_PIN);            //Read external trigger from GPIO0~5
    if (gpio_trig & 0x01)      //if GPIO0 is high
    {
       k = k + 1;
       itoa(k, str, 10); 
       strcat(str,".bmp");    //Generate file name
       GrabImage(str);
    }

  }
...  
}

 Full Arduino code can be downloaded from here.

End.

Tutorial

This tutorial will demonstrate how to use the ArduCAM shield on Arduino UNO board, aim the point and press a snapshot button you will get a BMP picture saved on the SD/TF card.

When you get the package you will have the following items:

*1x ArduCAM shield

*1x Arduino UNO compatible board

*1x Supported camera module

You will still need a Micro SD / TF card to complete this tutorial.

First plug the camera module to the ArduCAM shield, please note that the camera module may have more pins than the socket. So please align the pins on the left and leave the right pins left open like the way on the picture.

 

Next step we have to insert the Micro SD/TF card into the card socket. And make sure the 2 way DIP switch on the ArduCAM shield is on the ON position.

Download the latest ArduCAM firmware library from http://www.arducam.com/download section. Then unzip the library to the Arduino/libraries directory like this way. There are two libraries needed for ArduCAM shield, one is ArduCAM library and the other named UTFT4ArduCAM library which is derived from the UTFT library for the proper operation for the 3.2″ LCD.

 

 

 

 

 

 

 

Open the example folder unziped from the zip file, you will see several demos for different camera module. Then open the demo according to the camera module you have. Hera use MT9D111 for example. Select the correct COM port for your Arduino UNO board and upload the firmware.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

After successfully downloading the firmware, wait for the board to restart. You will see the preview video on the LCD screen, aim the point you want to take a picture and press buttom the LCD screen will freeze and wait for 10 seconds, a 320×240 RGB565 BMP file will be saved.

 

 Here is a very nice picture get from MT9D111 camera module.
 

New 5MP OV5642 Camera Module (support JPEG output)

Key specifications

  • active array size: 2592 x 1944
  • power supply:
    core: 1.5VDC + 5% (internal regulator)
    analog: 2.6 ~ 3.0V
    I/O: 1.7 ~ 3.0V
  • output formats :
    (8-bit): YUV(422/420) / YCbCr422,
    RGB565/555/444, CCIR656,
    8-bit compression data,
    8/10-bit raw RGB data
  • lens size: 1/4″
  • input clock frequency: 6 ~ 27 MHz
  • shutter: rolling shutter
  • maximum image transfer rate:
    5 megapixel (2592×1944): 15 fps (and any size scaling down from 5 megapixel)
    1080p (1920×1080): 30 fps
    720p (1280×720): 60 fps
    VGA (640×480): 60 fps
    QVGA (320×240): 120 fps
  • scan mode: progressive
  • pixel size: 1.4 µm x 1.4 µm
  •  image area: 3673.6 µm x 2738.4 µm
Sample picture captured by OV5642 with 2592x1944 QSXGA full resolution

Sample picture captured by OV5642 with 2592×1944 QSXGA full resolution

This image is captured at night in the room light with the full resolution (2592×1944).

OV5642 1080P

Sample picture captured by OV5642 with 1080P(1920×1080) video mode

This image is captured  in the room light with the 1080P video output (1920×1080).

ArduCAM Pinouts

 

Pin definition:

Signals Description Signals Description
+3.3V +3.3V from shield +5V +5V from Arduino
D1 3.3V logic version of D1 D0 3.3V logic version of D0
D3 3.3V logic version of D3 D2 3.3V logic version of D2
D5 3.3V logic version of D5 D4 3.3V logic version of D4
D7 3.3V logic version of D7 D6 3.3V logic version of D6
D9 3.3V logic version of D9 D8 3.3V logic version of D8
+3.3V +3.3V from shield GND Ground
IO1 Expansion GPIO1 IO0 Expansion GPIO0
D11 3.3V logic version of D11 D13 3.3V logic version of D13
IO2 Expansion GPIO2 D12 3.3V logic version of D12
IO3 Expansion GPIO3 D10 3.3V logic version of D10
IO5 Expansion GPIO5 IO4 Expansion GPIO4
A0 3.3V logic version of A0 A1 3.3V logic version of A1
A2 3.3V logic version of A2 A3 3.3V logic version of A3
A4 3.3V logic version of A4 A5 3.3V logic version of A5
GND Ground GND Ground

 Arduino board use IOs to emulate parallel bus to access ArduChip internal registers and external LCD registers. User should instantiate the ArduCAM and UTFT class which use parallel bus before the setup routine. The function of each signal list as follows:

Signals Functions
D[7:0] Parallel bus data[7:0]
A0 Parallel bus RD, active low
A1 Parallel bus WR, active low
A2 Parallel bus RS
A3 Parallel bus CS, active low
A4 I2CSDA for Camera Module
A5 I2CSCL for Camera Module
D10 LCD chipselect, active low
D9 SD/TF chipselect, active low
D11 SPI MOSI
D12 SPI MISO
D13 SPI SCLK

 The following is a piece of the code for demonstration of the instantiate the ArduCAM and UTFT class.

#define SD_CS 9 

//UTFT(byte model, int RS, int WR, int RD, int CS)
UTFT myGLCD(ITDB32S,A2,A1,A0,10);   
//ArduCAM(byte model,int RS, int WR, int RD, int CS)
ArduCAM myCAM(OV7670,A2,A1,A0,A3);

void setup()
{
  // Setup I2C port
  Wire.begin();   
  if (!SD.begin(SD_CS)) 
  {
    while (1);
  }
  // Setup ArduChip
  myCAM.InitCAM();
  // Setup the LCD
  myGLCD.InitLCD();
  ShowStart();
  delay(2000);
}

 

 

ArduChip Registers

ArduChip is the core of the ArduCAM, which incoperates a Altera MAXII CPLD EPM240 as main processor. The main task of the ArduChip is do the real time DMA transfer between Camera module and the 3.2″ LCD and act as Arduino, Camera and LCD bus multiplexer. It also provides AVR like GPIO expansion, it can be set as input or output and resolve the problem of limited IO resources in Arduino board. The GPIOs can be used as event trigger in and trigger out. 

Address Name Mode Description
0×00 DDR R/W Data Direction RegisterBit[7:6]: ReservedBit[5]: IO5 input/output selectionBit[4]: IO4 input/output selectionBit[3]: IO3 input/output selectionBit[2]: IO2 input/output selectionBit[1]: IO1 input/output selectionBit[0]: IO0 input/output selection1 = output, 0 = input
0×01 PORT R/W OutputPortRegisterThe value will reflect on the Pin IO0~IO6 correspondinglyBit[7:6]: ReservedBit[5]: IO5 output valueBit[4]: IO4 output valueBit[3]: IO3 output valueBit[2]: IO2 output valueBit[1]: IO1 output valueBit[0]: IO0 output value1 = High, 0 = Low
0×03 MODE R/W Bus ModeDetermine who is owner of the data bus, only one owner is allowed.Bit[7:3]: ReservedBit[2]: MCU read LCD busBit[1]: Camera write LCD busBit[0]: MCU write LCD bus
0×80 PIN RO Input Pin RegisterThe value will reflect the IO0~IO6 Pin status correspondinglyBit[7:6]: ReservedBit[5]: IO5 input valueBit[4]: IO4 input valueBit[3]: IO3 input valueBit[2]: IO2 input valueBit[1]: IO1 input valueBit[0]: IO0 input value1 = High, 0 = Low
0×81 Trigger RO Trigger input RegisterBit[7:2]: ReservedBit[1]: Capture button status, 0 = pressed, 1 = releasedBit[0]: Frame start signal, equal to VSYNC
0×82 Revision ID RO Bit[7:6]: Revision integer partBit[5:0]: Revision decimal partFirst revision released ID is 0×40, means V1.00

Examples:

 ArduCAM GPIO Write demo

// ArduCAM GPIO Write demo (C)2012 Lee
// web: http://www.ArduCAM.com
// This program is a demo of how to use GPIOs in ArduCAM to turn on/off
// LEDs or trigger any ohter devices.
//
// This program requires the ArduCAM library.
//
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>
#include <SoftwareSerial.h>

#define ARDUCHIP_DDR       0x00  //GPIO direction register
#define ARDUCHIP_PORT      0x01  //GPIO output register
#define ARDUCHIP_PIN       0x80  //GPIO input register
//ArduCAM(byte model,int RS, int WR, int RD, int CS)
ArduCAM myCAM(OV7670,A2,A1,A0,A3);
//Uncomment if use software serial
SoftwareSerial mySerial(8, 9); // RX, TX
void setup()
{
  mySerial.begin(9600);
  mySerial.println("hello");
  myCAM.write_reg( ARDUCHIP_DDR, 0xff);     //Set GPIO as output

}

void loop()
{
  uint8_t val = 0xff;
  uint8_t read_val;
  while(1)
  {
    delay(1000);
    myCAM.write_reg( ARDUCHIP_PORT, val);       //Output Register
    val = val ^ 0xff;                           //toggle output value
    read_val = myCAM.read_reg(ARDUCHIP_PORT);   //Read it back
    mySerial.write(read_val);
  }
  return;

}

 ArduCAM GPIO Read demo 

// ArduCAM GPIO Read demo (C)2012 Lee
// web: http://www.ArduCAM.com
// This program is a demo of how to use GPIOs in ArduCAM to read 
// trigger signals from any ohter devices.
//
// This program requires the ArduCAM library.
//
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>
#include <SoftwareSerial.h>

#define ARDUCHIP_DDR       0x00  //GPIO direction register
#define ARDUCHIP_PORT      0x01  //GPIO output register
#define ARDUCHIP_PIN       0x80  //GPIO input register

//ArduCAM(byte model,int RS, int WR, int RD, int CS)
ArduCAM myCAM(OV7670,A2,A1,A0,A3);
//Uncomment if use software serial
SoftwareSerial mySerial(8, 9); // RX, TX
void setup()
{
  mySerial.begin(9600);
  mySerial.println("hello");
  myCAM.write_reg( ARDUCHIP_DDR, 0x00);     //Set GPIO as input
}

void loop()
{
  uint8_t temp;
  while(1)
  {
    temp = myCAM.read_reg(ARDUCHIP_PIN);      //Read from GPIO
    mySerial.write(temp);                  //Send value read from GPIO
    delay(1000);
  }
  return;

}