@@ -44,13 +44,16 @@ 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);
54
57
```
55
58
56
59
In the `setup()` function, let's start the Serial communication at `921600` baud rate and initialize the camera using `cam.begin()`.
@@ -59,7 +62,7 @@ In the `setup()` function, let's start the Serial communication at `921600` baud
59
62
void setup() {
60
63
Serial.begin(921600);
61
64
//Init the cam QVGA, 30FPS
62
- cam.begin(CAMERA_R320x240, 30);
65
+ cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
63
66
}
64
67
```
65
68
@@ -68,16 +71,24 @@ In the loop we need to capture each Frame and send it over a serial connection t
68
71
``` cpp
69
72
void loop () {
70
73
// put your main code here, to run repeatedly:
74
+ if(!Serial) {
75
+ Serial.begin(921600);
76
+ while(!Serial);
77
+ }
71
78
79
+ // Time out after 2 seconds and send new data
80
+ bool timeoutDetected = millis() - lastUpdate > 2000;
81
+
72
82
// Wait until the receiver acknowledges
73
83
// that they are ready to receive new data
74
- while(Serial.read() != 1){};
84
+ if(!timeoutDetected && Serial.read() != 1) return;
85
+
86
+ lastUpdate = millis();
75
87
76
88
// Grab frame and write to serial
77
- if (cam.grab (fb) == 0) {
78
- Serial.write(fb, 320 * 240);
89
+ if (cam.grabFrame (fb, 3000 ) == 0) {
90
+ Serial.write(fb.getBuffer(), cam.frameSize());
79
91
}
80
-
81
92
}
82
93
```
83
94
@@ -226,7 +237,7 @@ while (bb.hasRemaining()) {
226
237
227
238
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
239
229
- ``` cpp
240
+ ``` cpp
230
241
myImage.updatePixels();
231
242
232
243
// Ensures that the new image data is drawn in the next draw loop
@@ -252,29 +263,39 @@ The `CaptureRawBytes.ino` Sketch.
252
263
253
264
``` cpp
254
265
#include " camera.h"
266
+ #include " himax.h"
255
267
256
- CameraClass cam;
257
- uint8_t fb[320 *240 ];
268
+ HM01B0 himax;
269
+ Camera cam (himax);
270
+ #define IMAGE_MODE CAMERA_GRAYSCALE
271
+ FrameBuffer fb(320,240,2);
258
272
259
273
void setup() {
260
- Serial.begin(921600);
261
-
262
- // Init the cam QVGA, 30FPS
263
- cam.begin(CAMERA_R320x240, 30);
274
+ Serial.begin(921600);
275
+ //Init the cam QVGA, 30FPS
276
+ cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
264
277
}
265
278
266
279
void loop() {
267
280
// put your main code here, to run repeatedly:
281
+ if(!Serial) {
282
+ Serial.begin(921600);
283
+ while(!Serial);
284
+ }
268
285
286
+ // Time out after 2 seconds and send new data
287
+ bool timeoutDetected = millis() - lastUpdate > 2000;
288
+
269
289
// Wait until the receiver acknowledges
270
290
// that they are ready to receive new data
271
- while(Serial.read() != 1){};
291
+ if(!timeoutDetected && Serial.read() != 1) return;
292
+
293
+ lastUpdate = millis();
272
294
273
295
// Grab frame and write to serial
274
- if (cam.grab (fb) == 0) {
275
- Serial.write(fb, 320 * 240);
296
+ if (cam.grabFrame (fb, 3000 ) == 0) {
297
+ Serial.write(fb.getBuffer(), cam.frameSize());
276
298
}
277
-
278
299
}
279
300
```
280
301
0 commit comments