Team 2

From BenningtonWiki

Jump to: navigation, search

Contents

TEAM 2

Monster:
Team 2 in the field

So, what will we measure?

I was thinking about doing something where we really try to develop something that can get a positive id on an animal shot, and then maybe we rig a camera up for a shot? I think we would want at least a few sensors simultaneously working, and we could make them give us the go ahead to take a picture. Then, we could determine all sorts of sub-routines. If the animal stays in a show for an extended period of time, we could just start snapping away, or should we just wait until a minute passes then click a picture to see what their effect on the area was, or just take another picture? from there on in, could we rely on just a few of the sensors to give us the go ahead to take some more pictures if the animal comes back?

Let's definitely make our final decision and start modding something up by the end of the week.

Devin^^

Im into the idea of using a camera; but I am also thinking of the feasibility of it. Either we would need to hack a cheap camera to trigger it externally or use an expensive camera with a remote shutter port. This would only work in the day too; because we would not have night-vision or infrared optics and a conventional flash would probably scare animals away..

--zack


Godes, a new hope

Stefan setup the beginning of the code tonight, and I finished the old sucker off. I decided to write two versions, well, to clean up one version, to show how much space can be saved if you get rid of all of the cruft. Of course, this can be tightened a lot more, but it still works for the first draft. Since we have yet to go over the real odds and ends, that is, the camera and the sd writing, I have just placed LED on in its place, to represent this action. You may notice a sensors = 3; this is because halfway through, Zack and I realized we were working on a kind of screwy breadboard (we checked all other possibilities extensively), so we just plced that in to show how it will eventually end up working.

COMPRESSED VERSION

<source lang="c"> int time = 0; int pir1 = 03; int pir2 = 12; int pir3 = 11; int tempIn = 0; int camPowerPin = 2; int camShutterPin = 3; int camFlashPin = 4; int lightPin1 = 1; int lightPin2 = 1; int sensors; void setup(){ pinMode(pir1, INPUT); pinMode(pir2, INPUT); pinMode(pir3, INPUT); pinMode(camPowerPin, OUTPUT); pinMode(camShutterPin, OUTPUT); pinMode(camFlashPin, OUTPUT); } void loop(){ int light; bool daylight; readSensors(); sensors = 3; light = (analogRead(lightPin1)+analogRead(lightPin2))/2; if (light > 5){ daylight = true; } else daylight = false; if (sensors >= 1){ camOn(); } if (sensors == 3){ if (daylight == true){ camShutter(); } else{ camFlash(); camShutter(); } sdWrite(time); sdWrite(analogRead(tempIn)); sdWrite(111111); } delay(1000); time++; sensors = 0; } void readSensors(){ int sensor1 = digitalRead(pir1); int sensor2 = digitalRead(pir2); int sensor3 = digitalRead(pir3); int i = (sensor1+sensor2+sensor3); if (i >= 1){ sensors = i; } } void sdWrite(int data){ digitalWrite(6, 1); delay(1000); digitalWrite(6, 0); } void camFlash(){ digitalWrite(camFlashPin, 1); delay(1000); digitalWrite(camFlashPin, 0); } void camShutter(){ digitalWrite(camShutterPin, 1); delay(1000); digitalWrite(camShutterPin, 0); } void camOn(){ digitalWrite(camPowerPin, 1); delay(1000); digitalWrite(camPowerPin, 0); } </source>

UNCOMPRESSED VERSION, with mucho comments and tons of serial prints

<source lang="c"> int time = 0; // Set global timer to zero initially int pir1 = 03; // initialize passive infrared resistor 1 int pir2 = 12; // initialize passive infrared resistor 2 int pir3 = 11; // initialize passive infrared resistor 3 int tempIn = 0; // initialize temp monitor, initially a potentiometer in rough draft of hardware int camPowerPin = 2; // digital port to turn camera on int camShutterPin = 3; // digital port to take a picture int camFlashPin = 4; // digital port to activate flash, if we can int lightPin1 = 1; // photoresistor used to determine if we have daylight int lightPin2 = 1; // x2 so we can average them out, since photoresistors are directional and shoddy int sensors; //initialize the global for the current status of the sensors

void setup(){ pinMode(pir1, INPUT); //Sensor 1 pinMode(pir2, INPUT); //Sensor 2 pinMode(pir3, INPUT); //Sensor 3 pinMode(camPowerPin, OUTPUT); //Camera Power pinMode(camShutterPin, OUTPUT); //Camera Shutter pinMode(camFlashPin, OUTPUT); //Camera Flash Serial.begin(9600); //only to be used for debugging }

void loop(){ int power; // initialize power, should be 1 or 0, but may have to be serial or some other crazy stuff int light; // variable to determine average of photoresistors bool daylight; // boolean for daylight true or false readSensors(); sensors = 3; // power = camStatus(); light = (analogRead(lightPin1)+analogRead(lightPin2))/2; // average out to find if daylight is true Serial.println(light); //display light value, only for debugging if (light > 5){ // if it is day time Serial.println("light is over 5, it's day time."); //debug note daylight = true; // daylight is true } else daylight = false; // else its false Serial.print("Sensors are reporting a read of "); //debug note Serial.println(sensors); //debug note if (sensors >= 1 && power == 0 ){ //if we think we've got something, pre-emptively turn the camera on Serial.println("sensors are reporting over one, turning camera on"); //debug note camOn(); //leads to function for camera turn-on; for now, this is just something as simple as ledOn. } if (sensors == 3){ //if all sensors are reporting steez, if (daylight == true){ // and if daylight is true, Serial.println("Snapping daylight picture"); //debug note camShutter(); //snap it already! } else{ //or else its night! Spooky! Serial.println("Snapping nighttime picture"); //debug note camFlash(); //in that case, we better use flash camShutter(); //take the picture } Serial.println("Writing to sd now..."); //debug note sdWrite(time); //write the time sdWrite(analogRead(tempIn)); //and record the time Serial.println(analogRead(tempIn)); //print for our debugging purposes sdWrite(111111); // and separate it with something to delimit, like 1111 Serial.println("Writing to sd is complete."); //debug note } delay(1000); // delay this for a second time++; // add to the timer sensors = 0; }

void readSensors(){ // function to read PIRs Serial.println("In readSensors()"); //debug note int sensor1 = digitalRead(pir1); //variable for the readout of pir1 Serial.println(sensor1); //debug note int sensor2 = digitalRead(pir2); //variable for the readout of pir2 Serial.println(sensor2); //debug note int sensor3 = digitalRead(pir3); //variable for the readout of pir3 Serial.println(sensor3); //debug note if ((sensor1+sensor2+sensor3) >= 1){ // if the sensor readout is more than one, we're interested Serial.println(sensor1); //debug note Serial.println(sensor2); //debug note Serial.println(sensor3); //debug note sensors = (sensor1+sensor2+sensor3); // set variable to it, if we can't just return it, i don't know much Serial.print((sensor1+sensor2+sensor3)); //print result for sanity check } }

void sdWrite(int data){ //function to write to sd card, will probably have some sub functions Serial.println("In sdWrite()"); //debug note digitalWrite(6, 1); //turn on debug test rough draft led delay(1000); // delay this for a second digitalWrite(6, 0); //turn off debug test rough draft led }

void camFlash(){ //function to turn on flash Serial.println("In camFlash()"); //debug note digitalWrite(camFlashPin, 1); //turn on debug test rough draft led delay(1000); // delay this for a second digitalWrite(camFlashPin, 0); //turn off debug test rough draft led }

void camShutter(){ //function to make camera take picture Serial.println("In camShutter()"); //debug note digitalWrite(camShutterPin, 1); //turn on debug test rough draft led delay(1000); // delay this for a second digitalWrite(camShutterPin, 0); //turn off debug test rough draft led }

void camOn(){ //function to turn camera power on Serial.println("In camOn()"); //debug note digitalWrite(camPowerPin, 1); //turn on debug test rough draft led delay(1000); // delay this for a second digitalWrite(camPowerPin, 0); //turn off debug test rough draft led } </source>

Uncompressed, the size of the file is 3336 bytes; compressed it is 1954 bytes, which is remarkably smaller.

<source lang="c"> void sd_print_log(void) { int i; struct memory mem; sd_raw_read(4, log_count); for (i=0; i < log_count; ++i) { sd_raw_read(i*sizeof(mem)+8, bizz &mem, sizeof(mem)); rsprintf("%d, %d, %d\n", mem.temperature, mem.timestamp, mem.light); }

}

</source>

SD is here, and only a little queer

I updated the code so that the SD writes should work, as best as I can tell from the test program. Our program includes no possibility of getting the data OUT, but it would be trivial to either write a separate program, or have a "barf pin" that upchucks the data to the serial when it reads high.

<source lang="c">

  1. include <sd_raw_config.h>
  2. undef SD_RAW_WRITE_BUFFERING
  3. define SD_RAW_WRITE_BUFFERING 0
  4. include <sd_raw.h>
  5. include <string.h>
  6. include <stdio.h>
  7. include <stdarg.h>

int time = 0; int pir1 = 03; int pir2 = 12; int pir3 = 11; int tempIn = 0; int camPowerPin = 2; int camShutterPin = 3; int camFlashPin = 4; int lightPin1 = 1; int lightPin2 = 1; int sensors;

void setup(){

 sd_raw_init();

pinMode(pir1, INPUT); pinMode(pir2, INPUT); pinMode(pir3, INPUT); pinMode(camPowerPin, OUTPUT); pinMode(camShutterPin, OUTPUT); pinMode(camFlashPin, OUTPUT); }

void loop(){ int light; bool daylight; readSensors(); sensors = 3; light = (analogRead(lightPin1)+analogRead(lightPin2))/2; if (light > 5){ daylight = true; } else daylight = false; if (sensors >= 1){ camOn(); } if (sensors == 3){ if (daylight == true){ camShutter(); } else{ camFlash(); camShutter(); } sdWrite(time); sdWrite(analogRead(tempIn)); sdWrite(111111); } delay(1000); time++; sensors = 0; }

void readSensors(){ int sensor1 = digitalRead(pir1); int sensor2 = digitalRead(pir2); int sensor3 = digitalRead(pir3); int i = (sensor1+sensor2+sensor3); if (i >= 1){ sensors = i; } }

void sdWrite(int data){ digitalWrite(6, 1);

 sd_raw_write(0, (uint8_t *) &data, sizeof(data));

delay(1000); digitalWrite(6, 0); }

void camFlash(){ digitalWrite(camFlashPin, 1); delay(1000); digitalWrite(camFlashPin, 0); }

void camShutter(){ digitalWrite(camShutterPin, 1); delay(1000); digitalWrite(camShutterPin, 0); }

void camOn(){ digitalWrite(camPowerPin, 1); delay(1000); digitalWrite(camPowerPin, 0); } </source>


EVERYTHING ABOVE THIS IS OLD NEWS.

Latest code for the duino is as follows:

<source lang="C">

  1. include <sd_raw_config.h>
  2. undef SD_RAW_WRITE_BUFFERING
  3. define SD_RAW_WRITE_BUFFERING 0
  4. include <sd_raw.h>
  5. include <string.h>
  6. include <stdio.h>
  7. include <stdarg.h>

int timeStamp = 0; int camPowerPin = 2; int camShutterPin = 3; int camFlashPin = 4; int lightPin1 = 4; int lightPin2 = 5; int pir1 = 6; int pir2 = 7; int pir3 = 8; int tempIn = 0; int power = 0; int sensors, hello, light, log_count;

void rsprintf(const char *format, ...);

void setup(){

 sd_check_format(); 	

pinMode(pir1, INPUT); pinMode(pir2, INPUT); pinMode(pir3, INPUT); pinMode(camPowerPin, OUTPUT); pinMode(camShutterPin, OUTPUT); pinMode(camFlashPin, OUTPUT);

}

void loop(){ readSensors(); light = (analogRead(lightPin1)+analogRead(lightPin2))/2; rsprintf("%d\n", light); rsprintf("Sensors are reporting a read of "); rsprintf("%d\n", sensors); if (sensors >= 2){ sd_log(analogRead(tempIn), timeStamp, light); } delay(1000); timeStamp++; sd_print_log(); } void readSensors(){ rsprintf("In readSensors()\n"); int sensor1 = digitalRead(pir1); rsprintf("%d\n", sensor1); int sensor2 = digitalRead(pir2); rsprintf("%d\n", sensor2); int sensor3 = digitalRead(pir3); rsprintf("%d\n", sensor3); if ((sensor1+sensor2+sensor3) >= 1){ rsprintf("%d\n", sensor1); rsprintf("%d\n", sensor2); rsprintf("%d\n", sensor3); sensors = (sensor1+sensor2+sensor3); rsprintf("%d\n", sensors); } }

struct memory{ int temperature, lightLevel, timestamp; };

void sd_format(){

 hello = 0x68656C6F; 
 sd_raw_write(0, (uint8_t *) &hello, sizeof(hello)); 
 log_count = 0; 
 sd_raw_write(4, (uint8_t *) &log_count, sizeof(log_count)); 

}

void sd_check_format(){

 int id; 
 sd_raw_read(0, (uint8_t *) &id, sizeof(id)); 
 if (id != hello){ 
   sd_format();
 }
 sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count)); 

}

void sd_log(int temp, int time, int light){

 struct memory mem; 
 mem.temperature = temp;
 mem.timestamp = time;
 mem.lightLevel = light;
 sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count));
 sd_raw_write(((log_count * sizeof(mem)) + 8 ), (uint8_t *) &mem, sizeof(mem));
 ++log_count;
 sd_raw_write(4, (uint8_t *) &log_count, sizeof(log_count));

}

void rsprintf(const char *format, ...) {

   static unsigned char inited = 0;
   char msg[100];
   va_list ap;
   if (!inited) {
       Serial.begin(9600);
       inited = 1;
   }
   va_start(ap, format);
   vsnprintf(msg, sizeof(msg)-1, format, ap);
   Serial.print(msg);
   va_end(ap);

}

void sd_print_log() { struct memory mem; sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count)); for (int i=0; i < log_count; ++i) { sd_raw_read(i*sizeof(mem)+8, (uint8_t *) &mem, sizeof(mem)); rsprintf("%d, %d, %d\n", mem.temperature, mem.timestamp, mem.lightLevel); } } </source>

Its pretty dopesick dipset dipset. I took the loop to task, made it stupid but functional, and am hoping we can do that more often, as its going to get really gross. no camera implementation yet; we are going to the max's in class i assume, and I'm waiting on the hardware peeps to get that together.

Personal tools