GIGA Display Shield Camera Connector Guide

Learn how to use the camera connector with the GIGA Display Shield.

Introduction

The GIGA Display Shield comes with an Arducam® camera connector. In this tutorial, we will go through what cameras are compatible with the display shield, how to connect the camera, and how to run a sketch to stream the camera feed to the display.

Hardware & Software Needed

Downloading the Library and Board Package

The Arduino Mbed OS Giga Boards Board Package contains most of the libraries you need to work with the shield's camera connector. To install the Board Package for GIGA boards, navigate to Tools > Board > Boards Manager or click the Boards Manager icon in the left tab of the IDE. In the Boards Manager tab, search for giga and install the latest Arduino Mbed OS Giga Boards version, the Arduino_H7_Video library library is included in the Board Package. Now open the library tab on the left, search for Arducam_dvp, and install this library.

Library tab in the Arduino IDE
Library tab in the Arduino IDE

Compatible Cameras

The GIGA Display Shield is compatible with the following cameras:

Connect the camera to the connector on the front of the display shield as shown in the image below.

Camera connected to the GIGA Display Shield
Camera connected to the GIGA Display Shield

Note the direction of the shield, physically the connector can be plugged in from both directions, but it will only work when facing the same direction as the display.

Full Sketch

Open the example sketch by going to File > Examples > Camera > GigaCameraDisplay in the Arduino IDE.

Opening the example sketch in the Arduino IDE
Opening the example sketch in the Arduino IDE

Whichever of the compatible cameras you are using the sketch will include libraries and definitions for them all, meaning only one line needs to be changed depending on what camera you will be using. The line that needs to be changed is this one:

1#define ARDUCAM_CAMERA_HM01B0

Depending on what camera you are using it should be changed accordingly:

  • HM01B0:
    #define ARDUCAM_CAMERA_HM01B0
  • HM0360:
    #define ARDUCAM_CAMERA_HM0360
  • GC2145:
    #define ARDUCAM_CAMERA_GC2145
  • OV7675:
    #define ARDUCAM_CAMERA_OV767x

The sketch will then capture frames into the framebuffer and print a live camera feed to the display.

Note: make sure to connect/disconnect the camera when the board is powered off.

1#include "arducam_dvp.h"
2#include "Arduino_H7_Video.h"
3#include "dsi.h"
4#include "SDRAM.h"
5
6// This example only works with Greyscale cameras (due to the palette + resize&rotate algo)
7#define ARDUCAM_CAMERA_HM01B0
8
9#ifdef ARDUCAM_CAMERA_HM01B0
10#include "Himax_HM01B0/himax.h"
11HM01B0 himax;
12Camera cam(himax);
13#define IMAGE_MODE CAMERA_GRAYSCALE
14#elif defined(ARDUCAM_CAMERA_HM0360)
15#include "Himax_HM0360/hm0360.h"
16HM0360 himax;
17Camera cam(himax);
18#define IMAGE_MODE CAMERA_GRAYSCALE
19#elif defined(ARDUCAM_CAMERA_OV767X)
20#include "OV7670/ov767x.h"
21// OV7670 ov767x;
22OV7675 ov767x;
23Camera cam(ov767x);
24#define IMAGE_MODE CAMERA_RGB565
25#elif defined(ARDUCAM_CAMERA_GC2145)
26#include "GC2145/gc2145.h"
27GC2145 galaxyCore;
28Camera cam(galaxyCore);
29#define IMAGE_MODE CAMERA_RGB565
30#endif
31
32// The buffer used to capture the frame
33FrameBuffer fb;
34// The buffer used to rotate and resize the frame
35FrameBuffer outfb;
36// The buffer used to rotate and resize the frame
37Arduino_H7_Video Display(800, 480, GigaDisplayShield);
38
39void blinkLED(uint32_t count = 0xFFFFFFFF)
40{
41 pinMode(LED_BUILTIN, OUTPUT);
42 while (count--) {
43 digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
44 delay(50); // wait for a second
45 digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW
46 delay(50); // wait for a second
47 }
48}
49
50uint32_t palette[256];
51
52void setup() {
53 // Init the cam QVGA, 30FPS
54 if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
55 blinkLED();
56 }
57
58 // Setup the palette to convert 8 bit greyscale to 32bit greyscale
59 for (int i = 0; i < 256; i++) {
60 palette[i] = 0xFF000000 | (i << 16) | (i << 8) | i;
61 }
62
63 Display.begin();
64
65 if (IMAGE_MODE == CAMERA_GRAYSCALE) {
66 dsi_configueCLUT((uint32_t*)palette);
67 }
68 outfb.setBuffer((uint8_t*)SDRAM.malloc(1024 * 1024));
69
70 // clear the display (gives a nice black background)
71 dsi_lcdClear(0);
72 dsi_drawCurrentFrameBuffer();
73 dsi_lcdClear(0);
74 dsi_drawCurrentFrameBuffer();
75}
76
77#define HTONS(x) (((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00))
78
79void loop() {
80
81 // Grab frame and write to another framebuffer
82 if (cam.grabFrame(fb, 3000) == 0) {
83
84 // double the resolution and transpose (rotate by 90 degrees) in the same step
85 // this only works if the camera feed is 320x240 and the area where we want to display is 640x480
86 for (int i = 0; i < 320; i++) {
87 for (int j = 0; j < 240; j++) {
88 if (IMAGE_MODE == CAMERA_GRAYSCALE) {
89 ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320];
90 ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320];
91 ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320];
92 ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320];
93 } else {
94 ((uint16_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480] = HTONS(((uint16_t*)fb.getBuffer())[i + j * 320]);
95 ((uint16_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480 + 1] = HTONS(((uint16_t*)fb.getBuffer())[i + j * 320]);
96 ((uint16_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480] = HTONS(((uint16_t*)fb.getBuffer())[i + j * 320]);
97 ((uint16_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480 + 1] = HTONS(((uint16_t*)fb.getBuffer())[i + j * 320]);
98 }
99 }
100 }
101 dsi_lcdDrawImage((void*)outfb.getBuffer(), (void*)dsi_getCurrentFrameBuffer(), 480, 640, IMAGE_MODE == CAMERA_GRAYSCALE ? DMA2D_INPUT_L8 : DMA2D_INPUT_RGB565);
102 dsi_drawCurrentFrameBuffer();
103 } else {
104 blinkLED(20);
105 }
106}

Note: Depending on the camera being used the captured resolution might be smaller than the screen. If this is the case, there will be a black bar displayed next to the captured feed, it will not be automatically centered.

Conclusion

This tutorial went through how to connect a compatible camera to the shield and also how to test it out quickly with the example sketch included in the Board Package. Now you should see a live feed from the camera on your GIGA Display Shield!

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.