AN412

Camera Interface Application Kit

Introduction

The Camera Interface Application Kit combines a VGA camera with a popular RabbitCore module that has removable memory. The pan and tilt movement of the camera can be controlled using two servo motors included with the kit. An infrared motion sensor can be used to trigger an image capture under software control via a Web interface as illustrated in one of several sample application programs included with the Camera Interface Application Kit.

The Camera Interface Application Kit serves as a template for a Rabbit-based system using a camera for remote monitoring, security, asset management, as a supplement to alarm systems, and other triggered events. Because the RCM3365 RabbitCore module provides up to 128 MB of storage and Ethernet functionality, the system allows the user to store and manage photos, send event notifications via e-mail, or send the logged files to an FTP server.

The sample programs and libraries demonstrate event and photo capture, servo motor control, and image data management using Rabbit Semiconductor's robust FAT file system. Since the RCM3365 acts as a server for the system, there is a simple Web interface that allows you to monitor and control the system using a standard Web browser — so you can monitor from anywhere in the world!

The password-protected Web interface allows you to capture photos based on various event triggers — by motion detection, a timed interval, or by a digital input. You can also control what to do with the captured photographs, and get information for each event, including a time stamp, the event trigger, and the action taken after the event. The Camera Interface Application Kit is quick and easy to use for home projects, yet has the software and tools for high-volume commercial applications.

Features

Example Applications

What Else You Will Need

Besides what is supplied with the Application Kit, you will need a PC with an available COM or USB port to program the RCM3365 in the Application Kit. If your PC only has a USB port, you will also need an RS-232/USB converter (Z-World Part No. 540-0070). Your PC also needs an RJ-45 jack to allow an Ethernet interface with the RCM3365 through one of the CAT 5/6 Ethernet cables included with the Camera Interface Application Kit.

Hardware Setup

The Camera Interface Application Kit Getting Started instructions included with the Application Kit show how to set up and program the RCM3365, the servo motors, and the serial camera. Figure 1 shows how the Camera Interposer Board is used to interface the camera and the servo motors to the RCM3365 and the Prototyping Board.


Figure 1. Camera Interface Kit Setup

The following steps from the Camera Interface Application Kit Getting Started instructions summarize the setup process once Dynamic C and the software from the other two CDs have been installed on your PC.

  1. Use a foam mounting strip to hold the pan servo motor in place, and connect it to the PWM3 jack on the Interposer Board. Run the SERVO_CALIB.C sample program from the Dynamic C SAMPLES\CAMERAINTERFACE folder to locate the movement limits of the servo motor and save the PAN values to the user block as prompted in the Dynamic C STDIO window. Finish by pressing the "l" and "r" keys on your PC keyboard with the Dynamic C STDIO window active until the PAN value is midway between the two limits.

  2. Use a foam mounting strip to attach the tilt servo motor to the rotating blade of the pan servo motor, and connect the tilt servo motor to the PWM1 jack on the Interposer Board. Use the SERVO_CALIB.C sample program to locate the movement limits of the servo motor and save the TILT values to the user block as prompted in the Dynamic C STDIO window. The SERVO_CALIB.C sample program will terminate once all four limit values have been saved. Run the SERVO.C sample program and press the "u" and "d" keys on your keyboard as prompted in the STDIO window until the TILT value is midway between the two limits.

  3. Use a foam mounting strip to secure the plastic camera bracket to the blade of the tilt servo motor, and finally use the remaining foam mounting strip the attach the camera to the plastic bracket — remove any labels from the back of the camera board before attaching it with the foam mounting strip.

  4. Use the 4-wire cable with polarized friction-lock plugs to connect the camera to header J9 on the Interposer Board — connect the white plug to the camera, and connect the black plug to header J9.

NOTE The foam mounting strips are included with the Application Kit to facilitate placing and removing the camera and servo motors as you work on developing your application. Consider using epoxy or some other more lasting bonding agent for your production setup.

Sample Programs

Calibration, Setup, and Basic Sample Programs

The following basic sample programs are available for the Camera Interface Application Kit, and can be found in the Dynamic C SAMPLES\CAMERAINTERFACE folder.

In order to run these and other sample programs,

  1. Your RCM3365 must be plugged in via the Camera Interposer Board to the Prototyping Board as described in the Camera Interface Application Kit Getting Started instructions.

  2. Dynamic C and the software from the two other CDs in the Camera Interface Application Kit must be installed and running on your PC.

  3. Set the compiler to run the application in the fast program execution SRAM by selecting "Code and BIOS in Flash, Run in RAM" from the Dynamic C Options > Project Options > Compiler menu.

  4. The programming cable must connect the programming header on the RCM3365 to your PC.

  5. Power must be applied to the RCM3365 via the Camera Interposer Board from the Prototyping Board.

To run a sample program, open it with the File menu, then run it by selecting Run in the Run menu (or press F9).

Sample Programs with Web Browser Interface

Two sample programs are available to demonstrate remote access to the camera via a Web browser interface.

Additional steps are needed to run these two sample programs.

Real-Time Clock

If you plan to use the real-time clock functionality in your application, you will need to set the real-time clock. Set the real-time clock using the onscreen prompts from the Dynamic C SAMPLES\RTCLOCK\SETRTCKB.C sample program. The RTC_TEST.C sample program provides additional examples of how to read and set the real-time clock.

Format Flash Memory

The EVENT_CAPTURE.C sample program uses the Dynamic C FAT file system to store the captured data, and so the NAND flash memories on the RCM3365 must be formatted.

NOTE Any information already stored on a NAND flash memory will be lost when the device is formatted, so be forewarned when formatting the flash memories.

Run the Dynamic C SAMPLES\FileSystem\FMT_DEVICE.C sample program. The Dynamic C STDIO window will open and will display the formatting menu. Both the onboard NAND flash and the removable xD-Picture Card are shown.


With the Dynamic C STDIO window active, type u <Enter> and n <Enter> on your PC keyboard, then 0 <Enter> and 1 <Enter> to format both NAND flash memories—you may omit the 0 or 1 if you do not want to format that memory. Press q <Enter> on your PC keyboard to quit the formatting application when you're done.

If you wish to remove the xD-Picture Card, first unmount it by pressing switches S2 and S3 on the Prototyping Board simultaneously, and confirm that the red LED on the RCM3365 is off. When you insert the xD-Picture Card, remount it by pressing switches S2 and S3 on the Prototyping Board simultaneously, and confirm that the red LED on the RCM3365 is on.

PC Configuration

If you only have one PC or notebook available, disconnect the programming cable once the PANTILT.C or the EVENT_CAPTURE.C sample program is running. Then press the RESET button on the Prototyping Board to restart the RCM3365 in the Run mode.

This section shows how to configure a PC or notebook for the Web interface. If the PC or notebook is already connected to a network, disconnect it from the network. Check with your administrator if you are unable to change the settings as described here since you may need administrator privileges. The screen shots shown here are from Windows 2000, and the interface is similar for other versions of Windows.

  1. Go to the control panel (Start > Settings > Control Panel) and start Network Connections.


  1. Select the network interface card used for the Ethernet interface you intend to use (e.g., TCP/IP Xircom Credit Card Network Adapter) and click on the "Properties" button. Depending on which version of Windows your PC is running, you may have to select the "Local Area Connection" first, and then click on the "Properties" button to bring up the Ethernet interface dialog. Then "Configure" your interface card for a "10Base-T Half-Duplex" or an "Auto-Negotiation" connection on the "Advanced" tab.

NOTE Your network interface card will likely have a different name.


  1. Now select the IP Address tab, and check Specify an IP Address, or select TCP/IP and click on "Properties" to fill in the following fields:

    IP Address : 10.10.6.101

    Netmask : 255.255.255.0

    Default gateway : 10.10.6.1

TIP If you are using a PC that is already on a network, you will disconnect the PC from that network to run these sample programs. Write down the existing settings before changing them to facilitate restoring them when you are finished with the sample programs and reconnect your PC to the network.



  1. Click <OK> or <Close> to exit the various dialog boxes.

Use a CAT 5/6 crossover Ethernet cable to connect the RCM3365 directly to your PC or notebook, or use a CAT 5/6 straight-through Ethernet cable is you are using a hub. Figure 2 shows how to tell the two types of cable apart.


Figure 2. CAT 5/6 Straight-Through and Crossover Cables

Now that the PC setup is done, let's open a Web browser and point it to the following IP address.

If you are running the EVENT_CAPTURE.C sample program, you will be prompted for a user name and password—use "username@isp.com" and "test" respectively. The display should look something like what is shown below for the EVENT_CAPTURE.C sample program, and is similar for PANTILT.C. The CAPTURE button has already been clicked to yield the captured image in the left frame.


If your camera images appear out of focus, the camera focus may be changed by rotating the lens at the front of the camera module.

Click on the UP, DOWN, LEFT, and RIGHT buttons to move the camera around, and the notches along the left and bottom of the image show where the camera is pointing in its range of motion. Check "Auto Refresh" to refresh the image. The dropdown menu at the bottom left controls the resolution of the camera.

The EVENT_CAPTURE.C sample program has the Options button to set the event-trigger options.


You have a choice of a time interval (in seconds), a pushbutton switch or two on the Prototyping Board, or a motion sensor connected to IN0 or IN1 on the Prototyping Board to trigger an image capture. Notification can be via e-mail, an FTP server, or by blinking selected LED(s) on the Prototyping Board. Click UPDATE to confirm your selections.

The images captured will be displayed in the log at the bottom of this interface.


Click on an image to get complete details about its capture and an enlarged view.



Appendix — Software Reference

Sample Program

Let's examine some of the code in the EVENT_CAPTURE.C sample program.

First, the program settings used at startup are defined. These macros are used by the parameters in the function calls, and you may change the macro definitions to suit your needs.

SMTP E-Mail Macros


FTP Server and Client Macros


HTTP Server Macros


FAT Server and Client Macros


TCP/IP Configuration

Now select a setting for the TCP/IP configuration from the TCP_CONFIG.LIB library. TCPCONFIG 1 specifies the following parameters in macros that may be changed in the TCP_CONFIG.LIB library.


Error Message Display

The verbose setting determines the extent to which error messages are displayed. Uncomment the #define definitions and assign a level to display the messages associated with that operation.


Camera Settings


Prototyping Board LED Settings


Web Interface for Handling Camera Images


Dynamic C Memory Mapping and Library Calls


Assign Clock and PWM Frequencies


User Block

Certain function calls on boards or RabbitCore modules other than the RCM3365 involve reading and storing calibration constants from/to the simulated EEPROM in flash memory located at the top of the user block memory area. For example, if the top 2K (3800–3FFF) are reserved, this leaves the address range 0–37FF in the user block available for your application.

The RCM3365 RabbitCore module does not have a reserved area in the user block. The calibration constants for the servo motors take up 8 bytes starting at address 0 in the user block, and that leaves the remainder of the user block available for other applications.

Function Reference Guide

The Dynamic C Lib\CameraInterface\C328_7640.LIB library provides the function calls used with the Camera Interface Application Kit. The definitions needed by the C328_7640.LIB library are provided in the C328_DEFS.LIB library, which contains all the #define statements and constant setup variables.

NOTE Since the C328_7640.LIB library does not uses flow control, we must set the serial port ISR level to 2—otherwise we will miss data because of the periodic interrupt.


_C328_CmdExp


int _C328_CmdExp(char *pcmd, int clen, int retries, char *prsp, int rlen, long tmt);

Description
This function is a state machine that sends and receives commands and responses via a serial port. It will send a command, if necessary, of a specified length, and it will check for a response, if necessary, of a specified length.
Parameters
pcmd
pointer to a C328 command or NULL; if NULL no command is sent, just checks for a response/data.

clen
pcmd length, set to 0 if pcmd is NULL.

retries
if set to 1, the pcmd command is sent and a check for a response is done; the pcmd command is resent if there is no response.

prsp
pointer to a C328 response/data or NULL; if NULL there is no expected response/data.

rlen
prsp length, set to 0 if prsp is NULL.

Return Value
-1 — error
0 — pending
1 — success

_C328_Sync


int _C328_Sync();

Description
Synchronizes the camera module.
Return Value
-1 — error
0 — pending
1 — success

_C328_PowerOff


int _C328_PowerOff();

Description
Puts the camera module in sleep mode. The _C328_Sync() command must be sent to wake up the camera module.
Return Value
-1 — error
0 — pending
1 — success

_C328_Reset


int _C328_Reset(byte type);

Description
Resets the camera module.
Parameter
type
0 = reset the whole system, will reboot and reset all registers.
1 = resets state machines only.


Return Value
-1 — error
0 — pending
1 — success

_C328_Baud


int _C328_Baud(long rate);

Description
Sets the camera module's baud rate. Since the default baud rate is 14400 bps, the host should make the connection at this baud rate each time power is cycled. This function call also changes the Rabbit's baud rate to the rate specified.
Parameter
rate
7200, 14400, 28800, 57600, or 115200

Return Value
-1 — error
0 — pending
1 — success

_C328_SnapShot


int _C328_SnapShot(byte type, int sframe);

Description
Captures a single frame of JPEG still picture data in the buffer.
Parameters
type
0 = compressed picture (JPEG.).
1 = uncompressed picture (raw).


sframe
the number of dropped frames before pic_type occurs (see _C328_GetPicture()).

0 = keep current frame
1 = capture the next frame
... = capture the n'th frame


Return Value
-1 — error
0 — pending
1 — success

_C328_Init


_C328_Init(byte color, byte pre_res, byte jpg_res);

Description
Configures the preview image size and color type.
Parameters
color
1 = 2-bit gray.
2 = 4-bit gray.
3 = 8-bit gray.
4 = 8-bit color.
5 = 12-bit color.
6 = 16-bit color.
7 = JPEG color.


pre_res
Preview resolution.

1 = QQQVGA (80 x 60)
3 = QQVGA (160 x 120)
5 = QVGA (320 x 240)
7 = VGA (640 x 480)


jpg_res
JPEG resolution.

1 = QQQVGA (80 x 64)
3 = QQVGA (160 x 128)
5 = QVGA (320 x 240)
7 = VGA (640 x 480)


Return Value
-1 — error
0 — pending
1 — success

_C328_SetPacket


int _C328_SetPacket(int _size);

Description
Changes the size of the data package that is used to transmit image data from the camera. This function call should be made before making the snapshot function call. The default size is 64 bytes.
Parameter
_size
64 – 512 bytes

Return Value
-1 — error
0 — pending
1 — success

_C328_GetPicture


int _C328_GetPicture(char pic_type, long *pic_data, long *pic_size);

Description
Gets a picture from the camera module.
Parameters
pic_type
1 = snapshot (see _C328_SnapShot() for more information).
2 = preview raw (uncompressed).
5 = preview JPEG (compressed).


pic_data
pointer to buffer to place picture.

pic_size
pointer to buffer that will contain picture size.

Return Value
-1 — error
0 — pending
1 — success

022-0111 Rev. B
Rabbit Semiconductor
www.rabbit.com