Flow Meter help with reading data

Hi, is there a way to run the cayenne sketch on my arduino uno and at the same time run a sketch that will read the data from the flow sensor and make the calculations so that I’ll be able see the data on the cayenne app?

1 Like

Hi
Using Arduino can add any sensor on the Cayenne Dashboard.
What connection is used (Ethernet, Serial, …)?
Do you have any sample code with output to Serial monitor?

1 Like

Yes you can use the virtual pins

2 Likes

Hi, I’m using an ethernet shield.
Found that code: http://diyhacking.com/projects/FlowMeterDIY.ino for the flow meter reading and calculation but I have no idea how to combine the 2 sketches - the one above with the cayenne so that I’ll be able to read the data ovet the cayenne app.

Try this.

Sensor.txt (4.4 KB)

1 Like

My friend, you’re a Genius!!!
How did you manage to change the wording to “float”?

Try clicking the settings icon (top right of widget) and changing the unit type with the widget settings.

-B

1 Like

Hello, I tried using this exact same code, I am able to see the output in the serial monitor but not on cayenne. I have connected it to the right token code, as I can see my device going online, but not able to get the values to display. Can you please help? Thank you in advance
I am attaching the chart data, and the screenshot of my channel and also the serial monitor

.

History_d070e7f0-f819-11e6-9d6c-3bf242c224a2_dfaf3b484a251830f301818a136c58881c97eb5c_minute_2017-02-23-10-41-00_2017-02-23 11-41-00.csv (6.6 KB)

What is the connection to the Cayenne using (Serial. Ethernet Shield, …)?

It is a USB connection, serial to usb and included the corresponding header file. I am also attaching the code I have used. Thank you for your prompt reply :slight_smile:

Flowmeter to cayenne good sketch.txt (4.6 KB)

Try comment on all Serial.print and Serial.println.

// Print the flow rate for this second in litres / minute
    //Serial.print("Flow rate: ");
    //Serial.print(int(flowRate));  // Print the integer part of the variable
    //Serial.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    //Serial.print(frac, DEC) ;      // Print the fractional part of the variable
    //Serial.print("L/min");
    // Print the number of litres flowed in this second
    //Serial.print("  Current Liquid Flowing: ");             // Output separator
    //Serial.print(flowMilliLitres);
    //Serial.print("mL/Sec");

    // Print the cumulative total of litres flowed since starting
    //Serial.print("  Output Liquid Quantity: ");             // Output separator
    //Serial.print(totalMilliLitres);
    //Serial.println("mL");
1 Like

Okay I will try it right away…Thank You

Hello, It now works, Thank you tons. I have been struggling the whole day to get this working.

But just one virtual pin V0 works. The other two are not displaying any value. I am attaching the new program with serial output commented. Please let me know what could be done ?

Commented the serial output flow sensor cayenne.txt (4.6 KB)

Additionally, I wanted to print a graph out. But when I am selecting graph in the custom widget, it is not showing any data, can you please help with this as well? Thank you in advance.:slight_smile:

Is this a graph only problem? Do you see any live data if you switch back to widget view?

Yes, I do see live data when I switch back to the widget view. Also, additionally, I can see data only for one virtual pin (only widget view), and not for others (nor widget, nor graph).

Thank you for your assistance in advance.

Hello, did you connect the two flow meters?

@pal.shruti30 @adam @tad.dvor We recently pushed some changes for the graph widget. You may have been experiencing a bug when the data would not show. If you could try again and let us know if issue persists. Thanks!

Special thanks to @tad.dvor for helping out here!

-B

2 Likes

Hello Everybody,
I use this code to measure flow rate. However, the widget is just standing at the last measured value. Any suggestions?

/*
Cayenne Serial USB Example
This sketch connects to the Cayenne server using an Arduino Serial USB connection
and runs the main communication loop.
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.
This requires the use of the Serial USB connection so you cannot use the Serial device for
printing messages. If you need to print you can use SoftwareSerial and connect another device
to read messages via the SoftwareSerial pins.
In order for this to work you must run the connection script on the machine the Arduino is connected to.
The scripts are located under the extras\scripts folder in the main library folder. This redirects the traffic
from the Arduino to the Cayenne server.
Steps:
1. Set the token variable to match the Arduino token from the Dashboard.
2. Compile and upload this sketch.
3. Launch the connection script as described below for Windows or Linux/OSX.
Windows:
  1. Open the Windows command line (cmd.exe)
  2. Navigate to the scripts folder by typing "cd [path]", e.g.  "cd C:\Users\[YourUserName]\Documents\Arduino\libraries\Cayenne\extras\scripts"
  3. Run the script by typing "cayenne-ser.bat -c COM4" (where COM4 is port with your Arduino) and hitting Enter
Linux and OSX:
    ./cayenne-ser.sh (may need to run with sudo)
    
You can specify port, baud rate, and server endpoint like this:
    ./cayenne-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>
    For instance :
      ./cayenne-ser.sh -c /dev/ttyACM0 -b 9600 -s arduino.mydevices.com -p 8442
    Run cayenne-ser.sh -h for more information
    Be sure to select the right serial port (there may be multiple).
ATTENTION!
  Do not use Serial to display any output in this sketch. It will interfere with the Serial
  USB connection. When uploading sketches the Arduino IDE may complain with "programmer is
  not responding" or "Access is denied." You will need to terminate the connection script
  before uploading new sketches since it blocks access to the Serial port. Also make sure 
  the Serial Monitor is disabled in the IDE since that can prevent the Arduino from 
  connecting to the Windows/Linux/OSX machine. If you use Visual Micro for Visual Studio make
  sure Automatic Debugging is disabled. Otherwise the Serial Monitor can interfere with the
  Serial connection.
*/

#include <CayenneSerial.h>

#include <OpenGarden.h>
#include <Wire.h>

#define VIRTUAL_LUM V5
#define VIRTUAL_IRR V6
#define VIRTUAL_TEMP V7

#define VIRTUAL_BAT V1
#define VIRTUAL_NODE_TEMP V2
#define VIRTUAL_NODE_HUM V3
#define VIRTUAL_NODE_LUM V4
#define VIRTUAL_LITERS V8
/////////
#define FLOWSENSORPIN 11

// 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);
  }
}






//////////////////
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "8vaedkt5m6";

void setup()
{
  //Baud rate can be specified by calling Cayenne.begin(token, 9600);
  Cayenne.begin(token);
  OpenGarden.initSensors();    //Initialize sensors power 
  OpenGarden.sensorPowerON();  //Turns on the sensor power supply
  OpenGarden.initIrrigation(1); //Initialize irrigation number 1 
  OpenGarden.irrigationOFF(1);
  delay(1000);
  OpenGarden.initRF();
  OpenGarden.initRTC();
  
  
  ////////////////
  

   
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);
   useInterrupt(true);

}

void loop()
{
  
  Cayenne.run();
 
}
CAYENNE_OUT(VIRTUAL_LITERS)
{
  float liters = pulses;
  liters /= 7.5;
  liters /= 60.0;
  
  Cayenne.virtualWrite(VIRTUAL_LITERS, liters);
  delay(1000);
}

CAYENNE_OUT(VIRTUAL_TEMP)
{
  float soilTemperature0 = OpenGarden.readSoilTemperature();
  
  //Serial.print(soilTemperature0);
  Cayenne.virtualWrite(VIRTUAL_TEMP, soilTemperature0);
}

CAYENNE_OUT(VIRTUAL_LUM)
{
  int luminosity0 = OpenGarden.readLuminosity();
  
  //Serial.print(soilTemperature0);
  Cayenne.virtualWrite(VIRTUAL_LUM, luminosity0);
}

CAYENNE_IN(VIRTUAL_IRR)
{
 
  // read the integer value which should be 0 or 1
  int enabled = getValue.asInt();
  if (enabled == 1) {
    // turns on the motor at the specified speed
    OpenGarden.irrigationON(1);
  } else {
    // turn motor off
    OpenGarden.irrigationOFF(1);
  }
}

CAYENNE_OUT(VIRTUAL_BAT)
{
 OpenGarden.receiveFromNode(); //Receive data from node
  delay(1000); 
  Payload node1Packet = OpenGarden.getNodeData(node1);
  
  float battery1 = node1Packet.supplyV;
  float battery2 = (battery1 / 1000);
  //Serial.print(battery1);
  Cayenne.virtualWrite(VIRTUAL_BAT, battery2);
  OpenGarden.receiveFromNode(); //Receive data from node
}

CAYENNE_OUT(VIRTUAL_NODE_TEMP)
{
 OpenGarden.receiveFromNode(); //Receive data from node
  delay(1000); 
  Payload node1Packet = OpenGarden.getNodeData(node1);
  
  float airTemperature1 = node1Packet.temperature;
  //Serial.print(airTemperature1);
  Cayenne.virtualWrite(VIRTUAL_NODE_TEMP, airTemperature1);
  OpenGarden.receiveFromNode(); //Receive data from node
  
}
CAYENNE_OUT(VIRTUAL_NODE_HUM)
{
 OpenGarden.receiveFromNode(); //Receive data from node
  delay(1000); 
  Payload node1Packet = OpenGarden.getNodeData(node1);
  
 float airHumidity1 = node1Packet.humidity;
  //Serial.print(airTemperature1);
  Cayenne.virtualWrite(VIRTUAL_NODE_HUM, airHumidity1);
  OpenGarden.receiveFromNode(); //Receive data from node
}

CAYENNE_OUT(VIRTUAL_NODE_LUM)
{
 OpenGarden.receiveFromNode(); //Receive data from node
  delay(1000); 
  Payload node1Packet = OpenGarden.getNodeData(node1);
  
 int luminosity1 = node1Packet.light;
  //Serial.print(node1Packet);
  Cayenne.virtualWrite(VIRTUAL_NODE_LUM, luminosity1);
  OpenGarden.receiveFromNode(); //Receive data from node
}

Hello. I have a doubt. How do I get the amount in liters? to know how many liters of water spent in a month. thank you.