Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: April 04, 2014, 12:23:24 pm
Thank you so much i can't wait to try it out this weekend im sure it will work great. I appreciate the time you put into writing the code to help me understand the concept! This community is great on the amount of effort people give to help other people learn! I appreciate all the help and will let you know if there are any other questions, thanks again!
2  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: April 02, 2014, 01:50:40 pm
Ok my only question is how would you actually code it to work with the flow meter? Can you help me with an example to measure out the flow with the flow meter using the micros() function?
3  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: March 30, 2014, 08:17:18 pm
Thank you for elaborating on it now i believe i understand the concept, you would be measuring the frequency of the flow meter in relation to 75 HZ. I have been looking at the blink without delay example and I'm trying to figure out how you would implement it using micros() function i understand that we want to measure between the rising edge of the clock cycles, and on interrupts we would use the RISING keyword i don't quite get how we would code it to do that just by using the micros function. 
4  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: March 30, 2014, 01:48:39 pm
That sounds like a very interesting way of taking measurements, So with that method i could take readings on any of the available pins? i still dont know how i would measure flow with that, From what i understand is that i would be reading the clock cycles from the flow meter to see how much water is flowing through but that is from what i understand. How would i implement that in my code is the bigger question?
5  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: March 29, 2014, 04:38:59 pm
I have it wired up exactly as i have it posted in the diagram and used the shortened code and there is no interrupts coming through. On the serial monitor it is just reading 0's. I even tried it with another PCF8574. Do i have the right chip to be doing this i am using a PCF8574AP i noticed on the datasheet (http://www.taydaelectronics.com/datasheets/A-905.pdf) there is a PCF8574P could that be my problem? and dlloyd the measurement of these would need to be somewhat precise but do you know a way to monitor the flow without using interrupts? I would like to get this chip figured out but if there is another way i would be glad to hear about it.
6  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: March 29, 2014, 12:05:48 am
I have been trying to work with the PCF8574 and have found that i i only need to hook up pin 2 (on the arduino) to pin 13 (on the PCF8574) i also found that i needed to add pin 2 as a input, but i still am getting no reading from the interrupt pin. I have been working on this and cant seem to get anywhere, any help would be appreciated. I will post the code and the way i hooked up the flow meter to the PCF8574.
Code:
//    FILE: PCF8574_int.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE:
//    DATE: 14-12-2013
//     URL:
//
// Released to the public domain

#include "PCF8574.h"
#include <Wire.h>

PCF8574 PCF_38(0x38);


unsigned long  lastTime = 0;
volatile unsigned long count[8];
int hallsensor = 2;

void setup()
{
  Serial.begin(115200);
  Serial.println("\nTEST PCF8574 Interrupt\n");
  pinMode(hallsensor, INPUT);
  attachInterrupt(0, catchChange, RISING);
}

void loop()
{
  // once per second
  if (millis() - lastTime >= 1000)
  {
    lastTime += 1000;
    for (uint8_t i=0; i< 8; i++)
    {
      Serial.print(',');
      Serial.print(count[i]);
    }
    Serial.println();
   }
}

void catchChange()
{
  static uint8_t last = 0xFF;
  uint8_t tmp = TWBR;
  TWBR = 2; // speed up I2C;
  uint8_t value = PCF_38.read8();
  TWBR = tmp;
 
  uint8_t v = (last ^ value) & value; // which pins are changed since last time from LOW to HIGH
  last = value;

  uint8_t mask = 0x01;
  for (uint8_t i=0; i< 8; i++)
  {
    if (v & mask) count[i]++;
    mask <<= 1;
  }
}
7  Using Arduino / Programming Questions / Re: While loop and Do/while loop trouble on: January 05, 2014, 02:25:10 pm
Maybe this approach is not the best way for the way i want to use it, but i used the write up on flow meters on this page(http://forum.arduino.cc/index.php/topic,8548.0.html) and I used that exact code and it has worked great up to this point where I am trying to switch a led off when it counts so many liters have passed. I cant use the main loop to count the pulses so it has to be in a separate function but it seems when i put it in a different functions it doesn't go back to the main loop at all. I dont know another approach where i could count the pulses and compare them in a while loop in a separate function such as lightCheck(). If you know of another approach i would be grateful if you could demonstrate so i could learn.
Thank you
8  Using Arduino / Programming Questions / Re: While loop and Do/while loop trouble on: January 05, 2014, 01:53:38 pm
Thank you for the fast replies and using the Serial.available > 0 was a fix for not having to use the delay (i just had it in there so it printed "Test" every two seconds while in the main loop.) But changing that did not fix the problem it still turned on the redLed and when the counter got above the limit it changed check to false and turned off the redLed then it turned on the greenLed and when that was above the limit it changed next to false and turned off the greenLed but then it is like the code is hanging there it doesn't continue back to the main loop it just sits there idling and doesn't do anything after that.
9  Using Arduino / Programming Questions / While loop and Do/while loop trouble on: January 05, 2014, 12:49:09 pm
Hello i am working on a project containing flow meters and used this article (http://forum.arduino.cc/index.php/topic,8548.0.html)
to read the flow rate and then i just added a counter to see how much has flowed through, I am trying to connect a solenoid to the same line as a counter and have the solenoid open and when a certain amount of liters flow through the flow meter i want the solenoid to shut off. I have the semi working code here
Code:
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal
float Calc;                             
int hallsensor = 2;    //The pin location of the sensor
float Total = 0;
float totalTwo = 0;
int redLed = 7;
int greenLed = 8;
boolean check = true;
boolean next = true;

void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
}
// The setup() method runs once, when the sketch starts
void setup() //
{
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  digitalWrite(hallsensor, HIGH);
  Serial.begin(9600); //This is the setup function where the serial port is
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()   
{
  int key = Serial.read();
  Serial.print("Test");
  delay(2000);
  if(key == 'G'){
    lightCheck();
  }
  if(key == 'H'){
    nextBlock();
  }
}


void lightCheck(){
  while(check){
    digitalWrite(redLed, HIGH);
    NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
    sei();            //Enables interrupts
    delay (1000);      //Wait 1 second
    cli();            //Disable interrupts
    Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
    Total += Calc;
    Serial.print (Calc, DEC); //Prints the number calculated above
    Serial.print (" Liters/Hour\r\n"); //Prints "L/hour" and returns a  new line
    Serial.print (Total, DEC);
    Serial.print ( "Total Liters\r\n");
    if(Total >= 100){
      check = false;
      digitalWrite(redLed, LOW);
    }
  }
  do{
    digitalWrite(greenLed, HIGH);
    NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
    sei();            //Enables interrupts
    delay (1000);      //Wait 1 second
    cli();            //Disable interrupts
    Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
    totalTwo += Calc;
    Serial.print (Calc, DEC); //Prints the number calculated above
    Serial.print (" Liters/Hour\r\n"); //Prints "L/hour" and returns a  new line
    Serial.print (totalTwo, DEC);
    Serial.print ( "Total Liters\r\n");
    if(totalTwo >= 200){
      next = false;
      digitalWrite(greenLed, LOW);
    }
  }
  while(next);

  nextBlock();

}

void nextBlock(){
  Serial.print("Hello");
}
The only problem i am having is it is not going to the nextBlock() part of the code and back to void loop. as soon as the boolean next becomes false it turns off greenLed but it does not continue to nextBlock() and back to void loop. My question is why i thought as soon as the while loop became false it went to the next part of code, i also tried using just a while loop instead of a do/while loop and still the same outcome, i also used a break; statement instead of declaring next and check false that also yielded the same result. For some reason after the while statements become false it wont go onto the next piece of code calling nextBlock() and eventually going back to loop(); What am i doing wrong?
10  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: December 15, 2013, 11:53:35 am
I tested it on the pins you said dc42 and  PinChangeInt did work on the pins you specified and that will be a good way for the flow meters I have now, however i already ordered some PCF8574 and they are shipped, Thanks to robtillaart I now have a better understanding on how to hook up the chip to the arduino board. I hook  pin 13 on the PCF8574 on pin 2 and 3 of the arduino, then i hook the flow meters to pin p0-p7 while grounding the other pins i don't use. The code is the only thing i am having a hard time to understand. The code that i was using was
Code:
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal
float Calc;                             
int hallsensor = 2;    //The pin location of the sensor
float Total = 0;


void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
}
// The setup() method runs once, when the sketch starts
void setup() //
{
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  digitalWrite(hallsensor, HIGH);
  Serial.begin(9600); //This is the setup function where the serial port is
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()   
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = ((NbTopsFan * 60 / 7.5) / 60); //(Pulse frequency x 60) / 7.5Q, = flow rate
  Total += Calc;
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" Ounces/Liters\r\n"); //Prints "L/hour" and returns a  new line
  Serial.print (Total, DEC);
  Serial.print ( "Total Liters\r\n");
}
I know that works with the arduino now i was curious how i could get the same effect with the PCF8574 and the example code provided
Code:
//    FILE: PCF8574_int.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE:
//    DATE: 14-12-2013
//     URL:
//
// Released to the public domain

#include "PCF8574.h"
#include <Wire.h>

PCF8574 PCF_38(0x38);


unsigned long  lastTime = 0;
volatile unsigned long count[8];

void setup()
{
  Serial.begin(115200);
  Serial.println("\nTEST PCF8574 Interrupt\n");

  attachInterrupt(0, catchChange, CHANGE);
}

void loop()
{
  // once per second
  if (millis() - lastTime >= 1000)
  {
    lastTime += 1000;
    for (uint8_t i=0; i< 8; i++)
    {
      Serial.print(',');
      Serial.print(count[i]);
    }
    Serial.println();
   }
}

void catchChange()
{
  static uint8_t last = 0xFF;
  uint8_t tmp = TWBR;
  TWBR = 2; // speed up I2C;
  uint8_t value = PCF_38.read8();
  TWBR = tmp;
 
  uint8_t v = (last ^ value) & value; // which pins are changed since last time from LOW to HIGH
  last = value;

  uint8_t mask = 0x01;
  for (uint8_t i=0; i< 8; i++)
  {
    if (v & mask) count[i]++;
    mask <<= 1;
  }
}
I know now i can have more that 6 interrupts on the Mega and it may seem like a strange thing to try and use the PCF8574 but i would like to use and learn how to use these wonderful chips as i may use them in the future and others may as well.
I appreciate all the help so far and helping me work out my problem, and I will be grateful of any further help.
11  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: December 14, 2013, 08:51:56 pm
Thank you for further investigation that the library doesn't work with Mega. I plan on working with the PCF8574 chip but now my question remains How would the wiring diagram look for the flowmeter to the PCF8574? So would I hook  pin 13 on the PCF8574 (datasheet http://www.taydaelectronics.com/datasheets/A-905.pdf)  on pin 2 and 3 on the arduino? Also where would i hook up the two flow meters on the PCF8574? on pin 1-7 and 9-12? Also from the demo code provided earlier
Code:
//    FILE: PCF8574_int.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE:
//    DATE: 14-12-2013
//     URL:
//
// Released to the public domain

#include "PCF8574.h"
#include <Wire.h>

PCF8574 PCF_38(0x38);


unsigned long  lastTime = 0;
volatile unsigned long count[8];

void setup()
{
  Serial.begin(115200);
  Serial.println("\nTEST PCF8574 Interrupt\n");

  attachInterrupt(0, catchChange, CHANGE);
}

void loop()
{
  // once per second
  if (millis() - lastTime >= 1000)
  {
    lastTime += 1000;
    for (uint8_t i=0; i< 8; i++)
    {
      Serial.print(',');
      Serial.print(count[i]);
    }
    Serial.println();
   }
}

void catchChange()
{
  static uint8_t last = 0xFF;
  uint8_t tmp = TWBR;
  TWBR = 2; // speed up I2C;
  uint8_t value = PCF_38.read8();
  TWBR = tmp;
 
  uint8_t v = (last ^ value) & value; // which pins are changed since last time from LOW to HIGH
  last = value;

  uint8_t mask = 0x01;
  for (uint8_t i=0; i< 8; i++)
  {
    if (v & mask) count[i]++;
    mask <<= 1;
  }
}
how would i differentiate between and store the amount of flow (liters per hour) in two different variables so i can use them later in the code ( from each water flow meter). I really appreciate the help with this i have never worked with a 8 bit I/O expander before and am thankful for all the help.
12  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: December 14, 2013, 04:06:54 pm
Hello thanks for the write up dc42. From what i understood i could only measure the RPM of the hall effect sensor with a external interrupt. I have no problem sparing pins as i am using the mega and have plenty not in use, But the Mega only has 6 external interrupts and i would like to use more than that. I tried using PinChangeInt libary (http://playground.arduino.cc/Main/PinChangeInt) but i dont think it is compatible with the mega as i used the example code
Code:
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
 
#define PIN 15  // the pin we are interested in
volatile byte burp=0;    // a counter to see how many times the pin has changed
byte cmd=0;     // a place to put our serial data
 
void setup() {
  Serial.begin(9600);
  Serial.print("PinChangeInt test on pin ");
  Serial.print(PIN);
  Serial.println();
  pinMode(PIN, INPUT);     //set the pin to input
  digitalWrite(PIN, HIGH); //use the internal pullup resistor
  PCintPort::attachInterrupt(PIN, burpcount,RISING); // attach a PinChange Interrupt to our pin on the rising edge
// (RISING, FALLING and CHANGE all work with this library)
// and execute the function burpcount when that pin changes
  }
 
void loop() {
  cmd=Serial.read(); 
  if (cmd=='p')
  {
    Serial.print("burpcount:\t");
    Serial.println(burp, DEC);
  }
  cmd=0;
}
 
void burpcount()
{
  burp++;
}
and it did not work with the mega. Maybe what you are mentioning is a different method? Any help would be much appreciated, I have many spare pins that can be used i just thought they needed to be the external interrupt pins specified by arduino.
Thank you for your time and help.
13  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: December 14, 2013, 12:14:32 pm
Hello thank you for the excellent idea i plan on using it i just need to verify some items as i am a little confused on how the wiring diagram works. I was looking at the data sheet ( http://www.taydaelectronics.com/datasheets/A-905.pdf)
Quote
you can connect its INT pin to the Arduino IRQ pin 2 and 3 giving you 16 IO lines monitored for pulses
So i hook pin 13 on the PCF8574 on pin 2 and 3 on the arduino? Also i have two flow meters right now where would i hook them up on the PCF8574? on pin 1-7 and 9-12?
Also thank you for the demo code but how would i differentiate between and store the amount of flow (liters per hour) in two different variables so i can use them later in the code ( from each water flow meter). Thank you so much for your help and i appreciate the time you take to help.
14  Using Arduino / Project Guidance / Re: Two Flow meters on one interrupt pin on: December 13, 2013, 10:57:11 pm
First i want to thank you all for the fast replies. I plan on using this in a project in where i use 6+ flow meters on one arduino board, so i want to use 2+ on each interrupt pin but i first want to get it working with just two before i even start adding more to the board. I know the Arduino uno only has two interrupt pins(I know the Mega has six but i plan on using more than six if possible) and this is a hall effect flow sensor, which from my understanding could only count RPM's with the interrupt. I was testing this earlier and had the two flow meter signal wires connected to the interrupt pin and i would test each flow meters at seperate times, giving adequate time inbetween tests to make sure the interrupt has finished then i would try it on the other one. Sometimes they would both work the way I imagined it would work, but just when i thought it would work perfect they would stop working like there was a short and it wasn't reading anything from the flow meter, 2 minutes later everything would work fine. So i know this method works but i must be missing something. Any ideas?
Thanks again.
15  Using Arduino / Project Guidance / Two Flow meters on one interrupt pin on: December 13, 2013, 09:10:06 pm
Hello i am trying to use more than one flow meter on one interrupt pin. I have followed the write up (http://forum.arduino.cc/index.php/topic,8548.0.html) and successfully got both flow meter working to count liters per hour separately. I was wondering how i could configure it to count two flow meters on the same interrupt pin. (only one flow meter will be working at one time). I tried hooking the flow meters up in parallel and it works, but sometimes it doesn't. It is very sporadic on reading the meters, sometimes it works and sometimes it doesn't which i dont understand, from my understanding the meters send 5v on the signal line and the arduino counts in and displays it in the serial monitor. When it is in parallel it works but there are times when it seems like the meter isnt sending out a signal, until I unhook the other meter and it works perfect again. My question is why does it work sometimes and randomly not work?
Thank you in advance for your time.
(I'll attach the code i used below)
Code:
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the

hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup() //
{
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is

initialised,
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()   
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate

in L/hour
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
}
Pages: [1] 2