|
| 1 | +--- |
| 2 | +title: Using the Camera Connector on the GIGA Display Shield |
| 3 | +description: 'Learn how to use the camera connector with the GIGA Display Shield.' |
| 4 | +author: Benjamin Dannegård |
| 5 | +tags: [Display, Camera, Arducam] |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +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. |
| 11 | + |
| 12 | +## Hardware & Software Needed |
| 13 | + |
| 14 | +- [Arduino GIGA R1 WiFi](/hardware/giga-r1) |
| 15 | +- [Arduino GIGA Display Shield]() |
| 16 | +- [Arduino IDE](https://www.arduino.cc/en/software) |
| 17 | +- HM01B0 or HM0360 camera |
| 18 | +- [Arduino_H7_Video library](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video) |
| 19 | +- [Arducam_dvp library](https://www.arduino.cc/reference/en/libraries/arducam_dvp/) |
| 20 | + |
| 21 | +## Downloading the Library and Core |
| 22 | + |
| 23 | +The Arduino Mbed OS Giga Boards core contains most of the libraries you need to work with the shield's camera connector. To install the core 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. Now open the library tab on the left, search for **Arducam_dvp**, and install this library. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Compatible Cameras |
| 28 | + |
| 29 | +The GIGA Display Shield is compatible with the following cameras: |
| 30 | + |
| 31 | +- [HM01B0](https://www.arducam.com/product/hm01b0-qvga-monochrome-dvp-camera-module-for-arduino-giga-r1-wifi-board/) |
| 32 | +- [HM0360](https://www.arducam.com/product/hm0360-vga-monochrome-dvp-camera-module-for-arduino-giga-r1-wifi-board/) |
| 33 | + |
| 34 | +Connect the camera to the connector on the front of the display shield as shown in the image below. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +## Full Sketch |
| 39 | + |
| 40 | +Open the example sketch by going to **File > Examples > Camera > GigaCameraDisplay** in the Arduino IDE. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +Whichever of the compatible cameras you are using the sketch will include libraries and definitions for them all, meaning no modification to the sketch is necessary to get it working. The sketch will capture frames into the framebuffer and then print a live camera feed to the display. |
| 45 | + |
| 46 | +```arduino |
| 47 | +#include "arducam_dvp.h" |
| 48 | +#include "Arduino_H7_Video.h" |
| 49 | +#include "dsi.h" |
| 50 | +#include "SDRAM.h" |
| 51 | +
|
| 52 | +// This example only works with Greyscale cameras (due to the palette + resize&rotate algo) |
| 53 | +#define ARDUCAM_CAMERA_HM01B0 |
| 54 | +
|
| 55 | +#ifdef ARDUCAM_CAMERA_HM01B0 |
| 56 | +#include "Himax_HM01B0/himax.h" |
| 57 | +HM01B0 himax; |
| 58 | +Camera cam(himax); |
| 59 | +#define IMAGE_MODE CAMERA_GRAYSCALE |
| 60 | +#elif defined(ARDUCAM_CAMERA_HM0360) |
| 61 | +#include "Himax_HM0360/hm0360.h" |
| 62 | +HM0360 himax; |
| 63 | +Camera cam(himax); |
| 64 | +#define IMAGE_MODE CAMERA_GRAYSCALE |
| 65 | +#elif defined(ARDUCAM_CAMERA_OV767X) |
| 66 | +#include "OV7670/ov767x.h" |
| 67 | +// OV7670 ov767x; |
| 68 | +OV7675 ov767x; |
| 69 | +Camera cam(ov767x); |
| 70 | +#define IMAGE_MODE CAMERA_RGB565 |
| 71 | +#error "Unsupported camera (at the moment :) )" |
| 72 | +#elif defined(ARDUCAM_CAMERA_GC2145) |
| 73 | +#include "GC2145/gc2145.h" |
| 74 | +GC2145 galaxyCore; |
| 75 | +Camera cam(galaxyCore); |
| 76 | +#define IMAGE_MODE CAMERA_RGB565 |
| 77 | +#error "Unsupported camera (at the moment :) )" |
| 78 | +#endif |
| 79 | +
|
| 80 | +// The buffer used to capture the frame |
| 81 | +FrameBuffer fb; |
| 82 | +// The buffer used to rotate and resize the frame |
| 83 | +FrameBuffer outfb; |
| 84 | +// The buffer used to rotate and resize the frame |
| 85 | +Arduino_H7_Video Display(800, 480, GigaDisplayShield); |
| 86 | +
|
| 87 | +void blinkLED(uint32_t count = 0xFFFFFFFF) |
| 88 | +{ |
| 89 | + pinMode(LED_BUILTIN, OUTPUT); |
| 90 | + while (count--) { |
| 91 | + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) |
| 92 | + delay(50); // wait for a second |
| 93 | + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW |
| 94 | + delay(50); // wait for a second |
| 95 | + } |
| 96 | +} |
| 97 | +
|
| 98 | +uint32_t palette[256]; |
| 99 | +
|
| 100 | +void setup() { |
| 101 | + // Init the cam QVGA, 30FPS |
| 102 | + if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) { |
| 103 | + blinkLED(); |
| 104 | + } |
| 105 | +
|
| 106 | + // Setup the palette to convert 8 bit greyscale to 32bit greyscale |
| 107 | + for (int i = 0; i < 256; i++) { |
| 108 | + palette[i] = 0xFF000000 | (i << 16) | (i << 8) | i; |
| 109 | + } |
| 110 | +
|
| 111 | + Display.begin(); |
| 112 | + dsi_configueCLUT((uint32_t*)palette); |
| 113 | +
|
| 114 | + outfb.setBuffer((uint8_t*)SDRAM.malloc(1024*1024)); |
| 115 | +
|
| 116 | + // clear the display (gives a nice black background) |
| 117 | + dsi_lcdClear(0); |
| 118 | + dsi_drawCurrentFrameBuffer(); |
| 119 | + dsi_lcdClear(0); |
| 120 | + dsi_drawCurrentFrameBuffer(); |
| 121 | +} |
| 122 | +
|
| 123 | +void loop() { |
| 124 | +
|
| 125 | + // Grab frame and write to another framebuffer |
| 126 | + if (cam.grabFrame(fb, 3000) == 0) { |
| 127 | +
|
| 128 | + // double the resolution and transpose (rotate by 90 degrees) in the same step |
| 129 | + // this only works if the camera feed is 320x240 and the area where we want to display is 640x480 |
| 130 | + for (int i = 0; i < 320; i++) { |
| 131 | + for (int j = 0; j < 240; j++) { |
| 132 | + ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320]; |
| 133 | + ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320]; |
| 134 | + ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320]; |
| 135 | + ((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320]; |
| 136 | + } |
| 137 | + } |
| 138 | + dsi_lcdDrawImage((void*)outfb.getBuffer(), (void*)dsi_getCurrentFrameBuffer(), 480, 640, DMA2D_INPUT_L8); |
| 139 | + dsi_drawCurrentFrameBuffer(); |
| 140 | + } else { |
| 141 | + blinkLED(20); |
| 142 | + } |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +## Conclusion |
| 147 | + |
| 148 | +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 core. Now you should see a live feed from the camera on your GIGA Display Shield! |
| 149 | + |
0 commit comments