Team 0

From BenningtonWiki

Jump to: navigation, search

[edit] Info

Team Members: Ian, Glen, Hannah, Kasia
Deploy Location: Mile Around(?) Woods, North Bennington
Deploy Date: March 27, 2009
Data to be Gathered: Light, Movement, Photos
Data Written to SD Card: Time since Arduino power-up, Light sensor value, 3 Motion sensor values (motion 1, or no motion 0), Number of motion sensors that detect motion
SD Write Routine: Sensors are read once about every second. Data is written to the SD when at least one motion sensor is tripped.
Take Photo Routine: A photo is taken each time all three sensors are tripped simultaneously.
Hardware:

  • 1 Arduino with SD card reader
  • 1 Disney digital camera
  • 2 SD cards
  • 1 6v battery
  • 1 MAX395 chip
  • 1 analog photo sensor
  • 3 digital IR motion sensors
  • 1 Tupperware container

stop animation of images collected

Pre-Deployment Notes/Revisions: I noticed a minor mistake in the wake-up routine. I fixed it, but maybe we should update the Arduino with this edit. Also, does it make sense that we are recording time in milliseconds? I realize we probably have the space, but is it necessary to know the time down to the millisecond, especially when it's not even that accurate? Maybe we should divide by 1000 for a count by second. -Ian

[edit] Code

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

//max stuff

  1. define NUM_MAX395_CHIPS 1 // number of max395s daisy-chained and being controlled
  2. define NUM_MAX395_SWITCHES (NUM_MAX395_CHIPS*8) // total number of switches being controlled

void max395Setup(void); void max395Write(int sw, int value);


//pins int motionSensor1Pin = 2; int motionSensor2Pin = 3; int motionSensor3Pin = 4; int lightSensorPin = 0; int reformatSDPin = 5;

//SD STUFF: //Pins 10, 11, 12, 13 used for SD card reading

  1. define CARD_ID 0x68656c6f

int log_count; void rsprintf(const char *format, ...); void sd_format(void); void sd_check_format(void); void sd_log(int temp, int timeStamp, int light); void sd_print_log(void);


int untilNextWakeUp = 0; int wakeUpInterval = 30;

//Pins 7, 8, 9 for MAX //MAX code on svn


struct memory { unsigned long timeStamp; int light; int sensor1; int sensor2; int sensor3; int sensorSum; };

struct memory mem;


void setup(void) {

max395Setup();

//pin setups pinMode(motionSensor1Pin, INPUT); pinMode(motionSensor2Pin, INPUT); pinMode(motionSensor3Pin, INPUT); Serial.begin(9600);

mem.timeStamp = 0; mem.light = 0; mem.sensor1 = 0; mem.sensor2 = 0; mem.sensor3 = 0; mem.sensorSum = 0;

//SD Stuff: struct sd_raw_info info;

   unsigned long write_test_value, read_test_value;
   sd_raw_init();
   sd_raw_get_info(&info);
   // rsprintf("manufacturer: %d\n", info.manufacturer);
   // rsprintf("serial number: %ld\n", info.serial);
   // rsprintf("capacity: %ld\n", info.capacity);
   // rsprintf("date of manufacture: %02d/%02d\n", info.manufacturing_month, info.manufacturing_year);
   sd_check_format();

//If pin 5 is on, force reformat if (analogRead(reformatSDPin) == 1023) { sd_format(); }

}

void loop(void) {

// Read sensors: mem.timeStamp = millis(); mem.light = analogRead(lightSensorPin); mem.sensor1 = digitalRead(motionSensor1Pin); mem.sensor2 = digitalRead(motionSensor2Pin); mem.sensor3 = digitalRead(motionSensor3Pin); // Calculate sensorSum: mem.sensorSum = mem.sensor1 + mem.sensor2 + mem.sensor3;

// Print readings: // Serial.print(mem.sensor1); // Serial.print(" "); // Serial.print(mem.sensor2); // Serial.print(" "); // Serial.print(mem.sensor3); // Serial.print(" : "); // Serial.println(mem.light);

// Wake up if wakeUpInterval has passed, set untilNextWakeUp to wakeUpInterval: if (untilNextWakeUp <= 0) { max395Write(1, 1); delay(100); max395Write(1, 0); untilNextWakeUp = wakeUpInterval; }

if (mem.sensorSum == 3) { max395Write(0, 1); delay(100); max395Write(0, 0); sd_log(mem.timeStamp, mem.light, mem.sensor1, mem.sensor2, mem.sensor3, mem.sensorSum); untilNextWakeUp = wakeUpInterval; } else if ((mem.sensorSum == 2) || (mem.sensorSum == 1)) { sd_log(mem.timeStamp, mem.light, mem.sensor1, mem.sensor2, mem.sensor3, mem.sensorSum); }

delay(1000); --untilNextWakeUp;

// Serial.print(untilNextWakeUp); // Serial.println(" seconds until next wake up"); // // Serial.println("SD CARD:\n"); // sd_print_log(); // Serial.println("\n"); }

void sd_format(void) { long id = CARD_ID; sd_raw_write(0, (uint8_t *) &id, sizeof(id)); log_count = 0; sd_raw_write(4, (uint8_t *) &log_count, sizeof(log_count)); }

void sd_check_format(void) { long id; sd_raw_read(0, (uint8_t *) &id, sizeof(id)); if (id != CARD_ID) sd_format(); sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count)); }

void sd_log (unsigned long timeStamp, int light, int sensor1, int sensor2, int sensor3, int sensorSum) { struct memory mem; mem.timeStamp = timeStamp; mem.light = light; mem.sensor1 = sensor1; mem.sensor2 = sensor2; mem.sensor3 = sensor3; mem.sensorSum = sensorSum;

sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count)); sd_raw_write(log_count * sizeof(struct memory) + 8, (uint8_t *) &mem, sizeof(mem)); ++log_count; sd_raw_write(4, (uint8_t *) &log_count, sizeof(log_count)); }

void sd_print_log(void) { int i; struct memory mem;

sd_raw_read(4, (uint8_t *) &log_count, sizeof(log_count)); for (i = 0; i < log_count; ++i) { sd_raw_read(i * sizeof(mem) + 8, (uint8_t *) &mem, sizeof(mem)); //rsprintf("%u, %d, %d, %d, %d, %d \n", mem.timeStamp, mem.light, mem.sensor1, mem.sensor2, mem.sensor3, mem.sensorSum); Serial.print(mem.timeStamp); Serial.print(" "); Serial.print(mem.light); Serial.print(" "); Serial.print(mem.sensor1); Serial.print(" "); Serial.print(mem.sensor2); Serial.print(" "); Serial.print(mem.sensor3); Serial.print(" "); Serial.print(mem.sensorSum); Serial.print("\n"); } }

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

}


//max stuff

  1. define SCLK_PIN 7 // max395 control line: synchronous clock. goes to max395 pin 1.
  2. define DIN_PIN 8 // max395 control line: data in. goes to max395 pin 3.
  3. define CS_PIN 9 // max395 control line: chip select. goes to max395 pin 24.

// For power connect pins 2 and 23 to V+, pins 4 and 21 to GND.

static unsigned char max395_switches[NUM_MAX395_CHIPS];

void output_max395_switches(void);

// sets all of the max395_switches to off // sets the arduino's pins to the necessary output mode // clears the max395 chip select void max395Setup(void) {

   int i;
   for (i = 0; i < NUM_MAX395_CHIPS; ++i)
       max395_switches[i] = 0;
   pinMode(SCLK_PIN, OUTPUT);
   pinMode(DIN_PIN, OUTPUT);
   pinMode(CS_PIN, OUTPUT);
   digitalWrite(CS_PIN, HIGH);
   digitalWrite(SCLK_PIN, LOW);
   digitalWrite(DIN_PIN, LOW);
   output_max395_switches();

}


// for value: 1 means on, 0 means off, -1 means opposite void max395Write(int sw, int value) {

   int m, s, b, v;
   if (sw < 0 || sw >= NUM_MAX395_SWITCHES)
       return;
   m = sw / 8;
   s = sw % 8;
   b = 1 << s;
   v = max395_switches[m];
   if (value >= 1)
       v |= b;
   else if (value == 0)
       v &= (b ^ 0xFF);
   else if (value <= -1)
       v ^= b;
   max395_switches[m] = v;
   output_max395_switches();

}


  1. if 0

// for value: 1 means on, 0 means off int get_max395_switch(int sw) {

   int m, s, b, v;
   if (sw < 0 || sw >= NUM_MAX395_SWITCHES)
       return 0;
   m = sw / 8;
   s = sw % 8;
   b = 1 << s;
   v = max395_switches[m];
   return (v & b) != 0;

}

  1. endif

// call this whenever you want the max395 switches to change // outputs the contents of the max395_switches array to the max395s void output_max395_switches(void) {

   int i, j;
   digitalWrite(SCLK_PIN, LOW);
   digitalWrite(CS_PIN, LOW);
   for (i = NUM_MAX395_CHIPS - 1; i >= 0; --i) {
       int val = max395_switches[i];
       int mask = 0x80;
       for (j = 7; j >= 0; --j) {
           digitalWrite(DIN_PIN, (val & mask) != 0);
           digitalWrite(SCLK_PIN, HIGH);
           digitalWrite(SCLK_PIN, LOW);
           mask >>= 1;
       }
   }
   digitalWrite(CS_PIN, HIGH);

}

</source>

[edit] Research/Notes

Camera Stuff:

I read up on the CMOS cameras ([1]) and how people have used them with arduinos. Basically the arduinos as they are are not fit to take images. The images taken will be at least 100k of data. I think the data from the camera to the arduino can be sent rather quickly, but I read that it takes some time (maybe a few minutes even) to send the data from the arduino to an SD card. The main problem is that the arduino only has 1k of RAM so it cannot store a still image and then send it to the SD card. There are some other problems too, but bottom line is that the arduino as-is is not powerful enough for image capturing. Since we would basically have to build a digital camera to do this, it sounds like we would be better off just using an existing digital camera, and just have the arduino control the "take photo" button. I think this is what the people did in that HALO project. The problem then would be finding a junk digital camera.

I checked the Video Cage for those spy cameras, which are actually checked out until Wednesday. I wasn't able to find out what make/model they are. But I do know they are wireless and I'm pretty sure they come with a separate module that they send the video data to. It's hard to say right now if they could be useful or not without possibly damaging them, or if they even take photos.

- Ian Pearce

Inclosure stuff:

Check this out: http://www.rcboataholic.com/building/conformal.htm http://www.psfk.com/2008/07/longtime-electronics-foe-eliminated.html

Looks like we can use Epoxy or this other coating to waterproof the circuts. I was also thinking about a ziploc bag and some seran wrap, but this sounds better.

Glen

Personal tools