arclite
Posts: 7
Joined: Mon Aug 18, 2014 9:14 am

Using a Hall effect sensor with RPi

Fri Feb 17, 2017 12:19 pm

What has happened to the Hall.py file offered in the article by Matt Hawkins, under Raspberry-Pi-Spy.co.uk Home > Hardware > Sensors, dated September 28th 2015? I wanted to try my first bit of Python and to use my Pi for the first time and just my luck to be frustrated. I have bought a big hot water tank to be used with a solar water heater but I want to build a weather monitor to check on the efficiency of my set up. A hall effect sensor will be used for both wind speed and direction. Just how many RPIs will be necessary to monitor a variety of single wire thermometer sensors and I2C humidity sensors is beginning to melt my brain!

In getting to post I lost the article date so I hope somebody will recognise this amongst a series of articles published in MagPi?

wget https://bitbucket.org/MattHawkinsUK/rpi ... on/hall.py

Thank you in advance for any help received.

Alexandra

User avatar
Ferdinand
Posts: 231
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: Using a Hall effect sensor with RPi

Fri Feb 17, 2017 8:47 pm

Hi arclite,

I rewrote the original hall.py code a little bit. Connect the output of the open collector of the hall sensor to GPIO 17 and use a pullup resistor of ~2.7 k ohm to 3.3 v. If the south pole passes the hall sensor it will turn the output on. This py script counts the passes of the magnet only.

Success with your project!

Try this code:

Code: Select all

#!/usr/bin/python

#--------------------------------------
#    ___  ___  _ ____
#   / _ \/ _ \(_) __/__  __ __
#  / , _/ ___/ /\ \/ _ \/ // /
# /_/|_/_/  /_/___/ .__/\_, /
#                /_/   /___/
#
#       Hall Effect Sensor
#
# This script tests the sensor on GPIO17.
#
# Author : Matt Hawkins
# Date   : 27/09/2015
#
# http://www.raspberrypi-spy.co.uk/

#--------------------------------------

# Import required libraries
import RPi.GPIO as GPIO
import time
import datetime

def sensorCallback(channel):
  global sensorCounter
  global sensorStatus
  sensorStatus = True
  #timestamp = time.time()
  #stamp = datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S')
  sensorCounter += 1
  #print "Sensor LOW " + stamp

def main():

  try:
    global sensorCounter
    global sensorStatus
    sensorStatus = True
    sensorCounter = 0
    while True :
      if sensorStatus == True:
        print "Sensor Counter   ", sensorCounter 
        sensorStatus = False

  except KeyboardInterrupt:
    # Reset GPIO settings
    GPIO.cleanup()  
  
# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)

print "Hall sensor test program \n"

# Set Switch GPIO as input
GPIO.setup(17 , GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setwarnings(False)
GPIO.add_event_detect(17, GPIO.RISING, callback=sensorCallback)

if __name__=="__main__":
   main()

Success with your project!
Ferdinand

arclite
Posts: 7
Joined: Mon Aug 18, 2014 9:14 am

Re: Using a Hall effect sensor with RPi

Sat Feb 18, 2017 11:50 am

Hi Ferdinand, sorry but my problem is that the original file is now missing, the link is broken!

Also when taking about critical stuff like frying a RPi, please refrain from using jargon like ASO and DBM because it frustrates me and possibly other newbies. At least treat us equally by providing a key to these shorthand references. It isn't fair or clever to use this stuff in an "open forum" , it is ok in private messages to friends you know etc. With thanks for your efforts and contributions. Looking forward to being able to put this example to good use, but I and others would need access to the complete file first however if you could help here?

User avatar
Ferdinand
Posts: 231
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: Using a Hall effect sensor with RPi

Sat Feb 18, 2017 12:29 pm

Hi arclite,

Are you looking for this article?

http://www.raspberrypi-spy.co.uk/2015/0 ... pberry-pi/
Success with your project!
Ferdinand

User avatar
Burngate
Posts: 5012
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Using a Hall effect sensor with RPi

Sat Feb 18, 2017 4:49 pm

... jargon like ASO and DBM
A.S.O. is "and so on"
DBM could possibly be an abbreviation for the power ratio in decibels (dB) of the measured power referenced to one milliwatt (mW), or mean 9-(6-deoxy-beta-D-allofuranosyl)-6-methyl-9H-purine in the Protein Data Bank. We await Ferdinand's explanation of his signature

Return to “The MagPi”

Who is online

Users browsing this forum: No registered users and 0 guests