Skip to content

Commit dcae285

Browse files
committed
Adding modified OV767X library
1 parent 738a5f5 commit dcae285

File tree

16 files changed

+3683
-9
lines changed

16 files changed

+3683
-9
lines changed

LICENSE.txt

Lines changed: 335 additions & 5 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# arduino-library
1+
# Harvard_TinyMLx Arduino Library
2+
3+
Source code and examples for using and testing your Tiny Machine Learning Kit and Shield.
4+
5+
This library also includes a modified verison of the OV767X Library for Arduino (Copyright (c) 2020 Arduino SA) which is based on https://www.kernel.org[Linux Kernel's] V4L2 driver for OmniVision OV7670 cameras - which was created by Jonathan Corbet.
6+
7+
== License ==
8+
9+
Copyright (c) 2021 TinyMLx. All rights reserved.
10+
11+
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2.
12+
13+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

examples/test_camera/test_camera.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
Harvard University
44
tinyMLx - OV7675 Camera Test
55
6-
Requires the the Arduino_OV767X library
76
*/
87

9-
#include <Arduino_OV767X.h>
108
#include <TinyMLShield.h>
119

1210
bool commandRecv = false; // flag used for indicating receipt of commands from serial port
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
OV767X - Camera Test Pattern
3+
4+
This sketch waits for the letter 'c' on the Serial Monitor,
5+
it then reads a frame from the OmniVision OV7670 camera and
6+
prints the data to the Serial Monitor as a hex string.
7+
8+
The website https://rawpixels.net - can be used the visualize the data:
9+
width: 176
10+
height: 144
11+
RGB565
12+
Little Endian
13+
14+
Circuit:
15+
- Arduino Nano 33 BLE board
16+
- OV7670 camera module:
17+
- 3.3 connected to 3.3
18+
- GND connected GND
19+
- SIOC connected to A5
20+
- SIOD connected to A4
21+
- VSYNC connected to 8
22+
- HREF connected to A1
23+
- PCLK connected to A0
24+
- XCLK connected to 9
25+
- D7 connected to 4
26+
- D6 connected to 6
27+
- D5 connected to 5
28+
- D4 connected to 3
29+
- D3 connected to 2
30+
- D2 connected to 0 / RX
31+
- D1 connected to 1 / TX
32+
- D0 connected to 10
33+
34+
This example code is in the public domain.
35+
*/
36+
37+
#include <Arduino_OV767X.h>
38+
39+
unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565)
40+
41+
void setup() {
42+
Serial.begin(9600);
43+
while (!Serial);
44+
45+
Serial.println("OV767X Camera Capture");
46+
Serial.println();
47+
48+
if (!Camera.begin(QCIF, RGB565, 1)) {
49+
Serial.println("Failed to initialize camera!");
50+
while (1);
51+
}
52+
53+
Serial.println("Camera settings:");
54+
Serial.print("\twidth = ");
55+
Serial.println(Camera.width());
56+
Serial.print("\theight = ");
57+
Serial.println(Camera.height());
58+
Serial.print("\tbits per pixel = ");
59+
Serial.println(Camera.bitsPerPixel());
60+
Serial.println();
61+
62+
Serial.println("Send the 'c' character to read a frame ...");
63+
Serial.println();
64+
}
65+
66+
void loop() {
67+
if (Serial.read() == 'c') {
68+
Serial.println("Reading frame");
69+
Serial.println();
70+
Camera.readFrame(pixels);
71+
72+
int numPixels = Camera.width() * Camera.height();
73+
74+
for (int i = 0; i < numPixels; i++) {
75+
unsigned short p = pixels[i];
76+
77+
if (p < 0x1000) {
78+
Serial.print('0');
79+
}
80+
81+
if (p < 0x0100) {
82+
Serial.print('0');
83+
}
84+
85+
if (p < 0x0010) {
86+
Serial.print('0');
87+
}
88+
89+
Serial.print(p, HEX);
90+
}
91+
}
92+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
OV767X - Camera Capture Raw Bytes
3+
4+
This sketch reads a frame from the OmniVision OV7670 camera
5+
and writes the bytes to the Serial port. Use the Procesing
6+
sketch in the extras folder to visualize the camera output.
7+
8+
Circuit:
9+
- Arduino Nano 33 BLE board
10+
- OV7670 camera module:
11+
- 3.3 connected to 3.3
12+
- GND connected GND
13+
- SIOC connected to A5
14+
- SIOD connected to A4
15+
- VSYNC connected to 8
16+
- HREF connected to A1
17+
- PCLK connected to A0
18+
- XCLK connected to 9
19+
- D7 connected to 4
20+
- D6 connected to 6
21+
- D5 connected to 5
22+
- D4 connected to 3
23+
- D3 connected to 2
24+
- D2 connected to 0 / RX
25+
- D1 connected to 1 / TX
26+
- D0 connected to 10
27+
28+
This example code is in the public domain.
29+
*/
30+
31+
#include <Arduino_OV767X.h>
32+
33+
int bytesPerFrame;
34+
35+
byte data[320 * 240 * 2]; // QVGA: 320x240 X 2 bytes per pixel (RGB565)
36+
37+
void setup() {
38+
Serial.begin(9600);
39+
while (!Serial);
40+
41+
if (!Camera.begin(QVGA, RGB565, 1)) {
42+
Serial.println("Failed to initialize camera!");
43+
while (1);
44+
}
45+
46+
bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel();
47+
48+
// Optionally, enable the test pattern for testing
49+
// Camera.testPattern();
50+
}
51+
52+
void loop() {
53+
Camera.readFrame(data);
54+
55+
Serial.write(data, bytesPerFrame);
56+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
OV767X - Camera Test Pattern
3+
4+
This sketch enables the test pattern mode, then reads a frame from
5+
the OmniVision OV7670 camera and prints the data to the
6+
Serial Monitor as a hex string.
7+
8+
The website https://rawpixels.net - can be used the visualize the data:
9+
width: 176
10+
height: 144
11+
RGB565
12+
Little Endian
13+
14+
Circuit:
15+
- Arduino Nano 33 BLE board
16+
- OV7670 camera module:
17+
- 3.3 connected to 3.3
18+
- GND connected GND
19+
- SIOC connected to A5
20+
- SIOD connected to A4
21+
- VSYNC connected to 8
22+
- HREF connected to A1
23+
- PCLK connected to A0
24+
- XCLK connected to 9
25+
- D7 connected to 4
26+
- D6 connected to 6
27+
- D5 connected to 5
28+
- D4 connected to 3
29+
- D3 connected to 2
30+
- D2 connected to 0 / RX
31+
- D1 connected to 1 / TX
32+
- D0 connected to 10
33+
34+
This example code is in the public domain.
35+
*/
36+
37+
#include <Arduino_OV767X.h>
38+
39+
unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565)
40+
41+
void setup() {
42+
Serial.begin(9600);
43+
while (!Serial);
44+
45+
Serial.println("OV767X Test Pattern");
46+
Serial.println();
47+
48+
if (!Camera.begin(QCIF, RGB565, 1)) {
49+
Serial.println("Failed to initialize camera!");
50+
while (1);
51+
}
52+
53+
Serial.println("Camera settings:");
54+
Serial.print("\twidth = ");
55+
Serial.println(Camera.width());
56+
Serial.print("\theight = ");
57+
Serial.println(Camera.height());
58+
Serial.print("\tbits per pixel = ");
59+
Serial.println(Camera.bitsPerPixel());
60+
Serial.println();
61+
62+
Serial.println("Enabling test pattern mode");
63+
Serial.println();
64+
Camera.testPattern();
65+
66+
Serial.println("Reading frame");
67+
Serial.println();
68+
Camera.readFrame(pixels);
69+
70+
int numPixels = Camera.width() * Camera.height();
71+
72+
for (int i = 0; i < numPixels; i++) {
73+
unsigned short p = pixels[i];
74+
75+
if (p < 0x1000) {
76+
Serial.print('0');
77+
}
78+
79+
if (p < 0x0100) {
80+
Serial.print('0');
81+
}
82+
83+
if (p < 0x0010) {
84+
Serial.print('0');
85+
}
86+
87+
Serial.print(p, HEX);
88+
}
89+
90+
Serial.println();
91+
}
92+
93+
void loop() {
94+
// do nothing
95+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
This sketch reads a raw Stream of RGB565 pixels
3+
from the Serial port and displays the frame on
4+
the window.
5+
6+
Use with the Examples -> CameraCaptureRawBytes Arduino sketch.
7+
8+
This example code is in the public domain.
9+
*/
10+
11+
import processing.serial.*;
12+
import java.nio.ByteBuffer;
13+
import java.nio.ByteOrder;
14+
15+
Serial myPort;
16+
17+
// must match resolution used in the sketch
18+
final int cameraWidth = 176;
19+
final int cameraHeight = 144;
20+
21+
final int cameraBytesPerPixel = 2;
22+
23+
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;
24+
25+
PImage myImage;
26+
27+
void setup()
28+
{
29+
size(176, 144);
30+
31+
// if you have only ONE serial port active
32+
//myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active
33+
34+
// if you know the serial port name
35+
myPort = new Serial(this, "COM3", 9600); // Windows
36+
//myPort = new Serial(this, "/dev/ttyACM0", 9600); // Linux
37+
//myPort = new Serial(this, "/dev/cu.usbmodem14101", 9600); // Mac
38+
39+
// wait for full frame of bytes
40+
myPort.buffer(bytesPerFrame);
41+
42+
myImage = createImage(cameraWidth, cameraHeight, RGB);
43+
}
44+
45+
void draw()
46+
{
47+
image(myImage, 0, 0);
48+
}
49+
50+
void serialEvent(Serial myPort) {
51+
byte[] frameBuffer = new byte[bytesPerFrame];
52+
53+
// read the saw bytes in
54+
myPort.readBytes(frameBuffer);
55+
56+
// create image to set byte values
57+
PImage img = createImage(cameraWidth, cameraHeight, RGB);
58+
59+
// access raw bytes via byte buffer
60+
ByteBuffer bb = ByteBuffer.wrap(frameBuffer);
61+
bb.order(ByteOrder.BIG_ENDIAN);
62+
63+
int i = 0;
64+
65+
img.loadPixels();
66+
while (bb.hasRemaining()) {
67+
// read 16-bit pixel
68+
short p = bb.getShort();
69+
70+
// convert RGB565 to RGB 24-bit
71+
int r = ((p >> 11) & 0x1f) << 3;
72+
int g = ((p >> 5) & 0x3f) << 2;
73+
int b = ((p >> 0) & 0x1f) << 3;
74+
75+
// set pixel color
76+
img.pixels[i++] = color(r, g, b);
77+
}
78+
img.updatePixels();
79+
80+
// assign image for next draw
81+
myImage = img;
82+
}

0 commit comments

Comments
 (0)