6
6
Camera cam (galaxyCore);
7
7
#define IMAGE_MODE CAMERA_RGB565
8
8
#elif defined(ARDUINO_PORTENTA_H7_M7)
9
- #include " hm0360.h"
10
- HM0360 himax;
9
+ // #include "hm0360.h"
10
+ // HM0360 himax;
11
+ #include " himax.h" ;
12
+ HM01B0 himax;
11
13
Camera cam (himax);
12
14
#define IMAGE_MODE CAMERA_GRAYSCALE
13
15
#elif defined(ARDUINO_GIGA)
@@ -33,14 +35,17 @@ If resolution higher than 320x240 is required, please use external RAM via
33
35
// and adding in setup()
34
36
SDRAM.begin();
35
37
*/
38
+ #define CHUNK_SIZE 512 // Size of chunks in bytes
39
+ #define RESOLUTION CAMERA_R320x240
36
40
FrameBuffer fb;
37
41
38
42
unsigned long lastUpdate = 0 ;
39
43
40
44
41
45
void blinkLED (uint32_t count = 0xFFFFFFFF )
42
46
{
43
- pinMode (LED_BUILTIN, OUTPUT);
47
+ pinMode (LED_BUILTIN, OUTPUT);
48
+
44
49
while (count--) {
45
50
digitalWrite (LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
46
51
delay (50 ); // wait for a second
@@ -49,38 +54,71 @@ void blinkLED(uint32_t count = 0xFFFFFFFF)
49
54
}
50
55
}
51
56
57
+ void clearSerialBuffer (){
58
+ while (Serial.available ()){
59
+ Serial.read ();
60
+ }
61
+ Serial.end ();
62
+ Serial.begin (9600 );
63
+ }
64
+
52
65
void setup () {
53
66
// Init the cam QVGA, 30FPS
54
- if (!cam.begin (CAMERA_R320x240 , IMAGE_MODE, 30 )) {
67
+ if (!cam.begin (RESOLUTION , IMAGE_MODE, 30 )) {
55
68
blinkLED ();
56
69
}
57
70
58
71
blinkLED (5 );
72
+
73
+ pinMode (LEDB, OUTPUT);
74
+ digitalWrite (LEDB, HIGH);
75
+ }
76
+
77
+ void sendFrame (){
78
+ // Grab frame and write to serial
79
+ if (cam.grabFrame (fb, 3000 ) == 0 ) {
80
+ byte* buffer = fb.getBuffer ();
81
+ size_t bufferSize = cam.frameSize ();
82
+ digitalWrite (LEDB, LOW);
83
+
84
+ // Split buffer into chunks
85
+ for (size_t i = 0 ; i < bufferSize; i += CHUNK_SIZE) {
86
+ size_t chunkSize = min (bufferSize - i, CHUNK_SIZE);
87
+ Serial.write (buffer + i, chunkSize);
88
+ Serial.flush ();
89
+ delay (1 ); // Optional: Add a small delay to allow the receiver to process the chunk
90
+ }
91
+
92
+ digitalWrite (LEDB, HIGH);
93
+ } else {
94
+ blinkLED (20 );
95
+ }
96
+ }
97
+
98
+ void sendCameraConfig (){
99
+ Serial.write (RESOLUTION);
100
+ Serial.write (IMAGE_MODE);
101
+ Serial.flush ();
102
+ delay (1 );
59
103
}
60
104
61
105
void loop () {
62
106
if (!Serial) {
63
- Serial.begin (921600 );
64
- while (!Serial);
107
+ Serial.begin (115200 , SERIAL_8E2 );
108
+ while (!Serial);
65
109
}
66
110
67
- // Time out after 2 seconds, which sets the (constant) frame rate
68
- bool timeoutDetected = millis () - lastUpdate > 2000 ;
69
-
70
- // Wait for sync byte and timeout
71
- // Notice that this order must be kept, or the sync bytes will be
72
- // consumed prematurely
73
- if ((!timeoutDetected) || (Serial.read () != 1 ))
74
- {
75
- return ;
76
- }
111
+ if (!Serial.available ()) return ;
77
112
78
- lastUpdate = millis ();
79
-
80
- // Grab frame and write to serial
81
- if (cam.grabFrame (fb, 3000 ) == 0 ) {
82
- Serial.write (fb.getBuffer (), cam.frameSize ());
83
- } else {
84
- blinkLED (20 );
113
+ byte request = Serial.read ();
114
+
115
+ switch (request){
116
+ case 1 :
117
+ sendFrame ();
118
+ break ;
119
+ case 2 :
120
+ sendCameraConfig ();
121
+ break ;
85
122
}
123
+
86
124
}
0 commit comments