TTL Camera and Accelerometer

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

TTL Camera and Accelerometer

Postby dere1 » Wed Apr 25, 2012 11:23 am

Hello,

I am working on a project that will take a picture based on an accelerometer reading. I had all of the pieces working- the camera storing, the accelerometer input conditions etc, but when I put it all together it's a bit unhappy. Basically whenever I tell it to take a picture, everything restarts. I'm posting a slightly shorter version of my code (it's really long), but I think it might abe a hardware problem, do you know if there is a voltage drop when the microSD card is storing a file? I am using a 5Volt Arduino Promini

Thanks!



#include <Adafruit_VC0706.h>
#include <SD.h>
#include <AcceleroMMA7361.h>

AcceleroMMA7361 accelero; //accelerometer
int xval[5];
int yval[5];
int zval[5];
int xacc[5];
int yacc[5];
int zacc[5];
int orient[5];
int orientloop;
int orientave;
int ytot;
int yave;

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


#define chipSelect 10

// 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);
#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

void setup() {
Serial.begin(9600);

#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.println("VC0706 Camera 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.begin()) {
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
//cam.setImageSize(VC0706_640x480); // biggest
// cam.setImageSize(VC0706_320x240); // medium
cam.setImageSize(VC0706_160x120); // small

cam.setMotionDetect(false); // turn it off


//initialize accelero
accelero.begin(5, 8, 7, 6, A4, A5, A2);
accelero.setSensitivity(HIGH); //sets the sensitivity to +/-6G
accelero.calibrate();
}

void loop() {
for (int i= 0; i < 3; i++) //fill array of latest data
{
xval[i] = accelero.getXRaw();
yval[i] = accelero.getYRaw();
zval[i] = accelero.getZRaw();
xacc[i] = accelero.getXAccel();
yacc[i] = accelero.getYAccel();
zacc[i] = accelero.getZAccel();
orient[i] = accelero.getOrientation();

orientloop += orient[i];
ytot +=yacc[i];

}
orientave = orientloop % 3;
yave= ytot % 3;
delay(100);

Serial.print("\noave: ");
Serial.print(orientave);
Serial.print("\tzave: ");
Serial.print(yave);


if(( yave < 0 ) && (orientave > 1 )){ //flick of wrist and upwards motion

cam.takePicture();
Serial.println("Picture taken!");

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;
}
}

File imgFile = SD.open(filename, FILE_WRITE);

uint16_t jpglen = cam.frameLength();
Serial.print(jpglen, DEC);
Serial.println(" byte image");
Serial.print("Writing image to "); Serial.print(filename);

while (jpglen > 0) {
// read 32 bytes at a time;
uint8_t *buffer;
uint8_t bytesToRead = min(64, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
buffer = cam.readPicture(bytesToRead);
imgFile.write(buffer, bytesToRead);

//Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
jpglen -= bytesToRead;
}
imgFile.close();
Serial.println("...Done!");

// cam.resumeVideo();

}
}
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 12:01 am

Re: TTL Camera and Accelerometer

Postby adafruit_support_bill » Wed Apr 25, 2012 11:40 am

Basically whenever I tell it to take a picture, everything restarts. ...
do you know if there is a voltage drop when the microSD card is storing a file?

Sounds like a 'brownout' induced reset. The SD cards do require extra current to write. You may need to find a better power supply.
User avatar
adafruit_support_bill
 
Posts: 15995
Joined: Sat Feb 07, 2009 9:11 am


Return to General Project help

Who is online

Users browsing this forum: No registered users and 9 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]