admin管理员组

文章数量:1405170

Below is the code, but in the serial monitor I'm getting the outputs camera is initialized, waiting, error. The code in if loop Serial.read() == 'c' is not getting executed. If anyone knows how to solve this and resolve the problem, I'm using an Arduino nano 33 BLE sense microcontroller.

code:-

#include <Arduino_OV767X.h>

long bytesPerFrame; // variable to hold total number of bytes in image
long numPixels;

// Declare a byte array to hold the raw pixels recieved from the OV7670
// Array size is set for QCIF; if other format requied, change size
// QCIF: 176x144 X 2 bytes per pixel (RGB565)
byte data[176 * 144 * 2]; 

void setup() {
  Serial.begin(115200);
  while (!Serial);

  // Begin the OV7670 specifing resoultion (QCIF, Pixel format RGB565 and frames per second)
  if (!Camera.begin(QCIF, RGB565, 1)) {
    Serial.println("Failed to initialize camera!");
    while (1);
  }
  
  bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel();
  numPixels = Camera.width() * Camera.height();
  Serial.println("initailesed camera");
  // Optionally, enable the test pattern for testing
  // If the next line is uncommented, the OV7670 will output a test pattern
  //Camera.testPattern();
}

void loop() {
  // Wait for a 'c' from Serial port before taking frame
  Serial.println("waititng");
  while (!Serial.available()) {
    delay(10);
  }
  Serial.println("take wait");
  if (Serial.read() == 'c') {
    
    // Read frame from OV7670 into byte array
    Camera.readFrame(data);
    Serial.println("reading");
    // Write out each byte of the array to the serial port
    // Probaly a quicker way to do this
    for (int i = 0; i < bytesPerFrame; i++){
      Serial.write(data[i]);
    }
    Serial.println("completed");
    // Write out a FF byte to tell receiving program that data is finished
    // Somewhat dangerous - but has worked so far
    delay(100);
    Serial.write(0xFF);
  }
  Serial.print("error");
}

本文标签: