element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Need Assist in Programing Flowmeter and temperature sensor to the RaspberryPi (Python)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 15 replies
  • Subscribers 707 subscribers
  • Views 3396 views
  • Users 0 members are here
  • raspberry_pi
  • flowmeter
  • temperaturesensor
Related

Need Assist in Programing Flowmeter and temperature sensor to the RaspberryPi (Python)

e14 Contributor
e14 Contributor over 12 years ago

Hey guys i'm new to the community and just starting out with the raspberry pi.

i do have some basic programming experience with C and FORTRAN but python is new to me.

 

I am working on a project that requires tow of the Liquid flow Meter - Plastic 1/2" NPS Threaded (adafruit 828), and six of the Waterproff DS18B20 Digital temperature (adafruit item 381).

 

I am trying to program them into the raspberry Pi in order to record and display each of temperature sensor data in Fahrenheit and each flow meter need to put out instantaneous speed of liquid in Gal / Minutes.

 

Adafruit does have the code for the temperature sensor and the flow meter but the problem is that the code for flowmeter is designed to output the data on a twitter page and i can't make any heads or tails of it. also the two programs need to be able to put together in to a single file.

 

please help.

  • Sign in to reply
  • Cancel
Parents
  • iagorubio
    0 iagorubio over 12 years ago

    I have experience with the DS1620 temperature sensor.

     

    If this DS18B20 is anywhere close to the DS1620, it's not the easiest temperature sensor to work with. Analog sensors use to be much easier as you just need a lookup table for taking temperature from the analog value read.

     

    Those are digital temperature sensors and have a more or less complex communication protocol to get data out of them. They also use to have signaling - at least the DS1620 - where you program a max and min temperatures Th and Tl and the chip will trigger an alarm when the temperature is higher than Th or lower than Tl. The 1620 also have a Tcom pin that goes high from when one temperature is reached, to when the opposite temperature is reached so it can act as a standalone thermostat is you plug it to a fan or a heater.

     

    I write this so you realize that may be those sensors are more complex than what you need to just make some temperature readings.

     

    With this kind of thermistor TMP36 - Analog Temperature sensor [TMP36] ID: 165 - $1.50 : Adafruit Industries, Unique & fun DIY electronics and kits as example the temp reading is trivial Temp in °C = [(Vout in mV) - 500] / 10.

     

    You just would need some marine heat shrink tube to isolate the sensor and solder it to a wire to have a working sensor like the other one you are linking. And much cheaper I guess.

     

    Anyway if you have already bought the temp sensors, there is a Arduino library you can use with the ardupi or PiFace wiring libraries. That may be the easier path.

     

    Ardupi - Cooking Hacks - Documentation - Raspberry Pi to Arduino shields connection bridge

    PiFace wiring - PiFace | Wiring Pi

    DS18B20 library - http://www.milesburton.com/?title=Dallas_Temperature_Control_Library

     

    Don't try the same path with the flow meter arduino example though as it uses interrupts, and those are completely different beasts in Arduino and raspberry. In the raspberry you can use separate processes for each reading so you don't need to use interrupts and use a dedicated process for each flow meter instead.

     

    The flow meter you just need to count pulses,  and average the readings to get the flow so it's trivial to dead with it.

     

    It just have a pinwheel with a magnet so each time it spins it sends a pulse when a hall effect sensor detects the magnet passing.

     

    You will also need to calibrate it because I am sure the piping will have something to do with how much liquid is passing by on each spin.

     

    You will also need to have a steady flow, because reflows -liquid going back - will make the pinwheel spin. This is a wild guess from the device description but something to take into account.

     

    What libraries / languages you plan to use ?

     

    ... and ...

     

    What kind of output you need ?

     

    It may be easier to separate each sensor in a task and later on plug it all together than to try to get it all working at the same time.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • iagorubio
    0 iagorubio over 12 years ago

    I have experience with the DS1620 temperature sensor.

     

    If this DS18B20 is anywhere close to the DS1620, it's not the easiest temperature sensor to work with. Analog sensors use to be much easier as you just need a lookup table for taking temperature from the analog value read.

     

    Those are digital temperature sensors and have a more or less complex communication protocol to get data out of them. They also use to have signaling - at least the DS1620 - where you program a max and min temperatures Th and Tl and the chip will trigger an alarm when the temperature is higher than Th or lower than Tl. The 1620 also have a Tcom pin that goes high from when one temperature is reached, to when the opposite temperature is reached so it can act as a standalone thermostat is you plug it to a fan or a heater.

     

    I write this so you realize that may be those sensors are more complex than what you need to just make some temperature readings.

     

    With this kind of thermistor TMP36 - Analog Temperature sensor [TMP36] ID: 165 - $1.50 : Adafruit Industries, Unique & fun DIY electronics and kits as example the temp reading is trivial Temp in °C = [(Vout in mV) - 500] / 10.

     

    You just would need some marine heat shrink tube to isolate the sensor and solder it to a wire to have a working sensor like the other one you are linking. And much cheaper I guess.

     

    Anyway if you have already bought the temp sensors, there is a Arduino library you can use with the ardupi or PiFace wiring libraries. That may be the easier path.

     

    Ardupi - Cooking Hacks - Documentation - Raspberry Pi to Arduino shields connection bridge

    PiFace wiring - PiFace | Wiring Pi

    DS18B20 library - http://www.milesburton.com/?title=Dallas_Temperature_Control_Library

     

    Don't try the same path with the flow meter arduino example though as it uses interrupts, and those are completely different beasts in Arduino and raspberry. In the raspberry you can use separate processes for each reading so you don't need to use interrupts and use a dedicated process for each flow meter instead.

     

    The flow meter you just need to count pulses,  and average the readings to get the flow so it's trivial to dead with it.

     

    It just have a pinwheel with a magnet so each time it spins it sends a pulse when a hall effect sensor detects the magnet passing.

     

    You will also need to calibrate it because I am sure the piping will have something to do with how much liquid is passing by on each spin.

     

    You will also need to have a steady flow, because reflows -liquid going back - will make the pinwheel spin. This is a wild guess from the device description but something to take into account.

     

    What libraries / languages you plan to use ?

     

    ... and ...

     

    What kind of output you need ?

     

    It may be easier to separate each sensor in a task and later on plug it all together than to try to get it all working at the same time.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to iagorubio

    Thanks for the replay.

     

    I actually already have the thermal sensor working with this code

     

    import os

    import glob

    import time

    os.system('sudo modprobe w1-gpio')

    os.system('sudo modprobe w1-therm')

     

     

    base_dir = '/sys/bus/w1/devices/'

    sensor1_folder = glob.glob(base_dir + '28-000004a8873d')[0]

    sensor1_file = sensor1_folder + 'w1-slave'

     

     

    def sensor1_raw():

      s1 = open(sensor1_file, 'r')

      s1lines = s1.readlines()

      s1.close()

      return s1lines

     

    def sensor1_temp():

      s1lines = sensor1_ra()

      while s1lines[0].strip()[-3:] !='YES':

      time.sleep(0.2)

      s1lines = sensor1_raw()

      equals_pos = s1lines[1].find('t=')

      if equals_pos != -1:

      tempstarting = s1lines[1][equals_pos+2:]

      temp_c = float(temp_string) / 1000.0

      temp_f = temp_c * 9.0 / 5.0 + 32.0

      return temp_c, temp_f

     

    while True:

      Print(sensor1_temp())

      time.sleep(1)

     

    ________________________________________________________________________________

    Which prints out the Temperature data every second but my big problem is figuring out how to count the pulses of the flow meter or to count the time between the pulses to get the frequency. That is the part of the program that i need big help with.

     

    Using Python

     

    I have tried this code but i'm doing something wrong it seems.

     

    ________________________________________________________________________________

     

    import os # importing OS module just in-case needed

    import time # Importing Time module

    import RPi.GPIO as gpio # Importing RPIO module as gpio

     

     

    # Initializing GPIO ports

    boardRevision = gpio.RPI_REVISION # Clearing previous gpio port settings

    gpio.setmode(gpio.BCM) # Use real physical gpio port numbering

    gpio.setup(22, gpio.IN, pull_up_down=gpio.PUD_UP) # setting pin 22 as pull up resistor

     

     

    while True: # main loop continuously running

     

     

      gflowcount = 1 # setting loop execution count

     

     

      while gflowcount <= 2: # loop for getting two times to compare

     

     

      if (gflowcount == 1 & gpio.input(22) == True): # Executing loop at first loop

     

      gflowtime1 = int(time.time()*1000) # Getting time of first pulse

      gflowcount = gflowcount + 1

     

      else if (gflowcount == 2 & gpio.input(22) == True): # Executing loop at second pulse

     

      gflowtime2 = int(time.time()*1000) # Getting time of second pulse

     

      else:

      print ('error')

     

      freq = gflowtime2 - gflowtime1 # Calculating time between two pulses

      hertz = 1000.0000 / freq # Calculating frequency

      flow = hertz / (60 * 7.5) # L/S # Calculating L/S

     

     

    while True: # loop running every 2 seconds to output the data

     

     

      print freq # Printing time between two pulses

      print ('time between two pulse')

      print hertz # printing the frequency

      print ('frequency')

      print flow # Printing L/S

      print ('L/S')

      time.sleep(2) # Pausing for 2 sec.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube