Friday, 25 November 2011

FINAL CIRCUIT DESIGN AND CURRENT MEASUREMENTS OF DATA LOGGING CIRCUIT

I have finished designing the data logger. I also measured the current draw of the main components of this circuit.

Arduino                                         47mA
Lm324 (Quad Op-amp)               1.5mA
Lm35 (Thermistor)                        15mA
24L256 (EEPROM)                     33mA
Mx210A (accelerometer)                3mA
MPX100 (barometer)                   10mA

TOTAL                                   ~ 110mA

The circuit design is as follows and the code remains the same as it was in the last post.


Note: there is supposed to be a logic switch on pin 14 and pin 15 of the arduino which tell the arduino whether to begin writing data or to read data (this process is in the code)

Saturday, 19 November 2011

Read/Write Program and circuit with External EEPROM Memory Chip

I have created a program and circuit that allows for the reading and writing of memory onto the EEPROM chip. The program has 4 analog inputs, and if the switch at d8 is flipped to 5V, then the microchip will begin to read values from four analog inputs (A6, A5, A4, A3) and write them to the memory of the external EEPROM chip. If the switch at d9 is turned to 5V, then the microchip will existing data from the EEPROM memory chip.


Heres the code I wrote for the program.

/*
WRITE READ 4 ANALOG INPUTS
program waits in a loop for the switch on either d8 or d9 to be thrown.
if d8 is thrown, it goes into write mode writing the voltages at 4 analog inputs
if d9 is thrown, it goes into read mode, reading all the information stored on the eeprom chip (waits for d9 to be shut off)
*/
#include  "Wire.h"    // for External EEPROM CHIP
#define chip 0x50    // device address for our chip
byte d=0; // example variable to handle data going in and out of EERPROM
int endLoop=0; //to define the end of our write loop
void setup()
{
Serial.begin(9600); // for screen output
Wire.begin();   // wake up, EEPROM
}
void writeData(unsigned int add, byte data)
// writes a byte of data 'data' to the chip at I2C address 'device', in memory location 'add'
{
Wire.beginTransmission(chip);
Wire.send((int)(add >> 8));   // left-part of pointer address
Wire.send((int)(add & 0xFF)); // and the right
Wire.send(data);
Wire.endTransmission();
Serial.println(data, DEC);
delay(10);
}
byte readData(unsigned int add) // reads a byte of data from memory location 'add' in chip at I2C address 'device'
{
byte result;  // returned value
Wire.beginTransmission(chip); //  these three lines set the pointer position in the EEPROM
Wire.send((int)(add >> 8));   // left-part of pointer address
Wire.send((int)(add & 0xFF)); // and the right
Wire.endTransmission();
Wire.requestFrom(chip,1); // now get the byte of data...
result = Wire.receive();  return result; // and return it as a result of the function readData
}
void loop()  {
  
  int sensor0=0; // integer value between 0 and 1023 (10 bits) for sensor 1
  int sensor1=0; 
  int sensor2=0;
  int sensor3=0;  
  Serial.println("Waiting to write or read data....");
  while(digitalRead(8)==LOW&&digitalRead(9)==LOW){   // while loop reads pin 8 and will stay in loop until pin 8 recieves 5 volts
    digitalWrite(13, HIGH);  //writes pin 13 to 5 volts
    delay(1000);             //waits a second
    digitalWrite(13, LOW);   //writes pin 13 to 0 volts
    delay(1000);             //watis a seconds
  }
    
  if(digitalRead(8)==HIGH){           //Loop that writes data
    int a=0;
    Serial.println("Writing data...");
    while(digitalRead(8)==HIGH)
    {
      digitalWrite(13, HIGH);  //writes pin 13 to 5 volts
      sensor0=analogRead(A0);
      sensor1=analogRead(A1);
      sensor2=analogRead(A2);
      sensor3=analogRead(A3);
      byte first0  = lowByte(sensor0); //takes the lowest 8 bits from the 10 bit number 
      byte second0 = highByte(sensor0);//takes the takes the last 2 digits from the 10 bit number, and 6 zeros
      byte first1  = lowByte(sensor1); //takes the lowest 8 bits from the 10 bit number 
      byte second1 = highByte(sensor1);//takes the takes the last 2 digits from the 10 bit number, and 6 zeros
      byte first2  = lowByte(sensor2); //takes the lowest 8 bits from the 10 bit number 
      byte second2 = highByte(sensor2);//takes the takes the last 2 digits from the 10 bit number, and 6 zeros
      byte first3  = lowByte(sensor3); //takes the lowest 8 bits from the 10 bit number 
      byte second3 = highByte(sensor3);//takes the takes the last 2 digits from the 10 bit number, and 6 zeros
      writeData(a,first0);
      writeData(a+1,second0);
      writeData(a+2,first1);
      writeData(a+3,second1);
      writeData(a+4,first2);
      writeData(a+5,second2);
      writeData(a+6,first3);
      writeData(a+7,second3);
      delay(5000);
      a=a+8;
    }
    endLoop=a;  
}
  if(digitalRead(9)==HIGH){                ///loop that reads data
    digitalWrite(13,LOW);
    Serial.println("S0   S1   S2   S3");
    int b=0;
    while(b<endLoop)
    {
      byte low0 = readData(b);    //defines low0 as whats in the chips memory space b
      byte high0 = readData(b+1);
      byte low1 = readData(b+2);
      byte high1 = readData(b+3);
      byte low2 = readData(b+4);
      byte high2 = readData(b+5);
      byte low3 = readData(b+6);
      byte high3 = readData(b+7);
      int result0=high0<<8; // rotate left 8 bits the high value and store in result
      int result1=high1<<8;
      int result2=high2<<8;
      int result3=high3<<8;
      Serial.print(result0+low0,DEC);//prints first result 
      Serial.print("  ");
      Serial.print(result1+low1,DEC);//prints second result 
      Serial.print("  ");//puts a space between results
      Serial.print(result2+low2,DEC);//prints third result 
      Serial.print("  ");
      Serial.println(result3+low3,DEC); //prints the fourth result and carridge returns
      b=b+8;
  }
  while(digitalRead(9)==HIGH){}
 } 
}

Wednesday, 9 November 2011

Esitmating the battery life of the components for the test flight

The current draw was measured from the baloon exploder microchip, the gps, and, the buffer op amp, and the data aquisition arduino. The baloon exploder microchip draws about 22 mA while counting, the buffer draws 36 mA (used an lf411 to estimate, but this is a +/- 15V op-amp which we will be replacing with a one sided 12V one that will draw less), the data aquisition microchip draws 25 mA, and the gps draws 45 mA. We are missing current draw from a few 12V regulators, but these aren't in yet, but the draw should be rather low. The current draw from the actual fuze itself is negligible because it will only draw current for less than a second. This gave us an estimated total of 128 mA draw from the entire circuit.

We are planning to use two 9V batteries in series to make 18V which we can regulate down. These batteries have a capacity of 500mAh, giving us an estimated 3.9 hours. These batteries have an operating range of -20°C to 54°C. This should be more than enough for the test flight.

Friday, 4 November 2011

EEPROM MEMORY STORAGE

I have been working on a program that will take data, and store it. Regularly when values are taken from a microchip, the data is stored into SRAM, which is cleared when the power is reset. For our balloon we want to be able to measure voltages from thermistors, pressure sensors and possibly other devices, and we don't want to lose this data when the power is shut off. So this data must be stored to either the EEPROM memory or the Atmega's flash memory. The difference between the two is that data going into EEPROM can only be stored byte by byte, and must be addressed where it is going, where data in flash memory can be stored in tables and arrays and are just stored "somewhere". After struggling with storing and retrieving data from flash memory, I decided to try using the EEPROM, even though we will likely have to use flash memory due to the lack of space in the Atmega's EEPROM.


***UPDATE*** The EEPROM memory will have to be used because only compiled information can be stored in the flash memory. Anything being declared after complile stages cannot be stored in the flash memory. We have placed and order for a seperate EEPROM memory chip that has 128 kB of memory, which will be more than enough for storing the flight data.


Below, is the code I successfully wrote for this process. I will be attempting to learn and figure out how to properly store and retrieve data into the flash memory.


/*
 Analog Reader
 Standby: Repeatedly blinks an LED
 Recieves voltage at input 8, turns off standby
 Repeatedly reads Voltages from analog pin 0, stores them in EEPROM memory.
 Once switch is turned, stops storing and goes into stanby 2 waiting for an input a pin9
 Once this is turned, it will read values either until it has read them all, or pin9 is turned off
*/
#include <EEPROM.h>
void setup() {              
  pinMode(8, INPUT);      //pin 8 is set to an input
  pinMode(13, OUTPUT);    //pin 12 is set to output
  pinMode(9,INPUT);       //pin 9 is set to an input
  Serial.begin(9600);     // baud rate for the chip is set to 9600
  }
void loop(){
  int sensor0 = 0;            //int to store value read from A0
 
  while(digitalRead(8)==LOW){   // while loop reads pin 8 and will stay in loop until pin 8 recieves 5 volts
    digitalWrite(13, HIGH);  //writes pin 13 to 5 volts
    delay(1000);             //waits a second
    digitalWrite(13, LOW);   //writes pin 13 to 0 volts
    delay(1000);             //watis a seconds
  }

  digitalWrite(13,HIGH);
  int k=0;
  while(digitalRead(8)==HIGH){      //while loop stores data in the first 6 bits availiable in EEPROM just for testing purposes
    sensor0=analogRead(A0);         //sets sensor0 to the value read from A0
    byte first  = lowByte(sensor0); //takes the lowest 8 bits from the 10 bit number
    byte second = highByte(sensor0);//takes the takes the last 2 digits from the 10 bit number, and 6 zeros
    int first8bits = first;         //converts the first 8 bits to an int
    int last8bits = second;         //converts the last bits to an int
    EEPROM.write(k, first8bits);    //writes this integer to EEPROM memory in space k
    EEPROM.write((k+1), last8bits); //writes this integer to EEPROM memory in space K+1
    digitalWrite(13,LOW);           //blinks to show it has written
    delay(500);
    digitalWrite(13,HIGH);      
    delay(5000);              
    k=k+2;                          //sets counter variable k=k+2
  }
  while(digitalRead(8)==LOW&&digitalRead(9)==LOW){  ///standby 2. Waits for switch at input9 to be turned on.
    digitalWrite(13,LOW);
    delay(100);
    digitalWrite(13,HIGH);
    delay(100);
  }
  int j=0;                            //new counter variable
  while(j<=k&&digitalRead(9)==HIGH){  //loops until j is i greater than k or switch is turned off
   digitalWrite(13,LOW);              //blink to show what state it is in
   int test1 = EEPROM.read(j);        //sets temp1 variable equal to what is in EEPROM slot j
   int test2 = EEPROM.read(j+1);      //sets temp2 variable equal to what is in eeprom slot j+1
   Serial.println(test1);             //sends numbers to computer via serial
   Serial.println(test2);
   delay(500);
   digitalWrite(13,HIGH);
   j=j+2;                             //counter is increased by 2
  }
}