Adafruit Flow meter sketch

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Adafruit Flow meter sketch

Post by yinita2005 »

Hello,

This is my first project using Arduino. I'm trying to get to work the Flow meter (Liquid Flow Meter - Plastic 1/2" NPS Threaded) with the sketch that is posted in the website. But it doesn't work for me, i keep getting the following error :" sketch_jan21d.ino:31:7: error: expected constructor, destructor, or type conversion before '(' token " . I don't know if it is because im using an Intel BANNED Board, Do i need to use a different code to get it to work with this board? I'm not applying any changes to the code at all, i'm basically copy pasting. Maybe do I have to call different the timers? I don't really know what to do as i said i have no experience at all.

Thank you very much!

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Flow meter sketch

Post by adafruit_support_bill »

Please post the complete error text. Be sure to scroll to the top of the output window to get the first few lines.

Also post the complete text of the code you are using. Based on the error message posted, it sounds like it may not have been copied completely from the tutorial page.

User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Re: Adafruit Flow meter sketch

Post by yinita2005 »

thank you , this is the code that i used from your website:

Code: Select all

/**********************************************************
This is example code for using the Adafruit liquid flow meters. 
Tested and works great with the Adafruit plastic and brass meters
    ------> http://www.adafruit.com/products/828
    ------> http://www.adafruit.com/products/833
Connect the red wire to +5V, 
the black wire to common ground 
and the yellow sensor wire to pin #2
Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!
Written by Limor Fried/Ladyada  for Adafruit Industries.  
BSD license, check license.txt for more information
All text above must be included in any redistribution
**********************************************************/
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
  
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
  
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}

void setup() {
   Serial.begin(9600);
   Serial.print("Flow sensor test!");
   lcd.begin(16, 2);
   
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);
   useInterrupt(true);
}

void loop()                     // run over and over again
{ 
  lcd.setCursor(0, 0);
  lcd.print("Pulses:"); lcd.print(pulses, DEC);
  lcd.print(" Hz:");
  lcd.print(flowrate);
  //lcd.print(flowrate);
  Serial.print("Freq: "); Serial.println(flowrate);
  Serial.print("Pulses: "); Serial.println(pulses, DEC);
  
  // if a plastic sensor use the following calculation
  // Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
  // Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
  // Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
  // Liters = Pulses / (7.5 * 60)
  float liters = pulses;
  liters /= 7.5;
  liters /= 60.0;

/*
  // if a brass sensor use the following calculation
  float liters = pulses;
  liters /= 8.1;
  liters -= 6;
  liters /= 60.0;
*/
  Serial.print(liters); Serial.println(" Liters");
  lcd.setCursor(0, 1);
  lcd.print(liters); lcd.print(" Liters        ");
 
  delay(100);
}
And this is the complete text of the error that im getting when i try to compile:


C:\Users\yinita2005\Documents\arduino-1.5.3-Intel.1.0.4/hardware/tools/x86/i686-pokysdk-mingw32/usr/bin/i586-poky-linux-uclibc/i586-poky-linux-uclibc-g++ -m32 -march=i586 --sysroot=C:\Users\yinita2005\Documents\arduino-1.5.3-Intel.1.0.4/hardware/tools/x86/i586-poky-linux-uclibc -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -D__ARDUINO_X86__ -Xassembler -mquark-strip-lock=yes -march=i586 -m32 -DARDUINO=153 -IC:\Users\yinita2005\Documents\arduino-1.5.3-Intel.1.0.4\hardware\arduino\x86\cores\arduino -IC:\Users\yinita2005\Documents\arduino-1.5.3-Intel.1.0.4\hardware\arduino\x86\variants\BANNED_fab_g -IC:\Users\yinita2005\Documents\arduino-1.5.3-Intel.1.0.4\libraries\LiquidCrystal\src C:\Users\YINITA~1\AppData\Local\Temp\build8123359864603119556.tmp\sketch_jan21d.cpp -o C:\Users\YINITA~1\AppData\Local\Temp\build8123359864603119556.tmp\sketch_jan21d.cpp.o

sketch_jan21d.ino:31:7: error: expected constructor, destructor, or type conversion before '(' token
enabled in File > Preferences.

Thank you!
Last edited by adafruit_support_bill on Thu Jan 22, 2015 1:26 pm, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Flow meter sketch

Post by adafruit_support_bill »

I'm downloading version 1.5.3 now to try to reproduce the problem. The server is quite slow at the moment, so I'm not sure how long that will take.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Flow meter sketch

Post by adafruit_support_bill »

OK. I am able to reproduce that here. It appears that the problem is with the command for setting up an interrupt handler for the timer interrupt:

Code: Select all

SIGNAL(TIMER0_COMPA_vect)
Timers and interrupts are very processor specific and the Intel BANNED has a completely different processor architecture from the UNO, and other Atmel-based Arduinos.

The Intel BANNED forum would be the best place to get advice on how to modify this sketch for use with the Intel processor: https://communities.intel.com/community ... ms/content

User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Re: Adafruit Flow meter sketch

Post by yinita2005 »

ok. I will check it out.

Thank you

User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Re: Adafruit Flow meter sketch

Post by yinita2005 »

Hello !

Could you please explain me what is this portion of the code doing??

void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}

Thank you,

User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Re: Adafruit Flow meter sketch

Post by yinita2005 »

Hello!

So i modified the code using the library TimerObject and it seems to be working, but im not sure !! I'm not interrupting the timer at all so i'm guessing that's wrong. But anyways im getting a flow rate but i think its not correct. This is my code if could explain me where do i need to interrupt the timer and under what condictions that would help me a lot. Please take a look to my code and if you have a BANNED Board you could run it and let me know what you think.

Code: Select all

#include "TimerObject.h"

TimerObject *timer1 = new TimerObject(1);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
void rpm() {
  uint8_t x = digitalRead(FLOWSENSORPIN);
  
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
  
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}
/*
void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}*/

void setup() {
  
   Serial.begin(9600);
   Serial.print("Flow sensor test!");
   timer1->setOnTimer(&rpm);
   timer1->Start();
   
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);

}

void loop()                     // run over and over again
{ 
  
  Serial.print("Freq: "); 
  Serial.println(flowrate);
  Serial.print("Pulses: ");
  Serial.println(pulses, DEC);

  float liters = pulses;
  liters /= 7.5;
  liters /= 60.0;

  Serial.print(liters); 
  Serial.println(" Liters");
  timer1->Update();
 
  delay(100);
}
Last edited by adafruit_support_bill on Fri Jan 23, 2015 9:29 pm, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Flow meter sketch

Post by adafruit_support_bill »

Could you please explain me what is this portion of the code doing??
That code is setting up the timer interrupts. It is processor specific to the Atmega-328. It will not work with any other processor.

We do not have any BANNED experts in-house. The Intel BANNED forum is the best place to get advice on advanced topics such as interrupts for this processor.

User avatar
yinita2005
 
Posts: 6
Joined: Wed Jan 21, 2015 7:13 pm

Re: Adafruit Flow meter sketch

Post by yinita2005 »

Hello,

I think is working. Just a quick question, when i get my result in "liters" is it liter/sec ?

Thank you,

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”