šŸ“£šŸ“Ŗ šŸšš Adafruit will not be shipping USPS orders Monday October 14, 2019 šŸ—“. Expedited USPS orders placed after 11am ET šŸ•š Friday October 11 will go out Tuesday October 15 šŸ“£šŸ“ŖšŸšš
0

"CMD Timeout" on a TTL Serial JPEG Camera - CommTool
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by adafruit_support_carter on Wed May 22, 2019 10:45 am

Do this import earlier in your program
Code: Select all | TOGGLE FULL SIZE
>>> import adafruit_sdcard


Syntax here is wrong. You've already setup D10 on cs. There's no D10 in the adafruit_sdcard module. Change this to create an SD card object:
Code: Select all | TOGGLE FULL SIZE
>>> sdcard = adafruit_sdcard.D10(spi, cs)

https://github.com/adafruit/Adafruit_Ci ... est.py#L20

adafruit_support_carter
 
Posts: 13163
Joined: Tue Nov 29, 2016 2:45 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Wed May 22, 2019 12:55 pm

Importing the adafruit_sdcard helped. No errors. However...

I'm still getting errors when trying to execute "SD_CS = board.SD_CS"
Code: Select all | TOGGLE FULL SIZE
>>> SD_CS = board.SD_CS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SD_CS'


Video (3 min): https://drive.google.com/file/d/1jB1-YS ... 03h9w/view

Note: My SD Card Breakout Board appears to turn on for 2 seconds and then off after connecting jumper wires to my breadboard. Is this normal?

What am I doing wrong with creating the SD card object? Could I be missing something from my library? See attached screenshot
Attachments
lib.png
lib.png (101.13 KiB) Viewed 209 times

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by adafruit_support_carter on Wed May 22, 2019 1:04 pm

Remember, you're working with a board that does not have a dedicated chip select (CS) pin for the SD card (SD). So there is no board.SD_CS. You need to specify the pin differently:
viewtopic.php?f=25&t=151472#p750312

adafruit_support_carter
 
Posts: 13163
Joined: Tue Nov 29, 2016 2:45 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Wed May 22, 2019 4:39 pm

It appears I'm incorrectly assigining the D10 pin. I receive the message "ValueError: Pin PA18 in use" when I try to assign. I thought I could replace any SDCard reference with "cs" since I already uploaded ">>> cs = digitalio.DigitalInOut(board.D10)". What am I missing still?

I REALLY appreciate you helping me here.

EDIT: I feel like an idiot.... I've been coding to a doc called untitled.py instead of code.py
I'm retrying my recent attempts now... Will post immediately in the event of success

Code: Select all | TOGGLE FULL SIZE

>>> import adafruit_sdcard
>>> import os
>>> import busio
>>> import digitalio
>>> import board
>>> import storage
>>> spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> cs = digitalio.DigitalInOut(board.D10)
>>> vfs = storage.VfsFat(D10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'D10' is not defined
>>> vfs = storage.VfsFat(cs)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'DigitalInOut' object has no attribute 'readblocks'
>>> dir(board)
['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'D0', 'RX', 'D1', 'TX', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13', 'SDA', 'SCL', 'NEOPIXEL', 'SCK', 'MOSI', 'MISO', 'I2C', 'SPI', 'UART']
>>> D10 = digitalio.DigitalInOut(board.D10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Pin PA18 in use
>>>

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by Blueshark on Thu May 23, 2019 2:39 am

@ GoldenDinosaurā€¦ and Admin,

I started following your progress and wondered if my Radio Shack Camera Shield would work on Adafruit VC0706 chip code.

Since there are several cameras in the market with the VC0706 chip on it, it should be universal just that some things may be specific to a board.

I got all the same problems as GoldenDinosaur got with the Commtool, no video same error message, same everything. I pushed forward to the Arduino code but I get the NO Camera error on the Serial Monitor... I think the problem lies on the Adafruit VC0706 Library, something is wrong....

my set up is...
1) Adafruit Metro 328
2) Seeed Studio SD card shield V2 ā€¦ (retired) (Connected by SPI; same pinout as Adafruit SD card breakout board connection) no problems here...
3) Radio Shack VC0706 Breakout Camera (connected by UART)

see pics for set up...
https://drive.google.com/file/d/1UrSbTAlXE0Zh6HSbKuvBVg_8vFL9QZic/view?usp=sharing

https://drive.google.com/file/d/1q4m6dAbLWBIcNOf5CPZ3T1EiW3IMFVjJ/view?usp=sharing

https://drive.google.com/file/d/17J69Av6hYYD6jedpzqRlaQE9VwTCaqJU/view?usp=sharing

After this I tried the code from Seedstudio's camera its shield use's the VC0706 chip plus extra for its shield, I managed to comment out an IF statement to see if it aleast picks up the Radioshack camera and it does with some error since the Radioshack camera is missing a feature the Seedstudio one has.

Seedstudios Camera Shield VC0706 with extras...
https://www.seeedstudio.com/Camera-Shield-p-2106.html


I think there's a problem with Adafruits Library, if my RadioShack VC0706 Camera partially works with Seedstudios code but not at all with Adafruitsā€¦

Hope this info helps

Cheers...

Blueshark
 
Posts: 142
Joined: Thu Dec 21, 2017 7:19 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by Blueshark on Thu May 23, 2019 11:42 am

@ GoldenDinosaurā€¦.

I tried to use the SeedStudio Arduino Library with the Adafruit Snapshot Arduino example by replacing a bit of code but nothing works still get the No Camera detection error see code... No compile errors you can try it yourself if you want.
Code: Select all | TOGGLE FULL SIZE
// This is a basic snapshot sketch using the VC0706 library.
// On start, the Arduino will find the camera and SD card and
// then snap a photo, saving it to the SD card.
// Public domain.

// If using an Arduino Mega (1280, 2560 or ADK) in conjunction
// with an SD card shield designed for conventional Arduinos
// (Uno, etc.), it's necessary to edit the library file:
//   libraries/SD/utility/Sd2Card.h
// Look for this line:
//   #define MEGA_SOFT_SPI 0
// change to:
//   #define MEGA_SOFT_SPI 1
// This is NOT required if using an SD card breakout interfaced
// directly to the SPI bus of the Mega (pins 50-53), or if using
// a non-Mega, Uno-style board.

#include <VC0706_UART.h>
//#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>

// comment out this line if using Arduino V23 or earlier
#include <SoftwareSerial.h>         

// uncomment this line if using Arduino V23 or earlier
// #include <NewSoftSerial.h>       

// SD card chip select line varies among boards/shields:
// Adafruit SD shields and modules: pin 10
// Arduino Ethernet shield: pin 4
// Sparkfun SD shield: pin 8
// Arduino Mega w/hardware SPI: pin 53
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
#define chipSelect 10

// Pins for camera connection are configurable.
// With the Arduino Uno, etc., most pins can be used, except for
// those already in use for the SD card (10 through 13 plus
// chipSelect, if other than pin 10).
// With the Arduino Mega, the choices are a bit more involved:
// 1) You can still use SoftwareSerial and connect the camera to
//    a variety of pins...BUT the selection is limited.  The TX
//    pin from the camera (RX on the Arduino, and the first
//    argument to SoftwareSerial()) MUST be one of: 62, 63, 64,
//    65, 66, 67, 68, or 69.  If MEGA_SOFT_SPI is set (and using
//    a conventional Arduino SD shield), pins 50, 51, 52 and 53
//    are also available.  The RX pin from the camera (TX on
//    Arduino, second argument to SoftwareSerial()) can be any
//    pin, again excepting those used by the SD card.
// 2) You can use any of the additional three hardware UARTs on
//    the Mega board (labeled as RX1/TX1, RX2/TX2, RX3,TX3),
//    but must specifically use the two pins defined by that
//    UART; they are not configurable.  In this case, pass the
//    desired Serial object (rather than a SoftwareSerial
//    object) to the VC0706 constructor.

// Using SoftwareSerial (Arduino 1.0+) or NewSoftSerial (Arduino 0023 & prior):
#if ARDUINO >= 100
// On Uno: camera TX connected to pin 2, camera RX to pin 3:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
// On Mega: camera TX connected to pin 69 (A15), camera RX to pin 3:
//SoftwareSerial cameraconnection = SoftwareSerial(69, 3);
#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif

VC0706 cam = VC0706(&cameraconnection);

// Using hardware serial on Mega: camera TX conn. to RX1,
// camera RX to TX1, no SoftwareSerial object is required:
//Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);

void setup() {

  // When using hardware SPI, the SS pin MUST be set to an
  // output (even if not connected or used).  If left as a
  // floating input w/SPI on, this can cause lockuppage.
#if !defined(SOFTWARE_SPI)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
#else
  if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.
#endif
#endif

  Serial.begin(9600);
  Serial.println("VC0706 Camera snapshot test");
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  } 
 
  // Try to locate the camera
  if (cam.takePicture()) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }
  // Print out the camera version information (optional)
  char *reply = cam.getVersion();
  if (reply == 0) {
    Serial.print("Failed to get version");
  } else {
    Serial.println("-----------------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

  // Set the picture size - you can choose one of 640x480, 320x240 or 160x120
  // Remember that bigger pictures take longer to transmit!
 
  cam.setImageSize(VC0706_640x480);        // biggest
  //cam.setImageSize(VC0706_320x240);        // medium
  //cam.setImageSize(VC0706_160x120);          // small

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  Serial.print("Image size: ");
  if (imgsize == VC0706_640x480) Serial.println("640x480");
  if (imgsize == VC0706_320x240) Serial.println("320x240");
  if (imgsize == VC0706_160x120) Serial.println("160x120");

  Serial.println("Snap in 3 secs...");
  delay(3000);

  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
 
  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
 
  // Open the file for writing
  File imgFile = SD.open(filename, FILE_WRITE);

  // Get the size of the image (frame) taken 
  uint16_t jpglen = cam.getFrameLength();
  Serial.print("Storing ");
  Serial.print(jpglen, DEC);
  Serial.print(" byte image.");

  int32_t time = millis();
  pinMode(8, OUTPUT);
  // Read all the data up to # bytes!
  byte wCount = 0; // For counting # of writes
  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);
    if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
      Serial.print('.');
      wCount = 0;
    }
    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
    jpglen -= bytesToRead;
  }
  imgFile.close();

  time = millis() - time;
  Serial.println("done!");
  Serial.print(time); Serial.println(" ms elapsed");
}

void loop() {
}



But when I try the SeedStudio code it partially works; it detects my camera but it fails to take a picture, it writes a 0kb file on the SD card with its file number. If you wish to try this code you need to install SeedStudio Library from here....
https://github.com/Seeed-Studio/Camera_Shield_VC0706

heres the SeedStudio code... that partially works, remember the SeedStudio Shield also has a Co-Processor the OV7725 chip to help it with the video stuff, I think that's what the problem is...
Code: Select all | TOGGLE FULL SIZE
#include "SoftwareSerial.h"
#include <VC0706_UART.h>
#include <SD.h>
#include <SPI.h>
#define SS_SD  10

//use software serial
SoftwareSerial cameraconnection(2,3);//Rx, Tx
VC0706 cam = VC0706(&cameraconnection);
//use hardware serial
//VC0706 cam = VC0706(&Serial1);

void setup()
{
    Serial.begin(9600);
    Serial.println("VC0706 Camera Snapshot Test ...");
   
    if (!SD.begin(SS_SD)) {
        Serial.println("SD Card init failed...");
        return;
    } 
    if(true == cameraInit()){
        snapShot();
    }else{
        Serial.println("camera init error...");
    }
}

void loop()
{
    //nothing to do
}

bool cameraInit()
{
    cam.begin(BaudRate_19200); //19200
    char *reply = cam.getVersion();
    if (reply == 0) {
        Serial.println("Failed to get version");
        return false;
    } else {
        Serial.println("version:");
        Serial.println("-----------------");
        Serial.println(reply);
        Serial.println("-----------------");
        return true;
    }
}

void snapShot()
{
    Serial.println("Snap in 3 secs...");
    delay(3000);
    if (! cam.takePicture()){
        Serial.println("Failed to snap!");
    }else {
        Serial.println("Picture taken!");
    }
    // Create an image with the name IMAGExx.JPG
    char filename[13];
    strcpy(filename, "IMAGE00.JPG");
    for (int i = 0; i < 100; i++) {
        filename[5] = '0' + i/10;
        filename[6] = '0' + i%10;
        // create if does not exist, do not open existing, write, sync after write
        if (! SD.exists(filename)) {
            break;
        }
    }
    // Open the file for writing
    File imgFile = SD.open(filename, FILE_WRITE);
    Serial.print("create ");
    Serial.println(filename);
    uint16_t jpglen = cam.getFrameLength();
    Serial.print("wait to fetch ");
    Serial.print(jpglen, DEC);
    Serial.println(" byte image ...");
    int32_t time = millis();
    cam.getPicture(jpglen);
    uint8_t *buffer;
    while(jpglen != 0){
         uint8_t bytesToRead = min(32, jpglen);
         buffer = cam.readPicture(bytesToRead);     
         imgFile.write(buffer, bytesToRead);
         //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
         jpglen -= bytesToRead;   
    }
    imgFile.close();
    time = millis() - time;
    Serial.println("Done!");
    Serial.print("Took "); Serial.print(time); Serial.println(" ms");
    cam.resumeVideo();   
}




I'll continue to play with this, but my skills are more in the Hardware than programming...

Hope this helps..

Cheers..

Blueshark
 
Posts: 142
Joined: Thu Dec 21, 2017 7:19 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Thu May 23, 2019 11:43 am

So an interesting development .... I started from scratch and Arduino cannot detect my formatted 64 GB SD card... I get the error message "Installation failed, things to check:
is a card inserted?");
is your wiring correct?");
did you change the chipSelect pin to match your shield or module?"

I'm following this guide: https://learn.adafruit.com/adafruit-mic ... no-library

I changed one line of code for the sketch to read pin 10 instead of pin 4
Code: Select all | TOGGLE FULL SIZE
const int chipSelect = 10;

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Thu May 23, 2019 11:47 am

Blueshark wrote:@ GoldenDinosaurā€¦.
Hope this helps..

Cheers..


I'm just reading this now. It'll take a few mins for me to get through. Are you on the discord channel?

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by adafruit_support_carter on Thu May 23, 2019 11:49 am

Try a smaller card. A card that size may be formatted with a filesystem the Arduino can't read.

adafruit_support_carter
 
Posts: 13163
Joined: Tue Nov 29, 2016 2:45 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Thu May 23, 2019 11:58 am

adafruit_support_carter wrote:Try a smaller card. A card that size may be formatted with a filesystem the Arduino can't read.

OK, I have a 32 GB I will try now and a friend is looking for <4GB cards on his lunch break

EDIT: I got an Arduino UNO board to work ... sorta... see image
Attachments
sd detect.png
sd detect.png (54.37 KiB) Viewed 158 times

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by Blueshark on Thu May 23, 2019 3:05 pm

@ GoldenDinosaurā€¦

Yes I'm on Discord, but I don't think I'll be of much help; This is my hobby, I'm not a pro, but not a beginner at this.

When you find an appropriate SD card, I recommend you test the SeedStudio Library and code, just connect as with the Adafruit tutorial tells you to for the Arduino.

I think I might have an Older model Of the VC0706 chip, I doubt it but that can be a possibility.

If you get the Seedstudio Camera shield, do note that the camera is small and I don't think you'll get a good picture. I got one of these Mini Spy Cam's and their ok, but the bigger lens of the VC0706 board make's it better.

Mini Spy cam...
https://www.adafruit.com/product/3202

Let me know what happens when you try the SeedStudio code/library on your Arduino setup, maybe it will work...


Cheers...

Blueshark
 
Posts: 142
Joined: Thu Dec 21, 2017 7:19 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Thu May 23, 2019 3:30 pm

I'm starting to go nuts. My Arduino UNO can connect with a 2 GB SD Card, but both of my Metro M0 Express Boards cannot connect to const int chipSelect = 10; . I get the same error message as before, while the Arduino UNO can connect on const int chipSelect = 4;

Any workaround or solution? I'm going to keep googling.
Attachments
2 GB SD Card on Arduino UNO.jpg
2 GB SD Card on Arduino UNO.jpg (88.57 KiB) Viewed 133 times

GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by Blueshark on Thu May 23, 2019 4:34 pm

@ GoldenDinosaur

Wing it..... use the Arduino version....
I changed the Seedstudio code touse CS 4 see code....
Code: Select all | TOGGLE FULL SIZE
#include "SoftwareSerial.h"
#include <VC0706_UART.h>
#include <SD.h>
#include <SPI.h>
#define SS_SD  4  //original was 10

//use software serial
SoftwareSerial cameraconnection(2,3);//Rx, Tx
VC0706 cam = VC0706(&cameraconnection);
//use hardware serial
//VC0706 cam = VC0706(&Serial1);

void setup()
{
    Serial.begin(9600);
    Serial.println("VC0706 Camera Snapshot Test ...");
   
    if (!SD.begin(SS_SD)) {
        Serial.println("SD Card init failed...");
        return;
    } 
    if(true == cameraInit()){
        snapShot();
    }else{
        Serial.println("camera init error...");
    }
}

void loop()
{
    //nothing to do
}

bool cameraInit()
{
    cam.begin(BaudRate_19200);
    char *reply = cam.getVersion();
    if (reply == 0) {
        Serial.println("Failed to get version");
        return false;
    } else {
        Serial.println("version:");
        Serial.println("-----------------");
        Serial.println(reply);
        Serial.println("-----------------");
        return true;
    }
}

void snapShot()
{
    Serial.println("Snap in 3 secs...");
    delay(3000);
    if (! cam.takePicture()){
        Serial.println("Failed to snap!");
    }else {
        Serial.println("Picture taken!");
    }
    // Create an image with the name IMAGExx.JPG
    char filename[13];
    strcpy(filename, "IMAGE00.JPG");
    for (int i = 0; i < 100; i++) {
        filename[5] = '0' + i/10;
        filename[6] = '0' + i%10;
        // create if does not exist, do not open existing, write, sync after write
        if (! SD.exists(filename)) {
            break;
        }
    }
    // Open the file for writing
    File imgFile = SD.open(filename, FILE_WRITE);
    Serial.print("create ");
    Serial.println(filename);
    uint16_t jpglen = cam.getFrameLength();
    Serial.print("wait to fetch ");
    Serial.print(jpglen, DEC);
    Serial.println(" byte image ...");
    int32_t time = millis();
    cam.getPicture(jpglen);
    uint8_t *buffer;
    while(jpglen != 0){
         uint8_t bytesToRead = min(32, jpglen);
         buffer = cam.readPicture(bytesToRead);     
         imgFile.write(buffer, bytesToRead);
         //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
         jpglen -= bytesToRead;   
    }
    imgFile.close();
    time = millis() - time;
    Serial.println("Done!");
    Serial.print("Took "); Serial.print(time); Serial.println(" ms");
    cam.resumeVideo();   
}




remember to install the Seedstudio library from the link in the previous post.. before running this code....


Cheers...

Blueshark
 
Posts: 142
Joined: Thu Dec 21, 2017 7:19 pm

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by GoldenDinosaur on Fri May 24, 2019 10:32 am

BIG success. I've got everything working! Needed to update to newest CPython and libraries. Also adjusted my MSO, DI, DO names within the code.

Question.... I want to add a loop so the camera takes a picture every 5 seconds as long as there is space on SD card. What would that code look like in CircuitPython?

Current code:

Code: Select all | TOGGLE FULL SIZE
# VC0706 image capture to SD card demo.
# You must wire up the VC0706 to the board's serial port, and a SD card holder
# to the board's SPI bus.  Use the Feather M0 Adalogger as it includes a SD
# card holder pre-wired to the board--this sketch is setup to use the Adalogger!
# In addition you MUST also install the following dependent SD card library:
#   https://github.com/adafruit/Adafruit_CircuitPython_SD
# See the guide here for more details on using SD cards with CircuitPython:
#   https://learn.adafruit.com/micropython-hardware-sd-cards
import time

import board
import busio
import digitalio
import storage

import adafruit_sdcard
import adafruit_vc0706


# Configuration:
SD_CS_PIN = board.D10  # CS for SD card (SD_CS is for Feather Adalogger)
IMAGE_FILE = '/sd/image.jpg'  # Full path to file name to save captured image.
                              # Will overwrite!

# Setup SPI bus (hardware SPI).
spi = busio.SPI(board.D13, MOSI=board.D11, MISO=board.D12)

# Setup SD card and mount it in the filesystem.
sd_cs = digitalio.DigitalInOut(board.D10)
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')

# Create a serial connection for the VC0706 connection, speed is auto-detected.
uart = busio.UART(board.TX, board.RX, timeout=250)
# Setup VC0706 camera
vc0706 = adafruit_vc0706.VC0706(uart)

# Print the version string from the camera.
print('VC0706 version:')
print(vc0706.version)

# Caution:  This is not advisable per TTL Guide.  Set the baud rate to 115200 for fastest transfer (its the max speed). DEFAULT RATE is 38400
vc0706.baudrate = 38400

# Set the image size.
vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480 # Or set IMAGE_SIZE_320x240 or
                                                       # IMAGE_SIZE_160x120
# Note you can also read the property and compare against those values to
# see the current size:
size = vc0706.image_size
if size == adafruit_vc0706.IMAGE_SIZE_640x480:
    print('Using 640x480 size image.')
elif size == adafruit_vc0706.IMAGE_SIZE_320x240:
    print('Using 320x240 size image.')
elif size == adafruit_vc0706.IMAGE_SIZE_160x120:
    print('Using 160x120 size image.')

# Take a picture.
print('Taking a picture in 3 seconds...')
time.sleep(3)
print('SNAP!')
if not vc0706.take_picture():
    raise RuntimeError('Failed to take picture!')

# Print size of picture in bytes.
frame_length = vc0706.frame_length
print('Picture size (bytes): {}'.format(frame_length))

# Open a file for writing (overwriting it if necessary).
# This will write 50 bytes at a time using a small buffer.
# You MUST keep the buffer size under 100!
print('Writing image: {}'.format(IMAGE_FILE), end='')
with open(IMAGE_FILE, 'wb') as outfile:
    wcount = 0
    while frame_length > 0:
        # Compute how much data is left to read as the lesser of remaining bytes
        # or the copy buffer size (32 bytes at a time).  Buffer size MUST be
        # a multiple of 4 and under 100.  Stick with 32!
        to_read = min(frame_length, 32)
        copy_buffer = bytearray(to_read)
        # Read picture data into the copy buffer.
        if vc0706.read_picture_into(copy_buffer) == 0:
            raise RuntimeError('Failed to read picture frame data!')
        # Write the data to SD card file and decrement remaining bytes.
        outfile.write(copy_buffer)
        frame_length -= 32
        # Print a dot every 2k bytes to show progress.
        wcount += 1
        if wcount >= 64:
            print('.', end='')
            wcount = 0
print()
print('Finished!')



GoldenDinosaur
 
Posts: 16
Joined: Wed May 08, 2019 10:00 am

Re: "CMD Timeout" on a TTL Serial JPEG Camera - CommTool

by adafruit_support_carter on Fri May 24, 2019 11:43 am

Easiest and simplest is just a forever loop at the bottom:
Code: Select all | TOGGLE FULL SIZE
while True:
    take_photo()
    time.sleep(5)

adafruit_support_carter
 
Posts: 13163
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.