@@ -44,13 +44,18 @@ To capture the frames you will need to use the functions contained in `camera.h`
44
44
45
45
``` cpp
46
46
#include " camera.h"
47
+ #include " himax.h"
47
48
```
48
49
49
50
Next, let's initialize a camera object and a frame buffer of the size 320* 240 (76'800 bytes).
50
51
51
52
``` cpp
52
- CameraClass cam;
53
- uint8_t fb[320 *240 ];
53
+ HM01B0 himax;
54
+ Camera cam (himax);
55
+ #define IMAGE_MODE CAMERA_GRAYSCALE
56
+ FrameBuffer fb(320,240,2);
57
+
58
+ unsigned long lastUpdate = 0;
54
59
```
55
60
56
61
In the `setup()` function, let's start the Serial communication at `921600` baud rate and initialize the camera using `cam.begin()`.
@@ -59,7 +64,7 @@ In the `setup()` function, let's start the Serial communication at `921600` baud
59
64
void setup() {
60
65
Serial.begin(921600);
61
66
//Init the cam QVGA, 30FPS
62
- cam.begin(CAMERA_R320x240, 30);
67
+ cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
63
68
}
64
69
```
65
70
@@ -68,16 +73,24 @@ In the loop we need to capture each Frame and send it over a serial connection t
68
73
``` cpp
69
74
void loop () {
70
75
// put your main code here, to run repeatedly:
76
+ if(!Serial) {
77
+ Serial.begin(921600);
78
+ while(!Serial);
79
+ }
71
80
81
+ // Time out after 2 seconds and send new data
82
+ bool timeoutDetected = millis() - lastUpdate > 2000;
83
+
72
84
// Wait until the receiver acknowledges
73
85
// that they are ready to receive new data
74
- while(Serial.read() != 1){};
86
+ if(!timeoutDetected && Serial.read() != 1) return;
87
+
88
+ lastUpdate = millis();
75
89
76
90
// Grab frame and write to serial
77
- if (cam.grab (fb) == 0) {
78
- Serial.write(fb, 320 * 240);
91
+ if (cam.grabFrame (fb, 3000 ) == 0) {
92
+ Serial.write(fb.getBuffer(), cam.frameSize());
79
93
}
80
-
81
94
}
82
95
```
83
96
@@ -226,7 +239,7 @@ while (bb.hasRemaining()) {
226
239
227
240
Once all the pixels have been updated, you need to tell the sketch to redraw the image. Additionally we send an acknowledgement back to the arduino sketch to ask it to send the pixels for the next frame. We update the image with ` updatePixels() ` and write ` 1 ` to the serial port for the acknowledgement.
228
241
229
- ``` cpp
242
+ ``` cpp
230
243
myImage.updatePixels();
231
244
232
245
// Ensures that the new image data is drawn in the next draw loop
@@ -252,29 +265,41 @@ The `CaptureRawBytes.ino` Sketch.
252
265
253
266
``` cpp
254
267
#include " camera.h"
268
+ #include " himax.h"
255
269
256
- CameraClass cam;
257
- uint8_t fb[320 *240 ];
270
+ HM01B0 himax;
271
+ Camera cam (himax);
272
+ #define IMAGE_MODE CAMERA_GRAYSCALE
273
+ FrameBuffer fb(320,240,2);
258
274
259
- void setup () {
260
- Serial.begin(921600);
275
+ unsigned long lastUpdate = 0;
261
276
262
- // Init the cam QVGA, 30FPS
263
- cam.begin(CAMERA_R320x240, 30);
277
+ void setup() {
278
+ Serial.begin(921600);
279
+ //Init the cam QVGA, 30FPS
280
+ cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
264
281
}
265
282
266
283
void loop() {
267
284
// put your main code here, to run repeatedly:
285
+ if(!Serial) {
286
+ Serial.begin(921600);
287
+ while(!Serial);
288
+ }
268
289
290
+ // Time out after 2 seconds and send new data
291
+ bool timeoutDetected = millis() - lastUpdate > 2000;
292
+
269
293
// Wait until the receiver acknowledges
270
294
// that they are ready to receive new data
271
- while(Serial.read() != 1){};
295
+ if(!timeoutDetected && Serial.read() != 1) return;
296
+
297
+ lastUpdate = millis();
272
298
273
299
// Grab frame and write to serial
274
- if (cam.grab (fb) == 0) {
275
- Serial.write(fb, 320 * 240);
300
+ if (cam.grabFrame (fb, 3000 ) == 0) {
301
+ Serial.write(fb.getBuffer(), cam.frameSize());
276
302
}
277
-
278
303
}
279
304
```
280
305
0 commit comments