Skip to content

Portenta Vision Shield: Getting Started, fix arduino code [PC-910] #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ To capture the frames you will need to use the functions contained in `camera.h`

```cpp
#include "camera.h"
#include "himax.h"
```

Next, let's initialize a camera object and a frame buffer of the size 320*240 (76'800 bytes).

```cpp
CameraClass cam;
uint8_t fb[320*240];
HM01B0 himax;
Camera cam(himax);
#define IMAGE_MODE CAMERA_GRAYSCALE
FrameBuffer fb(320,240,2);

unsigned long lastUpdate = 0;
```

In the `setup()` function, let's start the Serial communication at `921600` baud rate and initialize the camera using `cam.begin()`.
Expand All @@ -59,7 +64,7 @@ In the `setup()` function, let's start the Serial communication at `921600` baud
void setup() {
Serial.begin(921600);
//Init the cam QVGA, 30FPS
cam.begin(CAMERA_R320x240, 30);
cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
}
```

Expand All @@ -68,16 +73,24 @@ In the loop we need to capture each Frame and send it over a serial connection t
```cpp
void loop() {
// put your main code here, to run repeatedly:
if(!Serial) {
Serial.begin(921600);
while(!Serial);
}

// Time out after 2 seconds and send new data
bool timeoutDetected = millis() - lastUpdate > 2000;

// Wait until the receiver acknowledges
// that they are ready to receive new data
while(Serial.read() != 1){};
if(!timeoutDetected && Serial.read() != 1) return;

lastUpdate = millis();

// Grab frame and write to serial
if (cam.grab(fb) == 0) {
Serial.write(fb, 320*240);
if (cam.grabFrame(fb, 3000) == 0) {
Serial.write(fb.getBuffer(), cam.frameSize());
}

}
```

Expand Down Expand Up @@ -226,7 +239,7 @@ while (bb.hasRemaining()) {

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.

``` cpp
```cpp
myImage.updatePixels();

// Ensures that the new image data is drawn in the next draw loop
Expand All @@ -252,29 +265,41 @@ The `CaptureRawBytes.ino` Sketch.

```cpp
#include "camera.h"
#include "himax.h"

CameraClass cam;
uint8_t fb[320*240];
HM01B0 himax;
Camera cam(himax);
#define IMAGE_MODE CAMERA_GRAYSCALE
FrameBuffer fb(320,240,2);

void setup() {
Serial.begin(921600);
unsigned long lastUpdate = 0;

// Init the cam QVGA, 30FPS
cam.begin(CAMERA_R320x240, 30);
void setup() {
Serial.begin(921600);
//Init the cam QVGA, 30FPS
cam.begin(CAMERA_R320x240, IMAGE_MODE, 30);
}

void loop() {
// put your main code here, to run repeatedly:
if(!Serial) {
Serial.begin(921600);
while(!Serial);
}

// Time out after 2 seconds and send new data
bool timeoutDetected = millis() - lastUpdate > 2000;

// Wait until the receiver acknowledges
// that they are ready to receive new data
while(Serial.read() != 1){};
if(!timeoutDetected && Serial.read() != 1) return;

lastUpdate = millis();

// Grab frame and write to serial
if (cam.grab(fb) == 0) {
Serial.write(fb, 320*240);
if (cam.grabFrame(fb, 3000) == 0) {
Serial.write(fb.getBuffer(), cam.frameSize());
}

}
```

Expand Down