Gadget Renesas

Linking Ideas and Electronics

アイテム

GR-PEACH Special Page

Web server part 3

Let’s set up Web camera!

Overview

GR-PEACH can conduct the image processing of the camera. Let us introduce the case using GR-PEACH as a Web camera, with a security digital camera which is commercially available.

login

Preparations

Get ready GR-PEACH, a USB cable (microB type), a LAN cable, a microSD card, a digital camera
and a GR-PEACH AUDIO+CAMERA SHIELD released from CORE CORPORATION.

login
login login

 

How to connect with digital camera

login

 

Sample program for Web camera

First of all, save "index.htm" file in microSD for browser indication.

Click the following link with the right button; and execute “save the object in a file", for download.

index.htm

Next, insert microSD in an SD socket in the back side of GR-PEACH and copy to build the following sketch program in gr_sketch.cpp and write it down into GR-PEACH. 


#include 
#include "SD.h"
#include "HTTPServer.h"
#include "EthernetInterface.h"
#include "RomRamFileSystem.h"
#include "Camera.h"

RomRamFileSystem romramfs("romram");
#define NUM_WEBFILES 1
const char mount_files[NUM_WEBFILES][13] = { //name should be 8.3 format
		"index.htm"};

/** Network setting **/
// #define IP_ADDRESS           ("192.168.11.2")     /* IP address      */
// #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
// #define DEFAULT_GATEWAY      ("192.168.11.3")     /* Default gateway */

Camera camera; // default CMOS CAMERA. In case of NTSC, create camera(0).
EthernetInterface network;
File myFile;

char JpegBuffer[1024 * 200]__attribute((aligned(8)));  //8 bytes aligned!;

static int snapshot_req(const char ** pp_data) {
	int encode_size;
	encode_size = camera.getJpeg(JpegBuffer, sizeof(JpegBuffer));
	*pp_data = (const char *) JpegBuffer;
	return encode_size;
}

static void mount_romramfs(void) {
	FILE * fp;
	romramfs.format();

	char write_path[20];

	for (int i = 0; i < NUM_WEBFILES; i++) {
		myFile = SD.open(mount_files[i], FILE_READ);
		if (myFile) {
			sprintf(write_path, "/romram/%s", mount_files[i]);
			fp = fopen(write_path, "w");
			// read from the file until there's nothing else in it:
			while (myFile.available()) {
				putc(myFile.read(), fp);
			}
			// close the file:
			myFile.close();
			fclose(fp);
		}
	}
}

void setup(void) {

	Serial.begin(9600);
    Serial.print("********* PROGRAM START ***********\r\n");

	if (!SD.begin()) {
		return;
	}
	mount_romramfs();   //RomRamFileSystem Mount
	
	camera.begin();
	
	Serial.print("Network Setting up...\r\n");
	if (network.init() != 0) {                             //for DHCP Server
	//if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
		return;
	}
	if (network.connect() != 0) {
		return;
	}

 	Serial.print("MAC Address is ");
 	Serial.println(network.getMACAddress());
 	Serial.print("IP Address is ");
	Serial.println(network.getIPAddress());
 	Serial.print("NetMask is ");
	Serial.println(network.getNetworkMask());
 	Serial.print("Gateway Address is ");
	Serial.println(network.getGateway());
 	Serial.println("Network Setup OK\r\n");

	SnapshotHandler::attach_req(&snapshot_req);
	HTTPServerAddHandler("/camera"); //Camera
	FSHandler::mount("/romram", "/");
	HTTPServerAddHandler("/");
	HTTPServerStart(80);
	
}

void loop() {
}

                                
 


Operation check for the Web camera

Operation check for the Web camera After writing the program in GR-PEACH, start serial monitors such as Teraterm, then press a reset button on GR-PEACH.
The IP address acquired by DHCP will be shown up as follows.

login



Put the displayed IP address into the URL on the Web browser.
The camera image will be reflected on the display as following.

login

 


share