Hi,
excuse my bad English tongue. try to take.
Problem is... I'm trying to get a four-pulse flow meter data arduino mega.
( http://www.conrad.com/ce/en/product/150391/BIO-TECH-eK-FCH-M-POM-LC-G-18-Flow-Meter-FCH-m-POM-LC-001-35-Lmin?ref=searchDetail )
But the pulses are copied to the cross and in the wrong sensors. When E1 is the flow. E2 sensors will also receive pulses even if they do not have the flow. if turn off power the E2 sensors. then the E2 pulses disappear from the sensors. The same in reverse. Where could be the problem?
Can I get a four-sensor pulses at the same time, in the right places? or whether only two sensors at a time
I hope this may be something obvious, thanks
#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // 9 to lcd4 // 8 to lcd 6 // 7 to lcd 11 // 6 to lcd 12 // 5 to lcd13 // 4 to lcd 14
//E1
#define IRQ_A 5
#define IRQ_B 4
#define FlowA 18
#define FlowB 19
//E2
#define E2IRQ_A 1
#define E2IRQ_B 0
#define E2FlowA 3
#define E2FlowB 2
unsigned long oldTime = 0;
volatile byte pulseCountIN;
volatile byte pulseCountOUT;
volatile byte pulseCountIN2;
volatile byte pulseCountOUT2;
void setup()
{
Serial.begin(57600);
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("4 PULSE");
delay(5000);
lcd.clear();
pulseCountIN = 0; //E1 IN
pulseCountOUT = 0; //E1 OUT
pulseCountIN2 = 0; //E2 IN
pulseCountOUT2 = 0; //E2 OUT
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(12, HIGH); // POWER E1 Sensor
digitalWrite(13, HIGH); // POWER E2 sensor
pinMode(FlowA, INPUT);
pinMode(FlowB, INPUT);
digitalWrite(FlowA, HIGH);
digitalWrite(FlowB, HIGH);
pinMode(E2FlowA, INPUT);
pinMode(E2FlowB, INPUT);
digitalWrite(E2FlowA, HIGH);
digitalWrite(E2FlowB, HIGH);
attachInterrupt(IRQ_A, CounterIN, FALLING);
attachInterrupt(IRQ_B, CounterOUT, FALLING);
attachInterrupt(E2IRQ_A, E2CounterIN, FALLING);
attachInterrupt(E2IRQ_B, E2CounterOUT, FALLING);
}
void loop()
{
unsigned long now = millis();
if((now - oldTime > 1000))
{
unsigned long duration = now - oldTime;
oldTime = now;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("E1:");
lcd.setCursor(0,1);
lcd.print("IN: ");
lcd.print(pulseCountIN, DEC); //virtaus meno
lcd.setCursor(0,2);
lcd.print("OUT: ");
lcd.print(pulseCountOUT, DEC); //virtaus lapuu
lcd.setCursor(10,0);
lcd.print("E2:");
lcd.setCursor(10,1);
lcd.print("IN2: ");
lcd.print(pulseCountIN2, DEC);
lcd.setCursor(10,2);
lcd.print("OUT2: ");
lcd.print(pulseCountOUT2, DEC);
pulseCountIN = 0;
pulseCountOUT = 0;
pulseCountIN2 = 0;
pulseCountOUT2 = 0;
}
}
//E1 IN
void CounterIN()
{
pulseCountIN++;
}
//É1 OUT
void CounterOUT()
{
pulseCountOUT++;
}
//E2 IN
void E2CounterIN()
{
pulseCountIN2++;
}
//E2 OUT
void E2CounterOUT()
{
pulseCountOUT2++;
}