Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Hall effect sensor

Sun Dec 01, 2019 1:10 am

To start this post off on the right foot, I think I fried it.
I am trying to use a hall effect sensor to detect when my box is opened and turn on some lights. I think I probably purchased the wrong hall sensor for the job. I got a A3144. At some point I figured out its datasheet says it runs at a minimum of 4.5v, so I wired it up on my breadboard to draw its power directly from the same line that powers the RPi, at 5.2volts. next leg wired to ground, and then the final leg wired to gpio1 (board pin 12). I originally had a 10k pull up resistor on the output. When that didn't seem to work I dug into the datasheet and tried it as a pull down resistor instead. Still not sure which one's right.

After failing to get any reaction in my python script I pulled out my multimeter to see what was actually going on. The output pin is at 0 most of the time, as expected, and when I bring in a magnet it goes to 2 or 3 millivolts. I eventually realized I was probably putting bad voltage into my GPIO and thought I had probably fried that pin and would wire in a voltage divider and try another, but in reading the FAQ I gather its more likely that the whole setup is wrecked, not just the one pin.

So, questions:

1. Is the output of a hall effect sensor the same as the input voltage, in this case 5.2 and therefor I fried my GPIO?
2. Is there something I'm not understanding about why the hall effect sensor would put out a few mV? I feel like if I fried the GPIO pin then with only hot and ground connected I should still see somewhere around 5v on the output.
3. If I wire output of hall sensor to gpio1 via 200 ohm resistor, and then gpio1 to ground via 330 ohm resistor, is that a correct implementation of this sensor?
4. Is there a better sensor I should be using that would work right off the 3.3v pin instead of mucking about with a voltage divider?
5. I understand most of the rest of the warnings in the pitfalls for beginners, but the last one says don't fiddle with things attached to GPIO while its on. Is that due to a specific problem, or just that if your fiddling with things its likely youll end up connecting two things that ought not be connected?

hippy
Posts: 6281
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Hall effect sensor

Sun Dec 01, 2019 3:14 am

The A3144 is open-collector so should have a pull-up to 3V3. If that's not there, and the GPIO is not configured to use an internal pull-up you probably will read mere millivolts.

If you did connect that pull-up to 5V then you might have damaged the GPIO pin or the entire GPIO. If not, you likely haven't.

emma1997
Posts: 341
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not the old one)

Re: Hall effect sensor

Sun Dec 01, 2019 3:48 am

You shouldn't need any resistors at all and choose a better Pi pin.

Pin 12 (GPIO18) is not a good one with that default pulldown. It does need a pullup but best use one built into the PI so levels (~3v) are correct. I suggest use GPIO2 or 3 or 4 or 5 or any pin that has a default pullup. That divider kluge makes no sense and is probably doing more harm than good.

The sensor outputs voltage near ground with a properly oriented magnet and with no magnet about 3v in this configuration. Multimeter is definitely a good tool for checking this.

If all this still fails replace the PI with your 10k resistor and verify 0v to ~4v output with magnet.

I would be surprised if anything is dead but who knows. The sensors are only a dime each so hopefully you purchased at least a dozen or so. Even if you did blow a PI pin (highly unlikely IMO) there are a lot more left to try. A photo here might be the next step to verify wiring.

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Sun Dec 01, 2019 4:35 am

It was definitely connected with a pullup to 5v for my first attempts. Is there an easy way to find out how damaged or not the GPIO is?
I would love to pull it up to 3v3 but my understanding is thats not enough voltage to run the hall effect sensor I have.

User avatar
joan
Posts: 14473
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Hall effect sensor

Sun Dec 01, 2019 8:55 am

Run wiringPi's pintest or pigpio's gpiotest.

There is a difference between the A3144 V+ requirements and the pull-up voltage needed on the data output line. You can power from 5V and still use a pull-up to 3V3 on the output line. It is an open collector output (Google).

hippy
Posts: 6281
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Hall effect sensor

Sun Dec 01, 2019 2:52 pm

Callipygous wrote:
Sun Dec 01, 2019 4:35 am
Is there an easy way to find out how damaged or not the GPIO is?
Yes; write a short Python or other program which sets the pin as input and reports what level it is. Then connect that pin via a 1K resistor to 0V and 3V3. Assuming your program is correct you should see 0 and 1 respectively if working correctly.

Some GPIO utilities, pre-installed or installable, may save you from having to write that program yourself.

emma1997
Posts: 341
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not the old one)

Re: Hall effect sensor

Sun Dec 01, 2019 7:16 pm

Callipygous wrote:
Sun Dec 01, 2019 4:35 am
Is there an easy way to find out how damaged or not the GPIO is?
IME doubtful only one pin on your Pi is damaged. Out of nearly a hundred passed through my hands last few years only a few sustained damage and in almost every case the unit failed completely. Dead as a doornail. Two exceptions involved no WIFI and another with flaky USB but everything else seemed ok. I'm sure it can happen but for me not yet.

Probably best way to test is check the default pin state with your meter. If not as expected maybe there is damage. I categorize as possible but unlikely. Seems like you might want to verify the sensor first then move on to Pi hardware&software problems when time to cross those bridges.

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Wed Dec 04, 2019 7:20 am

Image
Image
Image
Here is my code, and all the pertinent wiring. Dont worry about the mess on the right hand side of the board, it will all get integrated eventually, but to simplify my troubleshooting right now none of it is connected to the pi.
Top left of the board is a power boost 1000 to take my batteries up to 5.2v for the pi. You can see the hot (blue) and neutral (blue and white) going to the pi, then jumpers just to bring power to my sensor. Voltage/continuity has been verified via multimeter every step of the way, including at the little nubs you can see right before it goes into the sensor.
I have tried numerous inputs, always with the same results. Gpiotest found no problems. If I use pull_up_down=gpio.PUD_DOWN instead of up I get the the opposite message. If I use pull_up_down=gpio.PUD_NONE it starts on one and I think it switched at some point, but then stayed stable. In all cases, the magnet has no effect on the output.
I also tried it wired directly onto pins 4 6 and 8(board numbering) with the same results. I also ordered another hall sensor from adafruit earlier this week, https://www.adafruit.com/product/158 the only difference I could discern is switching the neutral and drain pins, also wired to pins 4 6 and 8, again, with the same results.

Thank you very much for all the replies, if you tell me what I am doing wrong my family will be indebted to yours for generations to come.

Also, I realize my second if should really be an else. I've been eliminating everything I could think of, and keeping the code consistent between the two cases was just one more thing to try.

User avatar
joan
Posts: 14473
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Hall effect sensor

Wed Dec 04, 2019 8:01 am

You are using GPIO 8 in the software. I can see nothing connected to GPIO 8.

https://pinout.xyz/

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Wed Dec 04, 2019 2:24 pm

Wow. Ok.
I typed "rpi 3 a+ pinout" into google, and apparently didnt read the first result carefully enough, as its someones custom numbering scheme.
Thanks, Ill give that a try.

User avatar
rpdom
Posts: 15600
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Hall effect sensor

Wed Dec 04, 2019 2:42 pm

There are three recognised numbering schemes for the GPIOs:

1. The BCM system, which is what the Pi understands internally. This is preferred by many.

2. The "Board" system, which refers to the physical pin numbers.

3. The "WiringPi" system, which was based on the original idea to number the GPIOs in a simple way, but was later dropped by most software.

I suspect you found a diagram that used the WiringPi method.

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Wed Dec 04, 2019 4:09 pm

It looks like you are correct. I found the Pi4j project, it says they use the same scheme as wiringpi. Just to gripe... they are just labels, seems like coming up with any more than 1 scheme for them would cause more harm than good.

Works fine now, I just hope I can figure out a little bit bigger triggering distance. Thanks for the help!

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

Re: Hall effect sensor

Wed Dec 04, 2019 6:21 pm

Callipygous wrote:
Wed Dec 04, 2019 4:09 pm
Just to gripe... they are just labels, seems like coming up with any more than 1 scheme for them would cause more harm than good.
I agree entirely.
It's a bit like every town having its own street and house naming system, when we have a perfectly good latitude / longitude system that's universal (or at least planet-wide)

emma1997
Posts: 341
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not the old one)

Re: Hall effect sensor

Wed Dec 04, 2019 10:03 pm

"Shades of Arduino Batman!"

I used to think their wacky 'pin' numbers and odd connector spacing were stupid mistakes. Now I see that w/o that mess it's unlikely Uno would have ever caught on. Be it market differentiation or "I don't care what they call me as long as they call me" syndrome, IMO Massimo wasn't as incompetent as some claim.

Refer to physical pin by physical pin and port bit number by port bit number and there will be little confusion. Best to stick with RPi mfg definitions but, you know, everybody's got to be "creative" and assert their sumpin'-sumpin' onto the world.

GEN-what???

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Thu Dec 05, 2019 2:01 am

Burngate wrote:
Wed Dec 04, 2019 6:21 pm
I agree entirely.
It's a bit like every town having its own street and house naming system, when we have a perfectly good latitude / longitude system that's universal (or at least planet-wide)
GPS coordinates are terrible for telling humans how to navigate, they also lack the ability to lend creative or emotional attachment.

Pin numbers that are just numbers, vs other pin numbers that are just numbers, buried in code where they don't need to serve any aesthetic purpose, they just need to tell you what pin we're talking about... I'm not going to say no reason at all, I'm sure who ever did it thought they were clever, and they probably weren't entirely wrong. But I'm standing by my "more harm than good".

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Hall effect sensor

Thu Dec 05, 2019 8:11 am

http://wiringpi.com/pins/
https://projects.drogon.net/wiringpi-pin-numbering/

Explains the reasons and history (from 2012) for the numbering schemes.

The recommendation now is to use BCM numbers everywhere.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

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

Re: Hall effect sensor

Thu Dec 05, 2019 10:18 am

Callipygous wrote:
Thu Dec 05, 2019 2:01 am
GPS coordinates are terrible for telling humans how to navigate, they also lack the ability to lend creative or emotional attachment.
Also, they don't allow for continental drift. At an inch or so per year, it'll not be long (in relation to the age of her house) before emma1997 is getting her neighbour's post.

Similar to the way pins 3 & 5 changed their GPIO numbers between Rev 1 and Rev 2, but kept their WiringPi addresses.

User avatar
joan
Posts: 14473
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Hall effect sensor

Thu Dec 05, 2019 10:25 am

This just highlights many points familiar to anyone who has ever tried to write documentation. Many won't read it in the first place and of those that do some will find the most perverse interpretation of your words.

Callipygous
Posts: 14
Joined: Tue Jul 23, 2019 3:09 am

Re: Hall effect sensor

Thu Dec 05, 2019 2:08 pm

Burngate wrote:
Thu Dec 05, 2019 10:18 am
Similar to the way pins 3 & 5 changed their GPIO numbers between Rev 1 and Rev 2, but kept their WiringPi addresses.
Neat!
Why'd they change the pin numbers?

User avatar
rpdom
Posts: 15600
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Hall effect sensor

Thu Dec 05, 2019 4:14 pm

Callipygous wrote:
Thu Dec 05, 2019 2:08 pm
Burngate wrote:
Thu Dec 05, 2019 10:18 am
Similar to the way pins 3 & 5 changed their GPIO numbers between Rev 1 and Rev 2, but kept their WiringPi addresses.
Neat!
Why'd they change the pin numbers?
Because the internal connections changed. Originally they were GPIO 0 and 1 which are used for the main i2c bus. Those were needed for other things on later designs so the pins were reassigned to GPIO 2 and 3 on the second i2c bus.

I'm not entirely sure why the pin for GPIO 21 became GPIO 27, possibly something to do with routing tracks on the circuit board?

emma1997
Posts: 341
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not the old one)

Re: Hall effect sensor

Fri Dec 06, 2019 3:42 pm

Burngate wrote:
Thu Dec 05, 2019 10:18 am
At an inch or so per year, it'll not be long (in relation to the age of her house) before emma1997 is getting her neighbour's post.


lol

Apparently plate tectonics are speeding up because I am already getting many of his packages. Versa vice too. Almost always Amazon/Bluecare. Surely coincidence and unlikely due to poor delivery tactics because we all know what excellent drivers they have. Right? :)

Return to “Beginners”