From fd4b873edff32b51b830f527080bf0f375928caa Mon Sep 17 00:00:00 2001 From: nznaza Date: Sat, 25 Jun 2016 23:18:34 -0500 Subject: [PATCH 1/3] Added End Of File Detection Added EOF detection, and character print option line --- src/sketch.ino | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sketch.ino b/src/sketch.ino index af52f63..93f6f4f 100644 --- a/src/sketch.ino +++ b/src/sketch.ino @@ -8,9 +8,11 @@ SoftwareSerial camera_serial(2, 3); LSY201 camera; uint8_t buf[32]; +String hexbuf; void setup() { + Serial.begin(115200); camera.setSerial(camera_serial); camera_serial.begin(38400); } @@ -26,11 +28,25 @@ void loop() while (camera.readJpegFileContent(offset, buf, sizeof(buf))) { for (int i = 0; i < sizeof(buf); i ++) - Serial.println(buf[i], HEX); + { + if (buf[i] < 0x10) { + hexbuf = "0" + String(buf[i], HEX); + } + else { + hexbuf = String(buf[i], HEX); + } + //Serial.write(buf[i]); // Uncomment this for write character to Serial + Serial.print(hexbuf); // Uncomment this for print HEX value of character to Serial + if ((buf[i - 1] == 0xFF) && (buf[i] == 0xD9)) + { + break; + } + } offset += sizeof(buf); } + Serial.println(); Serial.println("Done."); camera.stopTakingPictures(); From 8adce52dfc618807280b3a1c467046834298e5d9 Mon Sep 17 00:00:00 2001 From: nznaza Date: Sun, 26 Jun 2016 01:33:18 -0500 Subject: [PATCH 2/3] Example Updated --- .../examples/TakePicture/TakePicture.ino | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/LSY201/examples/TakePicture/TakePicture.ino b/lib/LSY201/examples/TakePicture/TakePicture.ino index c7d0e6b..428d7d4 120000 --- a/lib/LSY201/examples/TakePicture/TakePicture.ino +++ b/lib/LSY201/examples/TakePicture/TakePicture.ino @@ -1 +1,49 @@ -../../../../src/sketch.ino \ No newline at end of file +#include +#include + +/* assuming the TX and RX pins on the camera are attached to pins 2 and 3 of + * the arduino. */ +SoftwareSerial camera_serial(2, 3); +LSY201 camera; +uint8_t buf[32]; +String hexbuf; + +void setup() +{ + Serial.begin(115200); + camera.setSerial(camera_serial); + camera_serial.begin(38400); +} + +void loop() +{ + Serial.println("Taking picture..."); + camera.takePicture(); + Serial.println("Bytes:"); + uint16_t offset = 0; + while (camera.readJpegFileContent(offset, buf, sizeof(buf))) + { + for (int i = 0; i < sizeof(buf); i ++) + { + if (buf[i] < 0x10) + { + hexbuf = "0" + String(buf[i], HEX); + } + else + { + hexbuf = String(buf[i], HEX); + } + //Serial.write(buf[i]); // Uncomment this for write character to Serial + Serial.print(hexbuf); // Uncomment this for print HEX value of character to Serial + if ((buf[i - 1] == 0xFF) && (buf[i] == 0xD9)) + { + break; + } + } + offset += sizeof(buf); + } + Serial.println(); + Serial.println("Done."); + camera.stopTakingPictures(); + delay(10000); +} From ea3028974282db85ebf2e6093d718456ed721b55 Mon Sep 17 00:00:00 2001 From: nznaza Date: Sun, 26 Jun 2016 01:49:45 -0500 Subject: [PATCH 3/3] Update README.md Fixed Typos and Updated Minimal Example to finish serial write in EOF --- README.md | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1bfc000..2687da9 100644 --- a/README.md +++ b/README.md @@ -17,30 +17,44 @@ takes pictures and outputs the raw bytes of the JPEG-encoded images to Serial: #include #include - + SoftwareSerial camera_serial(2, 3); LSY201 camera; uint8_t buf[32]; - + String hexbuf; void setup() { + Serial.begin(115200); camera.setSerial(camera_serial); camera_serial.begin(38400); } - + void loop() { camera.reset(); camera.takePicture(); - uint16_t offset = 0; while (camera.readJpegFileContent(offset, buf, sizeof(buf))) { for (int i = 0; i < sizeof(buf); i ++) - Serial.write(buf[i]); - + { + if (buf[i] < 0x10) + { + hexbuf = "0" + String(buf[i], HEX); + } + else + { + hexbuf = String(buf[i], HEX); + } + Serial.write(buf[1]); + if ((buf[i - 1] == 0xFF) && (buf[i] == 0xD9)) + { + break; + } + } offset += sizeof(buf); } + Serial.println(); } ## Usage @@ -201,13 +215,13 @@ outputting "Init end", so you must reconfigure your serial object accordingly: Call `setImageSize` with one of the following values to change the image size used to encode pictures: -* `LS101::Small` (160x120) -* `LS101::Medium` (320x240) -* `LS101::Large` (640x480) +* `LSY201::Small` (160x120) +* `LSY201::Medium` (320x240) +* `LSY201::Large` (640x480) You must reset the camera for the image size change to take effect: - camera.setImageSize(LS101::Small); + camera.setImageSize(LSY201::Small); camera.reset(); ### Setting the Compression Ratio @@ -219,7 +233,7 @@ Note that resetting the camera returns the compression ratio to its default value, so if you need to change both the image size and compression ratio, you must change the compression ratio after performing the reset: - camera.setImageSize(LS101::Large); + camera.setImageSize(LSY201::Large); camera.reset(); camera.setCompressionRatio(0x20);