input processing... yeah again :-D

so i got logging my water meter working... 2 pulses each liter so i multiply by 0.5 to get the liter figure... easy enough..

 

to get the flow rate i use rate of change .. also easy enough....but

 

now i want a graph that tells me the usage between each reading.... what should i use? pulse difference?????

boelle's picture

Re: input processing... yeah again :-D

so i tried to have the emon tx send the used water since start 3 times as 3 different streams as to make it more logical for myself

 

battery and total water was fine but

even the simple rate of change on the 3rd stream did only count up.. it did not go back to zero as i closed the tap

boelle's picture

Re: input processing... yeah again :-D

power to kwh gives a number... but i assume thats an average...

 

going to pull my hair soon... why is there not a simple way to see liters each hour or min or sec?

boelle's picture

Re: input processing... yeah again :-D

got rate of change to rise and drop... now i only need it to match real world.... got it to swing between 0.5 and 1 at full open tab

 

 

boelle's picture

Re: input processing... yeah again :-D

at a flow of 2 litres per min it barely jumps to 0.5 when i use rate of change

 

what can i do to make it match?

boelle's picture

Re: input processing... yeah again :-D

so a bit more working and at same flow with the puls demo sketch i get a number of -10401.00

 

as long i keep the tap open it is fairly stable... once i close the tab it stays at last updated value

 

what i'm doing wrong? it should go to zero once i close and at 2 litres a min it should be 120 litres an hour...

boelle's picture

Re: input processing... yeah again :-D

so if i divide by 50 i get the right litre an hour figure..... but i would like for it to go zero once there are no more incomming impulses....

 

sketch so far:

 

#define freq RF12_868MHZ                                                // Frequency
const int nodeID = 2;                                                  // emonTx  node ID
const int networkGroup = 210;                                           // emonTx  network group
const int time_between_readings= 5000;

#include <JeeLib.h>                                                    
#include <avr/sleep.h>

ISR(WDT_vect) { Sleepy::watchdogEvent(); }                              // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption

long pulse = 0;
unsigned long pulseTime,lastTime;
double flow;
int ppl = 2;

typedef struct {int pulse; int flow; int battery; } Payload;
Payload emontx;

void setup() {
  Serial.begin(9600);
 
  // pulse detection interrupt (emontx pulse channel - IRQ0 D3)
  attachInterrupt(1, onPulse, FALLING);
 
  rf12_initialize(nodeID, freq, networkGroup);                          // initialize RFM12B
  rf12_sleep(RF12_SLEEP);

}

void loop()
{
  emontx.pulse=pulse;
  emontx.flow=flow;
  emontx.battery=readVcc();
  rf12_sleep(RF12_WAKEUP);
  // if ready to send + exit loop if it gets stuck as it seems too
  int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
  rf12_sendStart(0, &emontx, sizeof emontx);
  // set the sync mode to 2 if the fuses are still the Arduino default
  // mode 3 (full powerdown) can only be used with 258 CK startup fuses
  rf12_sendWait(2);
  rf12_sleep(RF12_SLEEP); 
  Sleepy::loseSomeTime(time_between_readings);
 
}

long readVcc() {
  long result;
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2);
  ADCSRA |= _BV(ADSC);
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result;
  return result;
}

// The interrupt routine - runs each time a falling edge of a pulse is detected
 void onPulse()
 {
   lastTime = pulseTime;
  pulseTime = micros();
   pulse = pulse + 1; // count pulse
flow = int((3600000000.0 / (pulseTime - lastTime))/50);
 }

boelle's picture

Re: input processing... yeah again :-D

*bump*

 

what am i doing wrong here? i can only get the emontx to report pulses since start.. that i can get emoncms to multiply by 0.5 to get liters....

 

but how do i get liters per hour? ie 2 liters a min should be 120 an hour... and how do i get emoncms to store the difference between readings and not the total reported by emontx?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.