Team 3

From BenningtonWiki

Jump to: navigation, search
Team 3 in the field

Sketch of final product:

Woohoo!

<source> THIS IS SAMPLE DATA TAKEN IN DICKINSON 238 AT 4:16 on the 4th.

id 00009876 Hello 00009876 HELO 202 Logs are on the card 0: 44,50,4?id 00009876 Hello 00009876 HELO 202 Logs are on the card 0: 45,47,49,35,55,32,0 1: 45,50,49,35,43,30,0 2: 44,48,49,34,54,30,1 3: 44,47,49,34,49,30,2 4: 44,48,49,35,53,31,3 5: 44,52,49,35,50,31,4 6: 44,50,49,35,53,31,6 7: 45,48,49,35,56,31,7 8: 44,48,49,35,56,31,8 9: 44,51,49,35,52,32,9 10: 44,49,49,35,53,31,10 11: 45,48,49,35,54,32,11 12: 45,48,49,35,54,31,12 13: 45,48,49,35,56,31,13 14: 44,50,49,36,47,31,14 15: 44,52,49,35,47,31,15 16: 44,50,49,36,47,30,17 17: 44,48,49,35,56,32,18 18: 44,52,49,35,44,30,19 19: 44,52,49,36,45,31,20 20: 44,50,49,36,45,30,21 21: 45,48,49,36,49,31,22 22: 44,51,49,35,44,31,23 23: 44,48,49,35,55,31,24 24: 45,48,49,35,54,31,25 25: 44,52,49,35,46,30,26 26: 44,50,49,36,44,30,28 27: 45,52,49,36,50,32,29 28: 44,49,48,35,57,31,30 29: 45,49,49,35,55,31,31 30: 44,52,49,35,44,31,32 31: 45,48,49,34,50,30,33 32: 44,49,49,36,46,30,34 33: 45,52,49,35,46,31,35 34: 44,52,49,35,46,31,36 35: 45,48,49,35,55,31,37 36: 44,50,49,35,48,31,39 37: 45,52,49,36,47,31,40 38: 44,48,49,35,53,31,41 39: 44,51,49,36,53,32,42 40: 44,49,49,36,53,32,43 41: 45,50,49,35,56,31,44 42: 44,52,49,35,43,31,45 43: 44,50,49,35,55,31,46 44: 44,48,49,35,47,31,47 45: 45,48,49,35,54,31,48 46: 45,51,49,34,52,31,50 47: 44,50,50,36,44,31,51 48: 44,52,49,35,49,31,52 49: 44,48,49,35,52,30,53 50: 44,50,49,35,46,31,54 51: 44,50,49,35,43,31,55 52: 44,52,49,35,48,31,56 53: 44,52,49,35,56,31,57 54: 44,48,49,35,55,30,58 55: 45,52,49,35,53,32,59 56: 44,52,49,35,45,32,61 57: 45,48,49,35,51,31,62 58: 44,52,49,35,46,31,63 59: 45,51,50,35,45,31,64 60: 44,51,49,35,45,30,65 61: 45,52,49,35,45,31,66 62: 45,48,49,36,57,31,67 63: 44,52,49,35,45,31,68 64: 45,48,49,35,56,31,70 65: 45,48,49,35,54,32,71 66: 44,51,50,36,43,30,72 67: 44,52,49,35,56,32,73 68: 44,51,49,35,44,31,74 69: 44,52,50,36,46,31,75 70: 44,49,49,35,49,31,76 71: 44,51,49,36,45,31,77 72: 44,49,49,35,55,32,78 73: 44,49,49,35,56,31,79 74: 44,50,49,36,48,31,81 75: 44,48,49,35,49,31,82 76: 44,48,49,36,47,31,83 77: 45,49,49,35,44,31,84 78: 44,50,49,35,46,30,85 79: 44,52,49,36,51,31,86 80: 44,50,49,35,51,32,87 81: 44,48,49,35,53,31,88 82: 44,48,49,35,56,31,89 83: 44,53,49,35,51,31,90 84: 44,49,49,35,44,31,92 85: 45,48,50,35,50,31,93 86: 44,51,49,35,44,30,94 87: 45,52,50,35,43,31,95 88: 44,52,50,36,48,32,96 89: 45,48,50,35,48,31,97 90: 44,50,49,36,52,31,98 91: 45,48,50,36,43,31,99 92: 44,51,50,35,43,31,100 93: 44,48,50,36,48,31,101 94: 44,52,49,35,47,31,103 95: 45,48,50,35,49,31,104 96: 44,51,49,36,44,31,105 97: 44,49,50,35,44,31,106 98: 44,52,49,36,43,31,107 99: 44,52,50,35,45,31,108 100: 44,51,49,35,44,31,109 101: 44,53,50,35,51,31,110 102: 44,52,50,36,43,31,111 103: 44,52,50,35,46,31,113 104: 44,52,50,35,44,31,114 105: 44,52,49,34,55,31,115 106: 44,51,49,35,48,31,116 107: 44,49,49,36,53,31,117 108: 44,48,50,35,56,32,118 109: 45,49,50,35,48,30,119 110: 44,52,50,35,45,32,120 111: 44,49,49,36,52,31,121 112: 44,49,49,35,45,31,122 113: 44,52,50,36,49,31,124 114: 44,48,50,36,52,31,125 115: 44,51,50,35,47,32,126 116: 44,51,49,35,51,32,127 117: 45,51,49,35,56,31,128 118: 45,52,50,35,46,31,129 119: 44,48,50,35,49,30,130 120: 44,47,49,34,55,31,131 121: 44,49,50,36,44,31,132 122: 44,52,50,36,43,31,133 123: 44,48,50,35,47,31,135 124: 44,48,49,35,48,30,136 125: 44,52,49,35,57,32,137 126: 44,48,49,35,51,31,138 127: 45,48,49,36,52,31,139 128: 44,52,50,35,49,32,140 129: 44,52,50,36,49,32,141 130: 44,52,50,35,49,31,142 131: 44,52,50,36,53,31,144 132: 44,52,49,35,53,31,145 133: 44,52,50,35,45,31,146 134: 44,48,49,36,54,31,147 135: 45,52,50,35,53,31,148 136: 44,51,50,36,43,30,149 137: 45,48,50,35,52,31,150 138: 44,52,49,36,53,31,151 139: 45,48,49,36,50,31,152 140: 44,52,50,35,44,31,154 141: 45,50,50,35,54,31,155 142: 44,51,50,35,44,31,156 143: 44,53,50,35,54,32,157 144: 44,48,49,36,56,31,158 145: 44,52,50,35,53,31,159 146: 44,49,49,35,57,32,160 147: 44,52,50,35,48,31,161 148: 44,48,49,35,49,31,162 149: 44,50,50,36,43,31,163 150: 44,51,49,35,55,31,165 151: 44,49,50,36,44,30,166 152: 44,52,50,35,44,31,167 153: 44,48,50,35,50,30,168 154: 44,50,50,36,44,31,169 155: 44,52,49,35,56,31,170 156: 44,52,50,35,48,31,171 157: 44,51,50,35,47,32,172 158: 44,48,50,36,48,31,173 159: 44,49,50,35,53,31,174 160: 45,49,50,36,46,31,176 161: 44,49,50,35,51,30,177 162: 44,50,50,36,43,31,178 163: 45,48,50,36,51,32,179 164: 44,48,50,35,48,31,180 165: 44,52,50,35,56,31,181 166: 44,52,50,35,49,31,182 167: 44,48,50,36,49,31,183 168: 44,50,50,36,43,30,184 169: 44,51,50,35,57,31,185 170: 44,52,49,36,48,32,187 171: 45,49,50,35,45,31,188 172: 44,53,50,35,49,31,189 173: 44,49,50,36,43,31,190 174: 44,49,50,35,47,31,191 175: 45,52,50,35,53,32,0 176: 44,52,50,36,45,31,1 177: 44,52,50,35,49,32,2 178: 44,52,50,36,46,31,3 179: 44,50,50,35,53,31,4 180: 44,51,50,36,44,31,6 181: 44,50,50,35,55,30,7 182: 44,51,50,35,44,30,8 183: 44,52,50,34,54,31,9 184: 44,48,49,35,57,31,10 185: 45,48,50,36,46,30,11 186: 44,50,50,36,43,31,12 187: 45,48,50,35,47,31,13 188: 44,51,50,36,44,31,14 189: 44,52,50,35,56,31,15 190: 44,49,50,35,56,31,17 191: 45,52,50,36,51,31,18 192: 44,51,50,36,43,31,19 193: 44,52,50,36,52,31,20 194: 44,48,50,37,49,31,21 195: 44,52,50,36,47,31,22 196: 44,48,49,35,52,31,23 197: 44,49,50,35,49,30,24 198: 44,48,50,34,54,31,25 199: 44,51,50,35,53,30,26 200: 44,48,50,35,50,30,28 201: 44,50,50,35,44,31,29

</source> <source lang="c">

  1. include <sd_raw_config.h>
  2. include <sd_raw.h>
  3. include <string.h>
  4. include <stdio.h>
  5. include <stdarg.h>
  1. define PRESSURE_1 0
  2. define PRESSURE_2 1
  3. define PRESSURE_3 2
  4. define TEMPERATURE_1 3
  5. define TEMPERATURE_2 4
  6. define TEMPERATURE_3 5
  7. define LIGHT_PIN 2

void rsprintf(const char *format, ...); void sd_write(uint32_t offset, void *buffer, uint16_t length); void sd_read(uint32_t offset, void *buffer, uint16_t length);

int hello = 0x9876; int log_count; int joe = 0; void setup(){ sd_raw_init(); sd_check_format(); rsprintf("HELO\n"); rsprintf("%d Logs are on the card\n", log_count); pinMode(LIGHT_PIN, OUTPUT); sd_print_log();

   while(1) ;

} void loop(){

 rsprintf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");

digitalWrite(LIGHT_PIN, joe);

       rsprintf("The light is %d\n", joe);

int read1 = analogRead(PRESSURE_1); int read2 = analogRead(PRESSURE_2); int read3 = analogRead(PRESSURE_3); int tempc1 = analogRead(TEMPERATURE_1); int tempc2 = analogRead(TEMPERATURE_2); int tempc3 = analogRead(TEMPERATURE_3); rsprintf("%d,%d,%d,%d,%d,%d,%ld\n", read1, read2, read3, tempc1, tempc2, tempc3, millis()/1000); sd_log(read1, read2, read3, tempc1, tempc2, tempc3, millis()/1000); delay(1000); joe = !joe; }

struct memory{ int pressureRead1; int pressureRead2; int pressureRead3; int tempRead1; int tempRead2; int tempRead3; long log_count; };

void sd_format(){

 int id;
 rsprintf("in sd_format\n");
 sd_write(0, &hello, sizeof(hello)); 
 sd_read(0, &id, sizeof(id)); 
 rsprintf("id    %08x\n", id);
 log_count = 0;
 sd_write(4, &log_count, sizeof(log_count)); 

}

void sd_check_format(){

 int id;
 sd_read(0, &id, sizeof(id)); 
 rsprintf("id    %08x\n", id);
 rsprintf("Hello %08x\n", hello);
 if (id != hello){ 
   sd_format();
 }
 sd_read(4, &log_count, sizeof(log_count)); 

}

void sd_log(int pinRead1, int pinRead2, int pinRead3, int tempRead1, int tempRead2, int tempRead3, long timeStamp){

 struct memory mem; 
 mem.pressureRead1 = pinRead1;
 mem.pressureRead2 = pinRead2;
 mem.pressureRead3 = pinRead3;
 mem.tempRead1 = tempRead1;
 mem.tempRead2 = tempRead2;
 mem.tempRead3 = tempRead3;
 mem.log_count = timeStamp;
 sd_read(4, &log_count, sizeof(log_count));
 sd_write(((log_count * sizeof(mem)) + 8 ), &mem, sizeof(mem));
 ++log_count;
 sd_write(4, &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_read(4, &log_count, sizeof(log_count)); for (long i=0; i < log_count; ++i) { sd_read(i*sizeof(mem)+8, &mem, sizeof(mem)); rsprintf("%ld: %d,%d,%d,%d,%d,%d,%ld\n", i, mem.pressureRead1, mem.pressureRead2, mem.pressureRead3, mem.tempRead1, mem.tempRead2, mem.tempRead3, mem.log_count); } }


void sd_write(uint32_t offset, void *buffer, uint16_t length) {

 sd_raw_write(offset, (uint8_t *) buffer, length);
 sd_raw_sync();

}

void sd_read(uint32_t offset, void *buffer, uint16_t length) {

 sd_raw_read(offset, (uint8_t *) buffer, length);

} </source>

Contents

Work as of April 22nd

I got 3 temperature sensors and 3 pressure sensors working on one board; it seems that there are some discrepancies inherent to the readouts of these pressure sensors; i recommend spending 50 bucks on four new ones, then we mix and match to see if we can get identical readouts; otherwise we can try debugging; I'll leave that up to someone else. The board is all setup. For a temperature sensor, pin 1 is data, pin 2 is ground and pin 3 is power, starting from the notched pin. for temperature sensors, with the flat end facing outwards towards the breadboard gutters, from the left side relative to the text on the flat end, pin 1 is power, pin two is data, and pin 3 is ground. The next step would be to get 4 pairs instead of 3, so we'll have to incorporate the max chip. As for now, this is the code that writes the songs that make the whole world sing.

Power

I also set up the unit to test power; please do not touch it for 24 hours. I started the test at 10:35 on wednesday night, and i will check on it at that time on thursday; the battery started with 6.450 volts, and the program is running as is right now; we should be able to be a sense of how much power we'll need for the whole thing by then.

<source lang="c">

  1. include <sd_raw_config.h>
  2. undef SD_RAW_WRITE_BUFFERING
  3. include <sd_raw.h>
  4. include <string.h>
  5. include <stdio.h>
  6. include <stdarg.h>
  1. define SD_RAW_WRITE_BUFFERING 0
  2. define PRESSURE_1 0
  3. define PRESSURE_2 1
  4. define PRESSURE_3 2
  5. define TEMPERATURE_1 3
  6. define TEMPERATURE_2 4
  7. define TEMPERATURE_3 5

//MAX395 STUFF, will fill in later. // #define NUM_MAX395_CHIPS 1 // #define NUM_MAX395_SWITCHES (NUM_MAX395_CHIPS*8)

// void max395Setup(void); // void max395Write(int sw, int value); void rsprintf(const char *format, ...);

int hello = 0x68656C6E; long log_count;

void setup(){ sd_raw_init(); sd_check_format(); //MAX395 STUFF, will fill in later.

 // max395Setup();

} void loop(){ int read1 = analogRead(PRESSURE_1); int read2 = analogRead(PRESSURE_2); int read3 = analogRead(PRESSURE_3);

 int tempc1, tempc2, tempc3;

tempc1 = (5.0 * analogRead(TEMPERATURE_1) * 100.0) / 1024.0; tempc2 = (5.0 * analogRead(TEMPERATURE_2) * 100.0) / 1024.0; tempc3 = (5.0 * analogRead(TEMPERATURE_3) * 100.0) / 1024.0; // rsprintf("%d,%d,%d,%d,%d,%d\n", read1, read2, read3, tempc1, tempc2, tempc3, log_count); sd_log(read1, read2, read3, tempc1, tempc2, tempc3, log_count); delay(1000); sd_print_log(); tempc1 = 0; tempc2 = 0; tempc3 = 0; //MAX395 STUFF, will fill in later. // int i;

 // while (1) {
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 //     delay(250);
 // 
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 // 
 //     delay(500);
 // }

}

//Struct for memory and sd card functions struct memory{ int pressureRead1; int pressureRead2; int pressureRead3; int tempRead1; int tempRead2; int tempRead3; long log_count; };

void sd_format(){ 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 pinRead1, int pinRead2, int pinRead3, int tempRead1, int tempRead2, int tempRead3, long timeStamp){

 struct memory mem; 
 mem.pressureRead1 = pinRead1;
 mem.pressureRead2 = pinRead2;
 mem.pressureRead3 = pinRead3;
 mem.tempRead1 = tempRead1;
 mem.tempRead2 = tempRead2;
 mem.tempRead3 = tempRead3;
 mem.log_count = timeStamp;
 // 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,%d,%d,%d,%d\n", mem.pressureRead1, mem.pressureRead2, mem.pressureRead3, mem.tempRead1, mem.tempRead2, mem.tempRead3, mem.log_count); } }


//********************************************************************************************** // // Max395 support //

// The Max395 is connected to three digital output pins on the Arduino

// #define SCLK_PIN 7 // max395 control line: synchronous clock. goes to max395 pin 1. // #define DIN_PIN 8 // max395 control line: data in. goes to max395 pin 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(); // } // // #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; // } // #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>

Work as of Apr 13th

Tonight I combined the pressure sensor and one LM35 on the same board; it looks like they are working, but now I'm only getting sensitivity on a very rough scale from the pressure sensor; to be precise, a range of 0-5 instead of 0-1023. I have run out of time for working on the project until I come back from long weekend; I'll be putting all of the gear, with our pressure sensor and temperature sensors, in the class room, in the back of the room, near the geology table, where that 6 volt battery was powering that arduino for weeks on end; If you are feeling up to the challenge sometime before our class next thursday, I would suggest that you take a look at the setup and try your luck with it. Have a great long weekend guys.

Some notes on future steez:

  • How many analog inputs can we have? can we have multiples via a max chip?
  • Why is the pressure sensor no longer giving us the values we were getting?
  • Can anybody order 3 more pressure sensors and rig them up before class?

We are looking very good right now; all that is really left is ironing out some of these problems, then building the sucker and dropping it off.

<source lang="c">

  1. include <sd_raw_config.h>
  2. undef SD_RAW_WRITE_BUFFERING
  3. include <sd_raw.h>
  4. include <string.h>
  5. include <stdio.h>
  6. include <stdarg.h>
  1. define SD_RAW_WRITE_BUFFERING 0
  2. define PRESSURE_PIN_1 0
  3. define PRESSURE_PIN_2 1
  4. define PRESSURE_PIN_3 2
  5. define PRESSURE_PIN_4 3
  6. define TEMP_PIN_1 4
  7. define TEMP_PIN_2 5

//MAX395 STUFF, will fill in later. // #define NUM_MAX395_CHIPS 1 // #define NUM_MAX395_SWITCHES (NUM_MAX395_CHIPS*8)

// void max395Setup(void); // void max395Write(int sw, int value); void rsprintf(const char *format, ...);

int hello = 0x68656C6E; long log_count;

void setup(){ sd_raw_init(); //MAX395 STUFF, will fill in later.

 // max395Setup();

} void loop(){ int pinRead1 = analogRead(PRESSURE_PIN_1); // int pinRead2 = analogRead(PRESSURE_PIN_2); added when we have 3 more pressure sensors... // int pinRead3 = analogRead(PRESSURE_PIN_3); // int pinRead4 = analogRead(PRESSURE_PIN_4); rsprintf("The Read is: %d\n", pinRead1);

 int tempc = 0,tempf=0; // temperature variables 

tempc = (5.0 * analogRead(TEMP_PIN_1) * 100.0) / 1024.0; tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit rsprintf("%d Celsius, %d fahrenheit -> \n", tempc, tempf); tempc = 0;

delay(1000); sd_log(pinRead1, log_count); sd_print_log(); //MAX395 STUFF, will fill in later. // int i;

 // while (1) {
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 //     delay(250);
 // 
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 // 
 //     delay(500);
 // }

}

//Struct for memory and sd card functions struct memory{ int pinRead1; long time; };

void sd_format(){ 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 pinRead1, long timeStamp){

 struct memory mem; 
 mem.pinRead1 = pinRead1;
 mem.time = timeStamp;
 // 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\n", mem.pinRead1, mem.time); } }


//********************************************************************************************** // // Max395 support //

// The Max395 is connected to three digital output pins on the Arduino

// #define SCLK_PIN 7 // max395 control line: synchronous clock. goes to max395 pin 1. // #define DIN_PIN 8 // max395 control line: data in. goes to max395 pin 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(); // } // // #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; // } // #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>



Notes on Pressure Sensor

Alright, so Kasia, Max, and Devin met up on the night of April 8, 2009, to try to figure out how a pressure sensor works. Thankfully, we figured out that the Pressure sensor we got the other day in the mail behaves essentially the same as a run of the mill potentiometer. The code (with slight integration to the other components we'll be using on this round) is below. I don't know what we're going to do about integrating cell phones to the arduino; it seems like that is going to be a lot of work, but at the same time, we will probably need that test run in order to perfect it for the air launch.

Anyways, I'm just talkin' at this point. Here's the deal. The chip we're using, the MPX5010DP, with the case modification of CASE 867C-05 has 6 pins. pin one is demarcated by a slight notch on the pin out. from that point, pin 1 goes to a grounded analog in, pin two goes to ground on the board, and pin 3 goes to power on the board. The rest of the pins are listed as "NO CURRENT," which is weird, but I guess if that is how they want to design their products, then they are certainly within the bounds to do so. We are going to purchase three more MPX5010DP's from Newark electronics. We bought the other one that was on sparkfun, but since this one was so easy to set up, we'll just donate it to another team if they want to go that route instead; it appears that it has a similar pin configuration, so it should behave exactly the same way.

--INTERNET--

<source lang="c">

  1. include <sd_raw_config.h>
  2. undef SD_RAW_WRITE_BUFFERING
  3. include <sd_raw.h>
  4. include <string.h>
  5. include <stdio.h>
  6. include <stdarg.h>
  1. define SD_RAW_WRITE_BUFFERING 0
  2. define PRESSURE_PIN_1 0
  3. define PRESSURE_PIN_2 1
  4. define PRESSURE_PIN_3 2
  5. define PRESSURE_PIN_4 3
  6. define TEMP_PIN_4 4
  7. define TEMP_PIN_4 5
  8. define TEMP_PIN_4 6

//MAX395 STUFF, will fill in later. // #define NUM_MAX395_CHIPS 1 // #define NUM_MAX395_SWITCHES (NUM_MAX395_CHIPS*8)

// void max395Setup(void); // void max395Write(int sw, int value); void rsprintf(const char *format, ...);

int hello = 0x68656C6E; long log_count;

void setup(){ sd_raw_init(); //MAX395 STUFF, will fill in later.

 // max395Setup();

} void loop(){ int pinRead1 = analogRead(PRESSURE_PIN_1); // int pinRead2 = analogRead(PRESSURE_PIN_2); added when we have 3 more pressure sensors... // int pinRead3 = analogRead(PRESSURE_PIN_3); // int pinRead4 = analogRead(PRESSURE_PIN_4); rsprintf("The Read is: %d", pinRead1); delay(1000); sd_log(pinRead1, log_count); sd_print_log(); //MAX395 STUFF, will fill in later. // int i;

 // while (1) {
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 //     delay(250);
 // 
 //     max395Write(0, 1);
 //     max395Write(1, 1);
 //     delay(125);
 //     max395Write(0, 0);
 //     max395Write(1, 0);
 // 
 //     delay(500);
 // }

}

//Struct for memory and sd card functions struct memory{ int pinRead1; long time; };

void sd_format(){ 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 pinRead1, long timeStamp){

 struct memory mem; 
 mem.pinRead1 = pinRead1;
 mem.time = timeStamp;
 // 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\n", mem.pinRead1, mem.time); } }


//********************************************************************************************** // // Max395 support //

// The Max395 is connected to three digital output pins on the Arduino

// #define SCLK_PIN 7 // max395 control line: synchronous clock. goes to max395 pin 1. // #define DIN_PIN 8 // max395 control line: data in. goes to max395 pin 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(); // } // // #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; // } // #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>


Notes on temperature readouts

There are two chips out there that are promising: the DS1822 and the LM35. The DS1822 produces a digital signal that has to be boiled down to something that makes sense. This takes a tone of code, including a OneWire.h file that I as of yet cannot figure out how to set up. It seems that the DS1820 family of chips were setup to work perfectly with Arduino 0010, but in 0013 Alpha, nothing is going right at all. As of right now, we would need to spend tons and tons of time trying to figure out how to get these to work accurately; alternatively, we could just order LM35's, which are much easier to work with and seem to produce just as reliable data; they are just better cataloged. I have put in the code in comparison. If you want, you can go hunt out the information on these solutions at the Freeduino Index at http://www.freeduino.org/. This will give you a sense of what is out there; look under sensors - temperature and under temperature; all the worthwhile code and discussion is located in these links (about 12 in total).

LM35 Example code

<source lang="c"> /* An open-source LM35DZ Temperature Sensor for Arduino. This project will be enhanced on a regular basis (cc) by Daniel Spillere Andrade , http://www.danielandrade.net http://creativecommons.org/license/cc-gpl

  • /

int pin = 0; // analog pin int tempc = 0,tempf=0; // temperature variables int samples[8]; // variables to make a better precision int maxi = -100,mini = 100; // to start max/min temperature int i;

void setup() {

 Serial.begin(9600); // start serial communication

}

void loop() {


for(i = 0;i<=7;i++){ // gets 8 samples of temperature

 samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
 tempc = tempc + samples[i];
 delay(1000);

}

tempc = tempc/8.0; // better precision tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit

if(tempc > maxi) {maxi = tempc;} // set max temperature if(tempc < mini) {mini = tempc;} // set min temperature

Serial.print(tempc,DEC); Serial.print(" Celsius, ");

Serial.print(tempf,DEC); Serial.print(" fahrenheit -> ");

Serial.print(maxi,DEC); Serial.print(" Max, "); Serial.print(mini,DEC); Serial.println(" Min");

tempc = 0;

delay(1000); // delay before loop } </source>


DS1822 Example code

<source lang="c"> //BEGIN OneWire.h //RIGHT HERE>>>>>>

  1. include <Wire.h>


  1. include <inttypes.h>

// you can exclude onewire_search by defining that to 0

  1. ifndef ONEWIRE_SEARCH
  2. define ONEWIRE_SEARCH 1
  3. endif

// You can exclude CRC checks altogether by defining this to 0

  1. ifndef ONEWIRE_CRC
  2. define ONEWIRE_CRC 1
  3. endif

// Select the table-lookup method of computing the 8-bit CRC by setting this to 1

  1. ifndef ONEWIRE_CRC8_TABLE
  2. define ONEWIRE_CRC8_TABLE 0
  3. endif

// You can allow 16-bit CRC checks by defining this to 1 // (Note that ONEWIRE_CRC must also be 1.)

  1. ifndef ONEWIRE_CRC16
  2. define ONEWIRE_CRC16 0
  3. endif

class OneWire {

 private:
  1. if ONEWIRE_SEARCH
   uint8_t address[8];
   char searchJunction;
   uint8_t searchExhausted;
  1. endif
   uint8_t pin;
   uint8_t port;
   uint8_t bitmask;
   volatile uint8_t *outputReg;
   volatile uint8_t *inputReg;
   volatile uint8_t *modeReg;
 public:
   OneWire( uint8_t pin);
   
   // Perform a 1-Wire reset cycle. Returns 1 if a device responds
   // with a presence pulse.  Returns 0 if there is no device or the
   // bus is shorted or otherwise held low for more than 250uS
   uint8_t reset();
   // Issue a 1-Wire rom select command, you do the reset first.
   void select( uint8_t rom[8]);
   // Issue a 1-Wire rom skip command, to address all on bus.
   void skip();
   // Write a byte. If 'power' is one then the wire is held high at
   // the end for parasitically powered devices. You are responsible
   // for eventually depowering it by calling depower() or doing
   // another read or write.
   void write( uint8_t v, uint8_t power = 0);
   // Read a byte.
   uint8_t read();
   // Write a bit. The bus is always left powered at the end, see
   // note in write() about that.
   void write_bit( uint8_t v);
   // Read a bit.
   uint8_t read_bit();
   // Stop forcing power onto the bus. You only need to do this if
   // you used the 'power' flag to write() or used a write_bit() call
   // and aren't about to do another read or write. You would rather
   // not leave this powered if you don't have to, just in case
   // someone shorts your bus.
   void depower();
  1. if ONEWIRE_SEARCH
   // Clear the search state so that if will start from the beginning again.
   void reset_search();
   // Look for the next device. Returns 1 if a new address has been
   // returned. A zero might mean that the bus is shorted, there are
   // no devices, or you have already retrieved all of them.  It
   // might be a good idea to check the CRC to make sure you didn't
   // get garbage.  The order is deterministic. You will always get
   // the same devices in the same order.
   uint8_t search(uint8_t *newAddr);
  1. endif
  1. if ONEWIRE_CRC
   // Compute a Dallas Semiconductor 8 bit CRC, these are used in the
   // ROM and scratchpad registers.
   static uint8_t crc8( uint8_t *addr, uint8_t len);
  1. if ONEWIRE_CRC16
   // Compute a Dallas Semiconductor 16 bit CRC. Maybe. I don't have
   // any devices that use this so this might be wrong. I just copied
   // it from their sample code.
   static unsigned short crc16(unsigned short *data, unsigned short len);
  1. endif
  2. endif

};


//END ONE WIRE HEADER FILE, JUST ADDED IN HERE SO YOU DON'T HAVE TO HUNT...


// DS18S20 Temperature chip i/o

OneWire ds(10); // on pin 10

void setup(void) {

 // initialize inputs/outputs
 // start serial port
 Serial.begin(9600);

}

void loop(void) {

 byte i;
 byte present = 0;
 byte data[12];
 byte addr[8];
 if ( !ds.search(addr)) {
     Serial.print("No more addresses.\n");
     ds.reset_search();
     return;
 }
 Serial.print("R=");
 for( i = 0; i < 8; i++) {
   Serial.print(addr[i], HEX);
   Serial.print(" ");
 }
 if ( addr[0] != 0x22) {
     Serial.print("Device is not a DS1822 device.\n");
     return;
 }
 ds.reset();
 ds.select(addr);
 ds.write(0x44,1);         // start conversion, with parasite power on at the end
 delay(1000);     // maybe 750ms is enough, maybe not
 // we might do a ds.depower() here, but the reset will take care of it.
 present = ds.reset();
 ds.select(addr);    
 ds.write(0xBE);         // Read Scratchpad
 Serial.print("P=");
 Serial.print(present,HEX);
 Serial.print(" ");
 for ( i = 0; i < 9; i++) {           // we need 9 bytes
   data[i] = ds.read();
   Serial.print(data[i], HEX);
   Serial.print(" ");
 }
 Serial.print(" CRC=");
 Serial.print( OneWire::crc8( data, 8), HEX);
 Serial.println();

} </source>

Personal tools