-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
CameraCaptureRawBytes.ino
92 lines (77 loc) · 2.05 KB
/
CameraCaptureRawBytes.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "camera.h"
#ifdef ARDUINO_NICLA_VISION
#include "gc2145.h"
GC2145 galaxyCore;
Camera cam(galaxyCore);
#define IMAGE_MODE CAMERA_RGB565
#elif defined(ARDUINO_PORTENTA_H7_M7)
// uncomment the correct camera in use
#include "hm0360.h"
HM0360 himax;
// #include "himax.h"
// HM01B0 himax;
// Camera cam(himax);
Camera cam(himax);
#define IMAGE_MODE CAMERA_GRAYSCALE
#elif defined(ARDUINO_GIGA)
#include "ov767x.h"
// uncomment the correct camera in use
OV7670 ov767x;
// OV7675 ov767x;
Camera cam(ov767x);
#define IMAGE_MODE CAMERA_RGB565
#else
#error "This board is unsupported."
#endif
/*
Other buffer instantiation options:
FrameBuffer fb(0x30000000);
FrameBuffer fb(320,240,2);
If resolution higher than 320x240 is required, please use external RAM via
#include "SDRAM.h"
FrameBuffer fb(SDRAM_START_ADDRESS);
...
// and adding in setup()
SDRAM.begin();
*/
FrameBuffer fb;
unsigned long lastUpdate = 0;
void blinkLED(uint32_t count = 0xFFFFFFFF)
{
pinMode(LED_BUILTIN, OUTPUT);
while (count--) {
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
}
}
void setup() {
// Init the cam QVGA, 30FPS
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
blinkLED();
}
blinkLED(5);
}
void loop() {
if(!Serial) {
Serial.begin(115200);
while(!Serial);
}
// Time out after 2 seconds, which sets the (constant) frame rate
bool timeoutDetected = millis() - lastUpdate > 2000;
// Wait for sync byte and timeout
// Notice that this order must be kept, or the sync bytes will be
// consumed prematurely
if ((!timeoutDetected) || (Serial.read() != 1))
{
return;
}
lastUpdate = millis();
// Grab frame and write to serial
if (cam.grabFrame(fb, 3000) == 0) {
Serial.write(fb.getBuffer(), cam.frameSize());
} else {
blinkLED(20);
}
}