Pages: 1 [2]   Go Down
Author Topic: datalogger for counter sensor with RTC HELP!  (Read 3287 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
however, i wish i could make something like this where you don't include the data of sensor A when the sensor B was incremented, like this
Hard to see in that tiny picture, but writing out the changed value in column 1 or column 2 or both is trivial. If one or more values change, you need to write a record. For each column, determine what to put in that column - a new value or a series of spaces. Then, write the record.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
Hard to see in that tiny picture, but writing out the changed value in column 1 or column 2 or both is trivial. If one or more values change, you need to write a record. For each column, determine what to put in that column - a new value or a series of spaces. Then, write the record.

I modified my post. I wish i can create a logger like the one on the second picture. Can you suggest what can i do? thanks!!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also wonder why one of the sensor does a double count when i pressed it once. But if i unplug one pin. It actually just works right. hmmmmmm.

Im using 2 pushbuttons as my sensor. In the program i used debouncing so i don't think its the problem.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The last posted code contains:
Code:
    if (logFile)
    {
      logFile.print(buttonBeeCounterA);
      logFile.print(",");
      logFile.println(buttonBeeCounterB);
      Serial.print(buttonBeeCounterA);
      Serial.print(",");
      Serial.println(buttonBeeCounterB);
    }
inside an if test:
Code:
if (beeCounterA != lastBeeCounterA)
It's hard to tell whether you have a similar prevBeeCounterB, or not. You would need one.

The variable names used in this application are terrible. I look at a name like buttonBeeCounterA and I think of a pin that a switch is connected to. I can't imagine why writing a pin number to the output file is of any interest.

I think that the best thing, at this point, is for you to post all of your code.

Changing the whether to log code is easy:
Code:
if (beeCounterA != lastBeeCounterA || beeCoutnerB != lastBeeCounterB)

In the code to actually log data:
Code:
   if(beeCounterA != lastBeeCounterA)
   {
      logFile.print(buttonBeeCounterA);
   }
   logFile.print(",");
   if(beeCoutnerB != lastBeeCounterB)
   {
      logFile.print(buttonBeeCounterB);
   }

But, like I said, I can't tell that the correct stuff is being tested, or that the correct stiff is being written to the file, since the names are horrible.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think that the best thing, at this point, is for you to post all of your code.

im sorry for the terrible names, i changed it a little bit i hope it will be more understandable.

Code:
//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Assisted by Inigo D. Villanueva III
//Edited by Ignacio D. Villanueva III
//For thesis purpose entitled "
//Thesis members: James Santiago. Belen Cruz. Franzes Francisco, Kaye Agut

#include <SD.h>         //SD Card Library

//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
int CS_pin = 10;
int pow_pin = 8;

// this constant won't change:
const int  buttonPinA = 3;    // the pin that the pushbutton is attached to
const int  buttonPinB = 5;

// Variables will change:
int CurrentNumberofBeesA = 0;   // counter for the number of button presses
int ActualStateofCounterA = 0;         // state of the button (Either HIGH or LOW)
int PreviousStateofCounterA = 0;     // previous state of the button (Either HIGH or LOW)
int CurrentNumberofBeesB = 0;   // counter for the number of button presses
int ActualStateofCounterB = 0;         // state of the button (Either HIGH or LOW)
int PreviousStateofCounterB= 0;     // previous state of the button (Either HIGH or LOW)


long lastEvent= 0; // The last time a bee has entered the feeding station
long interval= 300; // The debounce time



void setup() {

  Serial.begin(9600);
  Serial.println("Initializing Card");
  //CS Pin is an output
  pinMode(CS_pin, OUTPUT);

  //SD Card will Draw Power from Pin 8, so set it high
  pinMode(pow_pin, OUTPUT); 
  digitalWrite(pow_pin, HIGH);

  //Initialize Card
  if (!SD.begin(CS_pin))
  {
    Serial.println("Card Failure");
    return;
  }
  Serial.println("Card Ready");

  // initialize the button pin as a input:
  pinMode(buttonPinA, INPUT);
  pinMode(buttonPinB, INPUT);

  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  ActualStateofCounterA= digitalRead(buttonPinA);
  ActualStateofCounterB = digitalRead(buttonPinB);

  // compare the buttonState to its previous state
  if ((ActualStateofCounterA != PreviousStateofCounterA ) || (ActualStateofCounterB != PreviousStateofCounterB))
  {
    // if the state has changed, increment the counter
    if (ActualStateofCounterA == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
    {
      lastEvent= millis(); // a bee can be recorded)
      // if the current state is HIGH then the button
      // wend from off to on:

      CurrentNumberofBeesA++;
      Serial.println("Bees are being detected entering Feeding Station A");
      Serial.print("number of bees that entered Feeding Station A:  ");
      Serial.println(CurrentNumberofBeesA);

    }
    {   
      // if the state has changed, increment the counter
      if (ActualStateofCounterB == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
      {
        lastEvent= millis(); // a bee can be recorded)
        // if the current state is HIGH then the button
        // wend from off to on:
      } 
      CurrentNumberofBeesB++;
      Serial.println("Bees are being detected entering Feeding Station B");
      Serial.print("number of bees that entered Feeding Station B:  ");
      Serial.println(CurrentNumberofBeesB);
    }




    //Write Log File Header
    File logFile = SD.open("DATALOG.csv", FILE_WRITE);
    if (logFile)


    {

      if(ActualStateofCounterA != PreviousStateofCounterA)

        logFile.print(CurrentNumberofBeesA);
      logFile.print(", ");
      logFile.println(CurrentNumberofBeesB);
      logFile.close();

      Serial.print(CurrentNumberofBeesA);
      Serial.print(", ");
      Serial.println(CurrentNumberofBeesB);

    }
    else

    {
      Serial.println("LogFile cannot be opened");

    }

    CurrentNumberofBeesA= ActualStateofCounterA;
    CurrentNumberofBeesB= ActualStateofCounterB;


  }

}










Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i hope it will be more understandable.
I'm sorry, but in my opinion, you have a ways to go.

Code:
int ActualStateofCounterA = 0;         // state of the button (Either HIGH or LOW)
Nowhere in this name is there a clue that it is a switch state. Counter is not a switch. Names like currStateA, currStateB, prevStateA, and prevStateB give a much clearer picture.

Code:
int CurrentNumberofBeesA = 0;   // counter for the number of button presses
Just out of curiosity, how do you get the bees to press the switches? It seems unlikely that they do, so it seems unlikely that you are using pushbutton switches. The names of variables, and the comments should reflect the kind of hardware actually used.

Code:
long lastEvent= 0; // The last time a bee has entered the feeding station
Last event of what kind? Details are important. Reading the comments is useful, but 300 lines later in the code, I won't remember what kind of event this is supposed to be. lastBeeFeeding or lastEventLogged would tell me, without the need for comments, exactly what last event.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pardon me, okay what i did here is that i have a pulse sensor, It is a phototransistor and an IR led, when the bee passed that a pulse (HIGH) will be detected, and it must increment the number. I originally modified the StateChangedetection program for this, and as a preliminary test i used push buttons to replace the sensor for conveniency purposes

BTW i replaced it this way

Code:
// Variables will change:
int CurrentNumberofBeesA = 0;   // counter for the number of bees that entered the sensor
int ActualStateofSensorA = 0;         // state of the sensor (Either HIGH or LOW)
int PreviousStateofSensorA = 0;     // previous state of the sensor (Either HIGH or LOW)
int CurrentNumberofBeesB = 0;   // counter for the number of bees that entered the sensor
int ActualStateofSensorB = 0;         // state of the sensor (Either HIGH or LOW)
int PreviousStateofSensorB= 0;     // previous state of the sensor (Either HIGH or LOW)


long lastEvent= 0; // The last time a bee has entered the feeding station or the last time a bee was detected by the sensor
Logged

Pages: 1 [2]   Go Up
Jump to: