Web Camera for mbed-os. This sample works on GR-LYCHEE besides GR-PEACH. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Dependencies:   HttpServer_snapshot_mbed-os

You are viewing an older revision! See the latest version

Homepage

For mbed-os sample

For mbed classic sample, please refer to the following.
mbed classic用サンプルについては以下を参照ください。

https://developer.mbed.org/teams/Renesas/code/GR-PEACH_WebCamera_mbed-classic/

Warning! 注意!

When exporting and using it, increase the following stack size.
エクスポートして使用する際は、以下のスタックサイズを増やしてください。

mbed-os/features/FEATURE_LWIP/lwip-interface/lwipopts.h

#define TCPIP_THREAD_STACKSIZE      1024
->
#define TCPIP_THREAD_STACKSIZE      2048

Warning! 注意!

Currently, if you use a static IP address, it does not work properly. If you use a static IP address, please use the mbed classic edition.
現在、静的IPアドレスを使用した場合、正常に動作しません。静的IPアドレスを使用する場合はmbed classic版をご利用ください。
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_WebCamera_mbed-classic/

License

When you use this program, we judge you have agreed to the following contents.
本プログラムを使用する際は、以下の内容に合意した事になります。

https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

Your video will be live at: https://youtu.be/loTD846FEL0 Part1 https://youtu.be/uKm77l8kl3A Part2 https://youtu.be/iwQ9RzwhDNI Part3

What is this ?

Web Camera sample program using GR-PEACH and GR-PEACH AUDIO CAMERA Shield. When you access GR-PEACH from a web browser, the following contents is indicated.

  • Camera input picture
  • Control screen of devices connected to the I2C bus
  • LED control screen

When importing this programming, please put a check in "Update all libraries to the latest version".
I consulted this about HTTPServer and RPC./users/yueee_yt/code/HttpServerSample/

Please refer to following link about GR-PEACH AUDIO CAMERA Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Composition

GR-PEACH, GR-PEACH AUDIO CAMERA Shield, Camera, PC and ethernet cable.
/media/uploads/dkato/web_camera_composition.png
MT9V111 is being used for a camera by this sample program. When using a camera besides MT9V111, please change the setting according to the used camera.
/media/uploads/dkato/grpeachaudiocamera4_whiteback.jpg

main.cpp (camera input config 1)

/** Camera setting **/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


The IP address is acquired from DHCP Server by this sample program. When you'd like to use a static IP address, please change the below.

main.cpp (IP address config)

/** Network setting **/
#define USE_DHCP               (1)                 /* Select  0(static configuration) or 1(use DHCP) */
#if (USE_DHCP == 0)
  #define IP_ADDRESS           ("192.168.0.2")     /* IP address      */
  #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
  #define DEFAULT_GATEWAY      ("192.168.0.3")     /* Default gateway */
#endif

Warning! 注意!

Currently, if you use a static IP address, it does not work properly. If you use a static IP address, please use the mbed classic edition.
現在、静的IPアドレスを使用した場合、正常に動作しません。静的IPアドレスを使用する場合はmbed classic版をご利用ください。
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_WebCamera_mbed-classic/


To specify MAC address, add fllowing function to main.cpp.

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


How to use

  1. Please turn on the power to GR-PEACH and start terminal software.
  2. Please connect an ethernet cable and press the reset button of GR-PEACH.
  3. An IP address is output on terminal.
    The after explanation assumes an IP address "192.168.0.2".
    Please refer to the following link about how to use the terminal.
    The default value of baud rate in mbed is 9600.
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
  4. When "http://192.168.0.2/web_top.htm" is opened by a web browser, top screen is indicated.
    The configuration of the top screen is a menu screen on the left side, a description screen of the sample program on the right side.
    If you click on each menu on the left side of the screen, the screen along the menu is indicated on the right screen.
  5. When you click the "Web camera" in the menu screen, the pictures of a camera is indicated.
    It can be changed at a slider bar in "Wait time" at the timing of a renewal of a camera picture. (Defaults are 500ms.)
  6. When you click the "Setting by I2C" of the menu screen, the control screen of the device connected to the I2C bus is indicated.
    By sending a command of a format listed below("Format of the device set by I2C") in Direct input or File reference, data transmission and reception is possible with respect to devices connected to I2C_SDA and I2C_SCL terminals of I2C.
    (In this configuration, you can execute the camera settings such as white balance and automatic exposure with respect to Camera(MT9V111).)
    The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window.
    When you press the "Clear" button, the log is cleared. When you press the "Save" button, the log is saved.
  7. When you click the "LED On/Off" of the menu screen, the LED control screen is indicated.
    Each switch switches the LED1 ~ LED3 of GR-PEACH to ON or OFF.
    Each switch indicates the current LED state. When the LED is On, the color of switch will change the LED color.
  8. When you click the "Top Page" of the menu screen, the top screen is indicated.


The Terminal indication when being a reset start.

********* PROGRAM START ***********
Network Setting up...
MAC Address is 00:02:f7:f0:00:00
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Network Setup OK




”Page Top” screen
/media/uploads/1050186/web_top2.jpg


”Web Camera” screen
/media/uploads/1050186/camera3.jpg


”Setting by I2C” screen
/media/uploads/1050186/setting_i2c3.jpg

Format of the device set by I2C

Method:I2C addr,data length,data1,data2,data3,...

The details of each parameter is shown below.
For specific settings, check on the specifications of the connected device, you must create a command along the format.

MethodPlease specify one of the following:
"Wr" ・・・ Write functions in I2C
"Rd" ・・・ Read functions in I2C
"WrNoP" ・・・ Write functions in I2C(No STOP condition)
"RdNoP" ・・・ Read functions in I2C(No STOP condition)
I2C addrSet the I2C address of device in hexadecimal.
Ex: If the address is 0x90, set the "90"
data lengthIf Method is "Wr" or "WrNoP", set write size(the size of the data portion) in hexadecimal.
Ex: If the write size is 2 byte(data1, data2), set the "02".
If Method is "Rd" or "RdNoP", set read size in hexadecimal.
Ex: If the read size is 10 byte, set the "0A".
dataIf Method is "Wr" or "WrNoP", set write data in 1 byte unit in hexadecimal.
Ex: If the write data is 0x01 0x02, set "01" in the data1 and "02" in the data2.
If Method is "Rd" or "RdNoP", this parameter is omitted.

An example of the format is shown below.

Wr:90,03,25,45,14

To the device of the I2C address 0x90, the data write of 3Byte(0x25 0x45 0x14)

Rd:90,02

To the device of the I2C address 0x90, the data read of 2Byte


Some of the camera settings commands for MT9V111 is shown below.
In the case of direct input, after writing the commands in a text box, press the "Send" button.
In the case of file reference, after selecting file in the "Choose a text file" button, press the "Send" button.
In MT9V111, the setting value is valid until you shut off the power supply disconnect the USB cable.



”LED On/Off” screen
/media/uploads/1050186/led2.jpg

Processing

  1. At the time of a reset start.
    1. Data for Web pages written on file_"table.h" is registered with FileSystem. ".htm" files and ".js" files are indicated on "file_table.h "as binary data.
    2. The merit of the picture is begun from a camera using GR-PEACH_video library.
    3. To allow LED operation and Terminal output from the Web browser, registration with the mbed-rpc library is done.
    4. EthernetInterface is started and an IP address is acquired from DHCP Server. (It's possible to set a static IP address.)
      The after explanation assumes an IP address "192.168.0.2".
    5. SnapshotHandler (for pictures), FSHandler (for Web page indication) and RPCHandler (for operation) are registered with HTTPServer.

  2. At the time of "Web Camera" click.
    1. "http://192.168.0.2/camera.htm" is opened.
    2. The function in the JavaScript "http://192.168.0.2/camera.js" is called, and a picture acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH accepts a picture acquisition order to SnapshotHandler, GR-PEACH changes the camera picture acquired from GR-PEACH_video library to JPEG in JPEG Converter in a GraphicsFramework library and replies to a web browser.
      The picture size GR-PEACH sends is QVGA (320 x 240). Even biggest VGA (640 x 480) is expanded on the web browser.

  3. At the time of "Setting by I2C" click.
    1. "http://192.168.0.2/i2c_set.htm" is opened.
    2. When you push the "Send" button, the function in the JavaScript "http://192.168.0.2/camera.js" is called, and a control acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH accepts a control acquisition order to SnapshotHandler, GR-PEACH analyzes the command part and execute the I2C communication using the I2C driver.

      The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window.
      In the writing format, GR-PEACH executes data writing by the I2C communication and displays the results of writing on the log window. In success, it is "OK run". In failure, it is "NG run".
      In the reading format, GR-PEACH executes data reading by the I2C communication and displays the results of writing on the log window. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      "Write successful example" screen
      /media/uploads/1050186/i2c_log_write.jpg

      "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_log_read.jpg

      Also when you connect the "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14", etc., GR-PEACH executes the I2C communication. When you set the writing format to the command part of subsequent of "/run,", GR-PEACH executes data writing by the I2C communication and displays the results of writing on the web browser. In success, it is "OK run". In failure, it is "NG run".
      When you set the reading format to the command part of subsequent of "/run,", GR-PEACH executes data reading by the I2C communication and displays the results of writing on the web browser. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      "Write successful example" screen
      /media/uploads/1050186/i2c_write2.jpg

      "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_read2.jpg


  4. At the time of "LED On/Off" click.
    1. "http://192.168.0.2/led.htm" is opened.
    2. When you push each switch, the function in the JavaScript "http://192.168.0.2/mbedrpc.js" is called, and a control acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    3. When GR-PEACH accepts a control acquisition order to RPCHandler, GR-PEACH operates an LED using mbed-rpc library.
    4. Then, an information acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    5. When GR-PEACH accepts an information acquisition order to RPCHandler, GR-PEACH gets the current status of LED using mbed-rpc library, replies to a web browser.


File in the "file_table.h"

It's modified by making reference to something introduced here about the RPC function ("led.htm" and "mbedrpc.js").
/users/yueee_yt/code/HttpServerSample/


When you enable the following thread startup process and thread process, you can set the device in the I2C at Terminal via as well as via a Web browser.
Command to be sent is the same as at the time through a Web browser.

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... Skip ...
}
#endif



Use NTSC input

GR-PEACH WebCamera sample can use NTSC input.
Modify "User Selection" setting of main.cpp as below when using NTSC input.

  1. Set "VIDEO_INPUT_METHOD"
    "VIDEO_INPUT_METHOD" is defined to choice Digital camera or Analog camera.
    If using Analog camera, "VIDEO_INPUT_METHOD" should be "VIDEO_CVBS".

  2. Set "VIDEO_INPUT_FORMAT"
    "VIDEO_INPUT_FORMAT" is defined to choice a format of input image.
    GR-PEACH WebCamera sample encodes a input image to JPEG by JCU(means JPEG encoder/decoder H/W).
    When JCU is used in program, "VIDEO_INPUT_FORMAT" should be "VIDEO_YCBCR422".

  3. Set "USE_VIDEO_CH"
    "USE_VIDEO_CH" is defined to choice NTSC input pin.
    In case of using CN11(NTSC-IN(1A)), "USE_VIDEO_CH" should be 0.
    In case of using CN12(NTSC-IN(1B)), "USE_VIDEO_CH" should be 1.
    We use CN11(NTSC-IN(1A)) this time.

  4. Set "VIDEO_PAL"
    Set 0 because using NTSC.

main.cpp (NTSC camera input config )

/** Camera setting **/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */



Using WiFi BP3595

When using "GR-PEACH Normal", it's possible to do a WiFi connection with BP3595 manufactured by ROHM instead of an ethernet connection. GR-PEACH has a dedicated connector for BP3595. Without the need for complex wiring work, it is capable of high-speed wireless communication of the USB2.0 connection.
/media/uploads/dkato/normal-wifi_01_s.png
https://developer.mbed.org/components/BP3595-for-GR-PEACH/

GR-PEACH、GR-PEACH AUDIO CAMERA Shield、Camera、PC、WiFi access point、BP3595。
/media/uploads/dkato/web_camera_composition_wifi.png

It's necessary to input 5V to VBUS1 to use BP3595. It is possible to supply 5V to VBUS1 by following one of them.

  1. Close GR-PEACH's JP21
    https://developer.mbed.org/teams/Renesas/wiki/Jumper-settings-of-GR-PEACH
  2. Close GR-PEACH AUDIO CAMERA Shield's JP1
    https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Modify "User Selection" setting of main.cpp as below when using BP3595.

main.cpp (Network type config)

#define NETWORK_TYPE           (0)                 /* Select  0(EthernetInterface) or 1(GR_PEACH_WlanBP3595) */
#if (NETWORK_TYPE == 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


NETWORK_TYPEIf using WiFi BP3595, "NETWORK_TYPE" should be "1".
SCAN_NETWORK0: It's connected to a network using WLAN_SSID, WLAN_PSK and WLAN_SECURITY.
1: A network is chosen from a scan result. A scan result is shown to Terminal.
WLAN_SSIDSet the SSID to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".
WLAN_PSKSet the password to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".
WLAN_SECURITYSet the security type to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".



Appendix

Setting of fixed IP address

Only for Windows(R) user:
You need to set up IP address of your PC to match GR-PEACH WebCamera sample when you use fixed IP address.
The default settings are as below.

GR-PEACH192.168.0.2
Subnet mask255.255.255.0
Default Gate Way192.168.0.3


Setting steps of IP address is shown as below.
We will set "192.168.0.3" for the IP address of PC in following steps.

  1. Open the control panel and click "Network and Sharing Center".
    /media/uploads/MasaoHamanaka/change_ip_eng_1.png

  2. Click "Change adapter settings".
    /media/uploads/MasaoHamanaka/change_ip_eng_2.png

  3. Right-click "Local Area Connection" to open a property.
    /media/uploads/MasaoHamanaka/change_ip_eng_3.png

  4. Select "Internet Protocol Version 4(TCP/IPv4)" and click "Properties".
    /media/uploads/MasaoHamanaka/change_ip_eng_4.png

  5. Check "Use the following IP address:" and "Use the following DNS server addresses:".
  6. Enter "192.168.0.3" to "IP address:", and enter "255.255.255.0" to "Subnet mask:".
    "Default gateway:", "Preferred DNS server:", and "Alternate DNS server:" are empty.
    And click "OK".
    /media/uploads/MasaoHamanaka/change_ip_eng_5.png


MATLAB & WebCamera

Do more with WebCamera.. ...

compare images

/media/uploads/pateshian/grp-matlab.pdf

GR-PEACH and MATLAB operations – Image differences – two jpeg (.jpg) image files. MATLAB using R2014A forward

Example – WebCamera –possible applications: Motion detection, Earthquake monitoring (or Camera vibration) Intruder detection, alarm function

Steganography*, (finding hidden messages in original source vs. modified version)

  • Can be independent of WebCamera – SURF section can be skipped for better performance

-MATLAB change detection, using general or WebCamera pictures - here is Scale Invariant difference of two similar pictures

This would be best case results –

File : difference.m (for MatLab) is complex code and Sqrt, Arctangent in SURF algorithms to do jpg to rgb absolute differences – this would not be fast on GR-PEACH. SURF is used as its 3-5x faster than SIFT.


概要

GR-PEACHとGR-PEACH AUDIO CAMERA Shieldを使ったWeb Cameraサンプルプログラムです。
WebブラウザからGR-PEACHにアクセスすると以下が表示されます。

  • Camera入力画像
  • I2Cバスに繋がっているデバイスの制御画面
  • LED操作画面

Importの際は"Update all libraries to the latest version"にチェックを入れてください。
HTTPServer、および、RPCについて、こちらを参考にさせていただきました。/users/yueee_yt/code/HttpServerSample/

GR-PEACH AUDIO CAMERA Shieldについては下記を参照ください。
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

構成

GR-PEACH、GR-PEACH AUDIO CAMERA Shield、Camera、PC、イーサーネットケーブル。
/media/uploads/dkato/web_camera_composition.png
サンプルプログラムではCameraにMT9V111を使用しています。MT9V111以外のCameraを使用する際は使用するCameraにあわせて設定を変更して下さい。
/media/uploads/dkato/grpeachaudiocamera4_whiteback.jpg

main.cpp (camera input config 1)

/** Camera setting **/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


サンプルプログラムではDHCP ServerからIPアドレスを取得します。固定IPアドレスを使用する場合は以下を変更してください。

main.cpp (IP address config)

/** Network setting **/
#define USE_DHCP               (1)                 /* Select  0(static configuration) or 1(use DHCP) */
#if (USE_DHCP == 0)
  #define IP_ADDRESS           ("192.168.0.2")     /* IP address      */
  #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
  #define DEFAULT_GATEWAY      ("192.168.0.3")     /* Default gateway */
#endif

Warning! 注意!

Currently, if you use a static IP address, it does not work properly. If you use a static IP address, please use the mbed classic edition.
現在、静的IPアドレスを使用した場合、正常に動作しません。静的IPアドレスを使用する場合はmbed classic版をご利用ください。
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_WebCamera_mbed-classic/


main.cppの最後にの下記のように関数を追加し、用意したMACアドレスを設定してください。

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


使い方

  1. GR-PEACHに電源を入れ、Terminalソフトを立ち上げます。
  2. イーサーネットケーブルを接続し、GR-PEACHのリセットボタンを押します。
  3. Terminal上にIPアドレスが出力されます。
    以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
    Terminalの使い方は以下のリンクを参照下さい。
    mbedでのボーレートのデフォルト値は9600です。
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
  4. PCのWebブラウザで”http://192.168.0.2/web_top.htm”を開くと、トップ画面が表示されます。
    トップ画面は、左側にメニュー画面、右側にサンプルプログラムの説明画面という構成になっており、
    左画面の各メニューをクリックすると、メニューに沿った画面が右画面に表示されます。
  5. メニュー画面の”Web Camera”をクリックすると、Camera画像が表示されます。
    "Wait time"のスライダーバーでCamera画像の更新タイミングが変更できます。(初期値は500msです)
  6. メニュー画面の"Setting by I2C"をクリックすると、I2Cバスに繋がっているデバイスの制御画面が表示されます。
    直接入力(Direct input)欄又はファイル参照(File reference)欄にて、下記("I2Cによるデバイス設定のフォーマット")に記載されているフォーマットのコマンドを送信する事で、I2CのI2C_SDA,I2C_SCL端子に繋がっているデバイスに対して、データの送受信が可能です。
    (今回の構成ではCamera(MT9V111)に対して、ホワイトバランスや自動露出といったカメラ設定が行えます。)
    "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。
    "Clear"ボタンを押すとログのクリア、"Save"ボタンを押すとログの保存ができます。
  7. メニュー画面の"LED On/Off"をクリックすると、LED操作画面が表示されます。
    各スイッチはGR-PEACHのLED1~LED3をON/OFF切り替えます。
    スイッチはそれぞれGR-PEACHのLED1~LED3の現在の状態を表しており、ONにすると対応するLEDの色になります。
  8. メニュー画面の"Top Page"をクリックすると、 トップ画面が表示されます。


リセットスタート時のTerminal表示

********* PROGRAM START ***********
Network Setting up...
MAC Address is 00:02:f7:f0:00:00
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Network Setup OK



”Page Top”画面
/media/uploads/1050186/web_top2.jpg


”Web Camera”画面
/media/uploads/1050186/camera3.jpg


”Setting by I2C”画面
/media/uploads/1050186/setting_i2c3.jpg

I2Cによるデバイス設定のフォーマット

Method:I2C addr,data length,data1,data2,data3,...

各パラメータの詳細を以下に示します。
具体的な設定値については、接続先のデバイスの仕様をご確認のうえ、フォーマットに沿ってコマンドを作成して下さい。

Method以下のいづれかを指定して下さい
"Wr" ・・・ I2Cでの書き込み
"Rd" ・・・ I2Cでの読み出し
"WrNoP" ・・・ I2Cでの書き込み(STOPコンディション省略)
"RdNoP" ・・・ I2Cでの読み出し(STOPコンディション省略)
I2C addr接続先デバイスのI2Cアドレスを16進数で設定して下さい。
(例) アドレスが0x90の場合、"90"を設定
data lengthMethodが"Wr"又は"WrNoP"の場合、書き込むサイズ(data部分のサイズ)を16進数で設定して下さい。
(例) 書き込むサイズが2Byte(data1,data2)の場合、"02"を設定
Methodが"Rd"又は"RdNoP"の場合は読み取るサイズを16進数で設定して下さい。
(例) 読み取りサイズが10Byteの場合、"0A"を設定
dataMethodが"Wr"又は"WrNoP"の場合、書き込むデータを16進数で1Byte単位で設定して下さい。
(例) 書き込みデータが0x01,0x02の場合、data1に"01"、data2に"02"を設定
"Rd"又は"RdNoP"の場合は省略して下さい。

フォーマットの例を以下に示します。

Wr:90,03,25,45,14

I2Cアドレス0x90のデバイスに対して0x25 0x45 0x14の計3Byteのデータ書き込み

Rd:90,02

I2Cアドレス0x90のデバイスに対して2Byteのデータ読み出し


また、MT9V111用のカメラ設定コマンドをいくつか用意しました。
直接入力(Direct input)の場合は、テキストボックスにコマンドを書いた後、"Send"ボタンを押して下さい。
ファイル参照(File reference)の場合は、"Choose a text file"ボタンをクリックしてファイルを選択した後、"Send"ボタンを押して下さい。
MT9V111の場合、USBケーブルを抜き電源供給を遮断するまで設定値が有効になります。



”LED On/Off”画面
/media/uploads/1050186/led2.jpg

処理の流れ

  1. リセットスタート時
    1. "file_table.h"に書かれたWeb page用データをFileSystemに登録します。 "file_table.h"には".htm"ファイルと".js"ファイルがバイナリデータとして記載されています。
    2. GR-PEACH_videoライブラリを用いてCameraからの画像取得を開始します。
    3. WebブラウザからI2Cでの設定、LED操作、及び、Terminal出力ができるように、mbed-rpcライブラリへの登録を行います。
    4. EthernetInterfaceを起動し、DHCP ServerからIPアドレスを取得します。(固定アドレスを設定することもできます)
      以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
    5. HTTPServerにSnapshotHandler(画像用)、FSHandler(Webページ表示用)、RPCHandler(操作用)を登録します。

  2. "Web Camera"クリック時
    1. "http://192.168.0.2/camera.htm"が開きます。
    2. JavaScript "http://192.168.0.2/camera.js"内の関数が実行され、定期的にSnapshotHandlerへの画像取得要求が発生します。
    3. GR-PEACHはSnapshotHandlerへの画像取得要求を受けると、GR-PEACH_videoライブラリから取得したCamera画像をGraphicsFrameworkライブラリのJPEG ConverterにてJPEGに変換し、Webブラウザに応答します。
      GR-PEACHが送信する画像サイズはQVGA(320 x 240)です。Webブラウザ上で最大VGA(640 x 480)まで拡大されます。

  3. "Setting by I2C"クリック時
    1. "http://192.168.0.2/i2c_set.htm"が開きます。
    2. "Send"ボタンを押すと、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などの操作要求が発生します。
    3. GR-PEACHはRPCHandlerへの操作要求を受けると、"/run,"以降のコマンド部分の解析を行い、I2Cドライバを用いてI2C通信を行います。

      "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。
      書き込みフォーマットの場合、I2C通信でデータ書き込みを行ない、ログウィンドウに書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      読み出しフォーマットの場合、I2C通信でデータ読み出し行ない、ログウィンドウに読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面
      /media/uploads/1050186/i2c_log_write.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面
      /media/uploads/1050186/i2c_log_read.jpg

      また、 "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などで直接接続した場合でも、上記同様のI2C通信を行います。 "/run,"以降のコマンド部分を書き込みフォーマットにすると、I2C通信でデータ書き込みを行ない、ブラウザ上に書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      "/run,"以降のコマンド部分を読み出しフォーマットにすると、I2C通信でデータ読み出しを行ない、ブラウザ上に読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面
      /media/uploads/1050186/i2c_write2.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面
      /media/uploads/1050186/i2c_read2.jpg

  4. "LED On/Off"クリック時
    1. "http://192.168.0.2/led.htm"が開きます。
    2. 各スイッチを操作すると、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/led1/write 1" などの操作要求が発生します。
    3. GR-PEACHはRPCHandlerへの操作要求を受けると、mbed-rpcライブラリを通してLEDのOn/Off操作を行います。
    4. その後、RPCHandlerへ "http://192.168.0.2/rpc/led1/read" などの情報取得要求が発生します。
    5. GR-PEACHはRPCHandlerへの情報取得要求を受けると、mbed-rpcライブラリを通してLEDの現在の状態を取得し、Webブラウザに応答します。


"file_table.h"内のファイル

RPC機能("led.htm"、"mbedrpc.js")については、こちらで紹介されているものを参考に一部変更しています。
/users/yueee_yt/code/HttpServerSample/


なお、サンプルプログラムにて、以下のスレッド起動処理とスレッド処理を有効すると、 Webブラウザ経由と同様にTerminal経由でもI2Cでのデバイス設定ができます。
送信するコマンドはWebブラウザ経由時と同じです。

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... 省略 ...
}
#endif



NTSC入力を使う

GR-PEACH WebCameraサンプルはNTSC入力に対応しています。
NTSC入力を使用する場合は以下のようにmain.cppのUser Selection の設定を変更してください。

  1. VIDEO_INPUT_METHODを設定する
    VIDEO_INPUT_METHODは使用するカメラを選択します。
    アナログカメラを使用する場合は、VIDEO_CVBSを設定します。

  2. VIDEO_INPUT_FORMATを設定する
    VIDEO_INPUT_FORMATは入力画像の形式を設定します。
    GR-PEACH WebCameraサンプルでは、カメラからの入力画像に対し、
    JCU(JPEGエンコーダ/デコーダ)でエンコードを行います。
    JCUでエンコードを行う場合はVIDEO_YCBCR422を設定します。

  3. USE_VIDEO_CHを設定する
    USE_VIDEO_CHはNTSC入力端子を設定します。
    0はCN11(内側 NTSC-IN(1A))、1はCN12(外側 NTSC-IN(1B))を使用します。
    ここではCN11(内側 NTSC-IN(1A))を使用することにします。

  4. VIDEO_PALを設定する
    NTSCを使用するため、0を設定します。

main.cpp (NTSC camera input config )

/** Camera setting **/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */



WiFi BP3595を使う

「GR-PEACH Normal」をご使用の場合、イーサーネット接続の代わりにROHM製BP3595を使用したWiFi接続を行うことができます。GR-PEACHにはBP3595専用のコネクタが搭載されています。複雑な配線作業をする必要なく、USB2.0接続の高速無線通信が可能です。
/media/uploads/dkato/normal-wifi_01_s.png
https://developer.mbed.org/components/BP3595-for-GR-PEACH/

GR-PEACH、GR-PEACH AUDIO CAMERA Shield、Camera、PC、WiFiアクセスポイント、BP3595。
/media/uploads/dkato/web_camera_composition_wifi.png

BP3595を使用する為にはVBUS1に5Vを入力する必要があります。以下のいずれかの対応でVBUS1に5Vを供給する事が可能です。

  1. GR-PEACHのJP21をショートする。
    https://developer.mbed.org/teams/Renesas/wiki/Jumper-settings-of-GR-PEACH
  2. GR-PEACH AUDIO CAMERA ShieldのJP1をショートする。
    https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

BP3595を使用する場合はmain.cppのUser Selection の設定を変更してください。

main.cpp (Network type config)

#define NETWORK_TYPE           (0)                 /* Select  0(EthernetInterface) or 1(GR_PEACH_WlanBP3595) */
#if (NETWORK_TYPE == 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


NETWORK_TYPEWiFi BP3595を使用する場合は、1を選択します。
SCAN_NETWORK0: WLAN_SSID、WLAN_PSK、WLAN_SECURITYを使ってネットワークに接続します。
1: スキャン結果からネットワークを選択します。スキャン結果はTerminalに表示されます。
WLAN_SSID接続先アクセスポイントのSSIDを設定します。SCAN_NETWORK=1の場合は使用しません。
WLAN_PSK接続先アクセスポイントのパスワードを設定します。SCAN_NETWORK=1の場合は使用しません。
WLAN_SECURITY接続先アクセスポイントのセキュリティタイプを設定します。SCAN_NETWORK=1の場合は使用しません。



付録

固定IPアドレスの設定

以降はWindows PCでの固定IPアドレス設定方法を記載します。
GR-PEACH WebCameraサンプルで、固定IPアドレスを使用する場合、
PC側のIPアドレスをプログラムに合うよう変更する必要があります。
デフォルトでは、以下の設定になっています。

GR-PEACH192.168.0.2
Subnet mask255.255.255.0
Default Gate Way192.168.0.3


以下にIPアドレス設定方法を記載します。
PCに設定するIPアドレスは、192.168.0.3を設定します。

  1. コントロールパネルを開き、「ネットワークと共有センター」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_1.png

  2. 「アダプターの設定の変更」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_2.png

  3. 「ローカルエリア接続」を右クリックし、プロパティを開きます。
    /media/uploads/MasaoHamanaka/change_ip_jpn_3.png

  4. 「インターネット プロトコル バージョン 4(TCP/IPv4)」を選択し、「プロパティ」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_4.png

  5. 「次のIPアドレスを使う」および「次のDNSサーバーのアドレスを使う」をチェックします。
  6. IPアドレスに192.168.0.3、サブネットマスクに255.255.255.0を入力します。
     デフォルトゲートウェイ、優先DNSサーバーおよび代替DNSサーバーを空欄にし、OKをクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_5.png

All wikipages