Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: program to run two PIR with time stamp on: May 01, 2008, 04:34:02 pm
Anyone?  smiley-sad
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: program to run two PIR with time stamp on: April 27, 2008, 12:32:08 pm
here is some data i have collected on one of my seven boards with in a 26hour period" the first column is hours the second is minutes, is my clock running fast or something i dont get it....



0      1      3      3      3      3      4      4      4      4      19      21      21      21      22      22      23      0      0      0      0      0      0      1      1      1      1      2      2      3      3      3      4      4      5      7      7      7      7      9      9      16      16      16      16      17      17      18      21      22      1      2      2


43      6      22      28      33      36      1      5      25      31      54      18      48      56      37      38      21      8      32      41      44      49      56      2      9      27      48      29      36      34      36      47      55      58      35      18      21      31      46      5      14      17      22      28      32      33      34      46      13      56      58      49      50
3  Forum 2005-2010 (read only) / Syntax & Programs / program to run two PIR with time stamp on: April 27, 2008, 12:22:33 pm
how does this look. I have it to collect data from hallway traffic from two passive IR sensors. When some one walks by it writes a time stamp to sram. Im running the board on two 6v lantern batteries for a total of 12volts. It looks like in a 24 hour period that im getting some weird times tho. Please help!

Code:
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <EEPROM.h>

#define INIT_TIMER_COUNT 6
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT

int infra_red_a = 2;    // IR Sensor connected to digital pin 2
int infra_red_l = 3;    // IR Sensor connected to digital pin 3
int int_counter = 0;

volatile int i = 0;
volatile int z = 0;
volatile int timer1=0;
volatile int timer2=0;
volatile int time_limit = ;//The time period between allowed writes to the board
volatile char time_h = 0;//hours,minutes,seconds
volatile char time_m = 0;
volatile char time_s = 0;
int ledPin = 13; //FOR TESTING DUH~
volatile char timeStamp[64][4];
char incomingByte = 0;


 // Aruino runs at 16 Mhz, so we have 1000 Overflows per second...  
 // 1/ ((16000000 / 64) / 256) = 1 / 1000  
 //this is to do timestamps correctly
  ISR(TIMER2_OVF_vect) {  //everytime counter = 1000, 1 sec passed , run clock function
   RESET_TIMER2;  
   int_counter += 1;  
   if (int_counter == 1000) {  
     //second+=1;  
       time_s+=1;
     int_counter = 0;
       clock();
   }  
 };  

void setup(){                             // run once, when the sketch starts
  pinMode(infra_red_a, INPUT);        // sets the digital pin as input 2
  pinMode(infra_red_l, INPUT);              // sets the digital pin as input 3  
  attachInterrupt(0,arrival,RISING);  //interrupts when first sensor goes off
  attachInterrupt(1,leaving,FALLING); //interrupts when second sensor turns off
  pinMode(ledPin, OUTPUT);//MORE TESTING
  Serial.begin(9600);//Sets Baud Rate For Serial Comm.
  Serial.flush();

 // for(int i=0;i<800;i++)
   // timeStamp[i]=0;
    //Timer Settings, for the Timer Control Register etc. , thank you internets
   //Timer2 Settings: Timer Prescaler /64,  
   TCCR2B |= (1<<CS22);      
   TCCR2B &= ~((1<<CS21) | (1<<CS20));      
   // Use normal mode  
   TCCR2A &= ~((1<<WGM21) | (1<<WGM20));    
   // Use internal clock - external clock not used in Arduino  
   ASSR |= (0<<AS2);  
   //Timer2 Overflow Interrupt Enable  
   TIMSK2 |= (1<<TOIE2) | (0<<OCIE2A);    
   RESET_TIMER2;                
   //sei();  
   //starttime = millis();    
  
 }

void loop(){               // run over and over again
 //dont know if this will actually do anything.... as its all interrupt driven
 delay(1000);
 digitalWrite(ledPin, LOW);
 
  if (Serial.available() > 0) {
            // read the incoming byte:
            incomingByte = Serial.read();
            if(incomingByte = 'a'){
                  sss();}//grab the data and output it to the serial monitor
              else if(incomingByte = 'b'){
                  Serial.flush();}//Clears the serial data
      
}
 

 
}


void sss(){
//this is going to be fun!
//read flash memory
//send all data points to the serial monitor
//POINTS ARE LOST AFTER MONITOR IS CLOSED, DO NOT CLOSE IF U DONT HAVE DATA

//timeStamp[0][0]=87;
int f=0;



for(int k=0;k<z;k++){
      for(int j=0;j<4;j++){
            f=timeStamp[k][j];
            Serial.println(f,DEC);
      }
      }
      

}

void arrival(){
 //EEPROM will be tooo small
/* This is where the code goes that will
 *  Store a timestamp when the 1st sensor triggers
 *  Example Stamp
 *  Sensor - Hour - Minute - Second
*        1         10              5        32
*      110532
*/
if(timer1 == 0){
char arrival = 1;



digitalWrite(ledPin, HIGH);   // sets the LED on


EEPROM.write(i,arrival);
EEPROM.write(i+1,time_h);
EEPROM.write(i+2,time_m);
EEPROM.write(i+3,time_s);

i = i+4;

//timeStamp[z][0]= {arrival,time_h,time_m,time_s};
timeStamp[z][0]=arrival;
timeStamp[z][1]=time_h;
timeStamp[z][2]=time_m;
timeStamp[z][3]=time_s;
z++;
timer1 = 1;
}
}

/*
prog_int16_t   - a signed int (2 bytes) -32,767 to 32,768

*/


void leaving(){
/* This is where the code goes that will
 *  Store a timestamp when the 2nd sensor triggers
 *  Example Stamp
 *  Sensor - Hour - Minute - Second
*        2         10              5        42
*      210532
*/
if(timer2 == 0 ){
char leave = 2;

digitalWrite(ledPin, HIGH);   // sets the LED on

EEPROM.write(i,leave);
EEPROM.write(i+1,time_h);
EEPROM.write(i+2,time_m);
EEPROM.write(i+3,time_s);

i = i+4;

timeStamp[z][0]=leave;
timeStamp[z][1]=time_h;
timeStamp[z][2]=time_m;
timeStamp[z][3]=time_s;
z++;
timer2 = 1;
}
}

void clock(){
int time3 =0;


time_s++;
  if(time_s > 59){
    time_s = 0;
    time_m++;
      time3++;
    if(time_m > 59){
      time_m = 0;
      time_h++;
      if(time_h > 23){
        time_h = 0;
      }
      }
 }
 
 //code to renable writes
 
 if( (time3 >= time_limit) && (timer1==1)){
      timer1=0;
      time3=0;
 }
 if((time3 >= time_limit) && (timer2==1)){
            timer2=0;
            time3=0;
 }
 
};

//EEPROM.write(i, arrival);
//EEPROM.write(i, time_h);
//EEPROM.write(i, time_m);
//EEPROM.write(i, time_s);
//i = sizeof(arrival) + sizeof(time_h) + sizeof(time_m) + sizeof(time_s);

//PROGMEM  prog_uint16_t charSet[]  = { 65000, 32796, 16843, 10, 11234};
//PROGMEM  prog_int16_t timeStamp[z]  = { arrival , time_h , time_m, time_s};
4  Forum 2005-2010 (read only) / Troubleshooting / Re: disable auto-reset by serial connection on: April 18, 2008, 09:45:19 am
Quote
Quote
so this code will work with the usb diecimila? i have problem where the arduino is being powered via battery and when i plug in the usb to collect data from the sram the board resets and i loose all my data  smiley-sad

if not will removing those r2 and r3 on the board work. I would like to avoid this....
thanks

Yes it is the USB Diecimila. I have only been using it USB powered though. The code works for connecting several timed to the Diecimila over USB/Serial from the same or different PC program, without causing a board reset. I don't know if it would be a problem to power from battery and connect/disconnect USB cable like you say.

I need to know where to put that code (i.e. I'm assuming it goes into the serial client program..... any chance of getting the full source code?)
 
Thanks again!
5  Forum 2005-2010 (read only) / Troubleshooting / Re: disable auto-reset by serial connection on: April 18, 2008, 01:26:40 am
so this code will work with the usb diecimila? i have problem where the arduino is being powered via battery and when i plug in the usb to collect data from the sram the board resets and i loose all my data  smiley-sad

if not will removing those r2 and r3 on the board work. I would like to avoid this....

thanks
Pages: [1]