Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: RPM Interrupt speed limit on: November 05, 2012, 05:16:09 am
Peter, Thank you for the explanation.

Paul S, I am not suggesting your comment about other interrupts still running is untrue, but it is unclear if your are just pointing out my ignorance or it has an impact on my goal, with out an explanation it is difficult to decide if it is a worthwhile avenue to explore. Helping people is not just about saying what is wrong, is it? I don't want you to code it for me, I can buy code, I want to learn, have fun, as you can see by the style of my code and how times I have posted that I am very new to this and at this stage need a bit of "hand holding". Hopefully as time goes on, I can get better and help others, until then I am just another newbie asking questions in blissful ignorance.
2  Using Arduino / Project Guidance / Re: RPM Interrupt speed limit on: November 04, 2012, 04:34:12 pm
PaulS

Quote
The comment is wrong. Some (maybe even many) interrupts will happen while your interrupt is detached.
Does this have any connection with my question or is this just an observation of my code comments?

Your offer a statement that the interrupt is detached for a long time. Is this why a see a limit at around 7000 RPM? Thank you for telling me what's wrong but it doesn't give me an opportunity to learn or move forward.
Simon
3  Using Arduino / Project Guidance / RPM Interrupt speed limit on: November 04, 2012, 02:08:53 pm
I am recording the RPM of a motor as start to a bigger project, the below code seems to have a limit of around 7000 to 8000 RPM. I am trying find out if this is a limitation of my hardware, the design of the hardware, code or Arduino.

The hardware consists of a IR LED and IR photosensor (SFH229 and SFH4350) spaced about 7mm apart at a radius of 23mm, a propeller (blade 12mm wide) pass's the IR's twice every revolution.

Any help or suggestions would be appreciated

Regards Simon

Code:
// RPM output to Serial Monitor using Interupt

volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;

void setup()
{
  Serial.begin(9600);
  //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
  //Triggers on FALLING (change from HIGH to LOW)
  attachInterrupt(0, rpm_fun, FALLING);

  rpmcount = 0;
  rpm = 0;
  timeold = 0;
}

void loop()
{
  //Don't process interrupts during calculations
  detachInterrupt(0);
  //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
  //happened once per revolution instead of twice. Other multiples could be used
  //for multi-bladed propellers or fans
  rpm = 30*1000/(millis() - timeold)*rpmcount;
  timeold = millis();
  rpmcount = 0;
  //Print out result to Serial
  Serial.println(rpm);


  //Restart the interrupt processing
  attachInterrupt(0, rpm_fun, FALLING);
}

void rpm_fun()
{
  //Each rotation, this interrupt function is run twice, so take that into consideration for
  //calculating RPM
  //Update count
  rpmcount++;
}

4  Using Arduino / Project Guidance / Re: data logging/processing on: October 04, 2012, 05:38:32 pm
Thank you very much for all your advise so far, I am starting to build a picture of what is required. I feel that the conciseness is to not hold data and query it on board the Arduino but to push this to a file.

I am not interested in channel specific results, what I require is total "in"s or total "out"s diced up in specific time periods. To be honest I was hoping to get the Arduino to calculate a few results as rolling totals, but I assume the lack of room to store data makes this difficult on board, especially as there could be hundreds of data points per hour!
So assuming I have to collect and send this data to a file ,due to my lack of knowledge I am afraid I am still at a loss to how I may code this and to add to this I am not sure I could extract my totals given this formatted file!
Vectorges and others - maybe you could help with explaining the limitations of data analysis with Arduino and how to create and analyse data in a file. Thanks Simon
P.S. can I add an RTC easily along with the Ethernet/SD Shield?
5  Using Arduino / Project Guidance / Re: data logging/processing on: October 01, 2012, 07:39:37 am
Quote
Are you logging when the transaction occurs, too?
No, I have no RTC or Arduino based timing at present

Quote
Capturing and showing it where? The Arduino does not have a lot of memory, so it will not be able to hold much data.
Eventually I would like data presented via web, but for now (testing) through the Serial Monitor would be fine

Quote
You could add an SD card, to increase the amount of data you can store.
I have bought a W5100 based Ethernet/SD card shield for later development, maybe I could use the SD card to store data now.

Quote
Showing that data may or may not be trivial. Depends on where and when you want to show it.
As mentioned, eventually to share formatted results/database queries over the internet. (reference Pachube/Cosm) I am just starting and didn't want to take too bigger steps, get the animals to trigger inputs (done), add direction and count "in"s and "out"s (done), present the data against time intervals on serial monitor...don't know here to start!

Quote
What would trigger showing this data? Per channel or an aggregate?
Eventually live streaming to web, but for now a selection of formatted results. "in"s in the last hour, total "in"s today, that sort of thing.

Quote
Collect it where? Retrieve a file from where?
At the moment I would like to just print running totals to the serial monitor but next step would be to push it to a file for Excel, then ultimately to present via web a range of live streamed results.

Quote
I would simply stuff each animal entry/exit event into a MySQL database, using an ethernet shield. The server hosting the database could timestamp the entries.

Then, use the power of SQL to extract the data that you want - entries and exits in the last hour, the last 24 hours, the busiest channel, etc.

I have no idea about SQL databases or Ethernet shields yet. I think I am after a generalised explanation of how you capture, manipulate and show data such as I am collecting. As an example, how would I deal with working out the total "in"s in the last hour as a rolling total?
Sorry for not asking very specific questions, but I only know what I am trying to achieve and not the tools or techniques I should use.
Cheers Simon
6  Using Arduino / Project Guidance / data logging/processing on: September 30, 2012, 02:50:33 pm
Hello,

I am collecting movement data for some animals. I have several openings where I detect the animal pass, each opening uses two IR LED/photodiodes to detect direction. Currently I can successfully count each channel, running total for each channel and the overall movement in and out of the building. At the moment I am limited to 5 channels (10 inputs) but I will be adding further channels maybe up to 30, but that's another problem for later.

My question is about capturing and showing the data in different ways. I would like to show (at the moment on the serial monitor) the data against time intervals. By that I mean showing the data as Total animals "IN" (plus on count) in the last hour, in the last 24 hours, in which hour did maximum "OUT"s occur, that sort of thing.  I would like to also collect data against time and retrieve a file to plot a graph against time of "IN"s and "OUT"s but I can leave that for now.

I am very new to Arduino/coding/electronics and it has taken me a fairly long time just to write the code to count and detect direction.....fairly simple stuff for some I am sure....

I am after guidance on how this would normally be achieved, may be some code examples and if applicable pro's and cons for different ways to achieve my goals.  As always, thank you for spending time in helping me.
Regards Simon
7  Using Arduino / Programming Questions / Re: Counting "In" and "Out" on: July 13, 2012, 06:49:31 am
Hi,

I have finally got some spare time to make some more progress on the counter.  I have got the IR LED/Sensor to successfully count objects passing counting both up and down. This is the first piece of code so I am sure it is not very elegant or even the right way to achieve the goal, but it seems to work reliably.

My next task is to build a housing to test this in its proper environment.

In addition to this I would like to interrogate the data I collect for things like "objects out in the 'n' hours", peek 'in' objects per hour, graphs in Excel would be great. Can anyone give me some clues to where I should concentrate my learning?

Simon

Code:
/*

 Reads a digital input from IR LED on 2-3 and switches LED on 11-12
 
 This example code is in the public domain.
 */

// variables
// int testLed;
unsigned long aTime;
int a1Trigger = LOW;
int a2Trigger = LOW;
int ATriggerState = HIGH;
int ATriggerLast = HIGH;
int gateACount = 0;

// the setup routine runs once when you press reset:
void setup() {
  // set pins as input or outputs
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
 
  gateA();  // call gate1 routine
  // delay(20);
  // Serial.print("number of objects:  ");
  Serial.println(gateACount);
 // Serial.print("Time:  ");
//  Serial.println(aTime);
 // Serial.print("Varables:  ");
 // Serial.println(a1Trigger);
 // Serial.println(a2Trigger);
 // Serial.println(ATriggerState);
 // Serial.println(ATriggerLast);
}

void gateA() {
   a1Trigger = digitalRead(2); // read IR Sensor a1
   a2Trigger = digitalRead(3); // read IR Sensor a2
   
   if (a1Trigger == LOW && a2Trigger == LOW) {
     ATriggerState = LOW;
     aTime = millis();  // Start 'a' gate timer
     digitalWrite(11, LOW);
     digitalWrite(12, LOW);
  }
  else { ATriggerState = HIGH;
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
 }
 // delay (20);
 
 if (a1Trigger == HIGH && a2Trigger == LOW) {
   if (ATriggerLast != ATriggerState) {
   gateACount ++;
   digitalWrite(11, LOW);
  // delay(3);
  }
 }

 if (a2Trigger == HIGH && a1Trigger == LOW) {
   if (ATriggerLast != ATriggerState) {
    gateACount --;
    digitalWrite(12, LOW);
  // delay(3);
  }
 }
  ATriggerLast = ATriggerState;
//}
}
8  Using Arduino / Programming Questions / Re: Counting "In" and "Out" on: June 15, 2012, 04:28:49 am
What do you mean by "State code for this application"?

The pills are passing very slowly, I don't think the code below will work without some "time" conditioning.
I think I need to post this thread into "Project Guidance" or "Sensors" to get my theory straight first. Should I start a new thread in there?

void loop() {
  pillCount = pillOut - pillIn;
  // read the pushbutton input pin:
  gateFront1state = digitalRead(gateFront1);
  gateBack1state = digitalRead(gateBack1);

  // check for both sensors being triggered
  if (gateFront1 == HIGH && gateBack1 == HIGH) {
    trigger = true;
    timeChange = millis();
    digitalWrite(gate1Led, HIGH);
  }   
  else {
    // digitalWrite(gate1Led, LOW);
    trigger = false;
  }

  if (gateFront1 == LOW && trigger == true)
  {
    pillIn ++;
  }
  else if (gateBack1 == LOW && trigger == true)
  {
    pillOut ++;
  }
9  Using Arduino / Programming Questions / Re: Counting "In" and "Out" on: June 14, 2012, 05:08:21 pm
No the ends aren't rounded. If rounded, what impact would this have?
I said "unlikely" because if they are touching, a count of one rather than two would be acceptable based on the probability and the overall large count numbers, percentage wise well within tolerance. I want to make the two sensors being triggered together as the start then within say for 0.5sec look for a either of the sensors going low to confirm a count and its direction. Think this is a sound theory but struglling to code it....
10  Using Arduino / Programming Questions / Re: Counting "In" and "Out" on: June 14, 2012, 02:04:07 pm
PaulS ... Yes you are correct, that's my mistake should be trigger == true

Yes I do need to detect direction, the pills are actually short lengths of bar (10mm -12mm) that travel in both directions but not at high speed, probably maximum 0.5 to 1.0 sec to pass the sensors. Very unlikely to be two pills back to back.
Simon
11  Using Arduino / Programming Questions / Counting "In" and "Out" on: June 14, 2012, 12:02:51 pm
Hi,

This is my first program and first post so go easy on me! I am trying to count pills through a tube using two Photodiodes/IR LED. I am testing this program with two push buttons before I move to the true sensors. What will happen is pills will slide (gravity) down a tube past the pair of sensors, the sensors will be close enough together to be both covered with just 1 pill. I am not sure how fast the pills will past, probably some fast some slow but I think I can add timing/conditioning to the program later. At the moment I am trying just to get the theory right. The below does not compile because of the second IF conditions, where it looks for the direction indicator (sensor going LOW) Can someone help to confirm my theory and clues to how I would code this.
Later on I need to count maybe up to 30 tubes of passing pills, would be interested to hear schemes on how this would be possible....or not as the case maybe.

Thanks for any help
Simon

/*
 Reads a digital input on pin 2 and pin 3,
 determine direction and increment counter,
 print counter to the serial monitor
 
 Code copyright Simon Miller
 */

// Assign digital pins:
const int gateFront1 = 2;
const int gateBack1 = 3;
const int gate1Led = 13;

// Assign variables
int gateFront1state = 0;
int gateBack1state = 0;
int lastgateFront1 = 0;
int lastgateBack1 = 0;
boolean trigger = false;
unsigned long timeChange;
int pillOut = 0;
int pillIn = 0;
int pillCount = 0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(gateFront1, INPUT);
  pinMode(gateBack1, INPUT);
  pinMode(gate1Led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  pillCount = pillOut - pillIn;
  // read the pushbutton input pin:
  gateFront1state = digitalRead(gateFront1);
  gateBack1state = digitalRead(gateBack1);

  // check for both sensors being triggered
  if (gateFront1 == HIGH && gateBack1 == HIGH) {
    trigger = true;
    timeChange = millis();
    digitalWrite(gate1Led, HIGH);
    }   
    else {
    digitalWrite(gate1Led, LOW);
    trigger = false;
    }
   
  if (gateFront1 == LOW && trigger = true)
  {
    pillIn ++;
  }
  else (gateBack1 == LOW && trigger = true)
  {
    pillOut ++;
  }
   
      // print results to serial
     // Serial.print("number of pills in:  ");
     // Serial.println(pillIn);
     // Serial.print("number of pills out:  ");
    // Serial.println(pillOut);
     // Serial.print("delta pills:  ");
    //  Serial.println(pillCount);
  }
Pages: [1]