reed switch on odroid-c1

Post Reply
dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

reed switch on odroid-c1

Unread post by dblade » Fri Jul 15, 2016 8:07 am

I'd like to hook up the linked reed switch to my odroid-c1+. I believe what I would do for monitoring a door that is usually closed is

- hookup common on the switch to 3v3 pin [[ could that 1v8 pin be used? ]]
- hookup N/O on the switch to pin ?? [any of the blue pins on the gpio diagram?] .
Is a resistor absolutely needed on this connection? I have some 4.7k resistors would those work?
- For the software, https://github.com/swkim01/RPi.GPIO-OdroidC1

Am I on the right track and do you have any feedback on this?

reference: https://blog.haschek.at/post/fb64f
switch: https://www.amazon.com/gp/product/B0009 ... UTF8&psc=1
Attachments
b6755fac_ss2014-12-27at05.02.37.png
gpio
(47.72 KiB) Downloaded 1371 times

Jojo
Posts: 524
Joined: Mon May 18, 2015 12:13 am
languages_spoken: english, german
ODROIDs: C1, C1+, C2, HC1, HC2, VU8C
Location: Germany
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by Jojo » Fri Jul 15, 2016 4:54 pm

Hi,

basically you are on the right track. I strongly recommend the series resistor on the GPIO. Imagine the following case: you mistakenly configured the GPIO as "output", and you've mistakenly set the GPIO to "low". Now the switch gets closed, then you'll have a short-circuit from 3,3V over the GPIO to GND. A relatively high current fill flow "into" the GPIO and it will surely be damaged. Thats why it is recommended to use a resistor.

Taking into account, that you have ONLY 4k7 resistors, I personally would do it like this:

5V-----Reed_Contact-------R1_4k7-----(to GPIO)----R2_4k7----R3_4k7----GND

Then you'll have the series resistor (R1) and a pull-down resistor (R2 and R3)
The resistors create a voltage divider, so when reed contact closes, there will be 5/(3*4k7)*(2*4k7) = 3,333V at the GPIO.

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sat Jul 16, 2016 9:05 am

Thanks for the response. I don't understand series and pull-down. So there are two connections on the GPIO? one coming in from reed switch having a 4.7k resistor then from there (GPIO) continuing on into 2 4.7k resistors (unclear if these would be connected to each other parallel or series) that lead into the GND?

Also it's not a problem for me to pickup 10k resistors so how would this change?

rpnid
Posts: 52
Joined: Sun Nov 15, 2015 11:05 pm
languages_spoken: deutsch, english
ODROIDs: some C1+, C2, XU4, and add-ons (Hifi-Shield, VU, 3"2 TFT, SHOW2, etc.)
Location: Germany
Has thanked: 1 time
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by rpnid » Sat Jul 16, 2016 7:13 pm

For my own part, I'm not one of those who like "hot wiring" with switches and alike.

Why not use internal pull-up, and shut to GND, with a protective resistor for misconfigs?

Even the (given) 4k7 ones may right away be ok for the protector(s). Possibly dividing a bit too much - but even if so... another one in parallel should cure that.

just my 2 cents,
Ralf
(a s/w guy in the first place)
deepthought:~# make common sense
make: *** No rule to make target `common'. Stop.

Jojo
Posts: 524
Joined: Mon May 18, 2015 12:13 am
languages_spoken: english, german
ODROIDs: C1, C1+, C2, HC1, HC2, VU8C
Location: Germany
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by Jojo » Sun Jul 17, 2016 12:34 am

dblade wrote:Thanks for the response. I don't understand series and pull-down. So there are two connections on the GPIO? one coming in from reed switch having a 4.7k resistor then from there (GPIO) continuing on into 2 4.7k resistors (unclear if these would be connected to each other parallel or series) that lead into the GND?
What?!?!
My post was showing exactly how to connect the different components to each other! Basically there is a series of three 4k7 resistors between +5V and GND, and the connection to the GPIO is made after the first resistor (looking from the +5V side). Please do a little bit of research about the basics (series protection resistor, pull-up/down resistors, usage of Ohm's Law) by yourself.
rpnid wrote:For my own part, I'm not one of those who like "hot wiring" with switches and alike.

Why not use internal pull-up, and shut to GND, with a protective resistor for misconfigs?

Even the (given) 4k7 ones may right away be ok for the protector(s). Possibly dividing a bit too much - but even if so... another one in parallel should cure that.

just my 2 cents,
Ralf
(a s/w guy in the first place)
Well, basically you are right. The reason why I "recommended" the solution above is, that it directly builds up on the original idea of the TO (connection to the "hot" rail). Your idea is the better one and I personally would do it that way, too. I just did not want to confuse the TO even more by "swapping" his circuit and the logic ;) .
One more thing is, that depending on your system, you might not have access to the internal pull-resistors. I personally was forced to install wiringPI to have access to them, because my OS did not provide that in the file system.
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 2:40 am

All I was asking is if I understood your connection description correctly, specifically how the last 2 4.7k resistors tied together. I'm not sure why you answered the thread.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 3:00 am

rpnid wrote:For my own part, I'm not one of those who like "hot wiring" with switches and alike.

Why not use internal pull-up, and shut to GND, with a protective resistor for misconfigs?

Even the (given) 4k7 ones may right away be ok for the protector(s). Possibly dividing a bit too much - but even if so... another one in parallel should cure that.

just my 2 cents,
Ralf
(a s/w guy in the first place)

Do you mind elaborating on how this would be connected?

Jojo
Posts: 524
Joined: Mon May 18, 2015 12:13 am
languages_spoken: english, german
ODROIDs: C1, C1+, C2, HC1, HC2, VU8C
Location: Germany
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by Jojo » Sun Jul 17, 2016 3:40 am

dblade wrote:All I was asking is if I understood your connection description correctly, specifically how the last 2 4.7k resistors tied together. I'm not sure why you answered the thread.
I answered this thread to help you. There was no offence when I was recommending you to learn a little bit about the basics. Again, this is not meant as an offence, but these are typical cases, for people who tie up "something" to their ODROIDs, and then they come back and ask "How do I fix a fried GPIO?"

From my point of view it is much more effective, satisfying and sustainable, when people learn how to help themselves. I respect your willing to do something practical with your ODROID. But to safe you from bad/smoking experiences, I recommended a little bit of research. I'm not sorry for that. I just regret, that you got it wrong.
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 3:43 am

unless I am certain, no connections or tests will be conducted. I'm not against learning the basics, which i plan to do today. I am only trying to be absolutely clear on the basic connection first so I can then learn how that works.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 1:15 pm

better?
Attachments
reed_try2.jpg
(615.34 KiB) Downloaded 1317 times
Last edited by dblade on Sun Jul 17, 2016 1:40 pm, edited 1 time in total.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 1:38 pm

and a test
Attachments
reed_test1.jpg
(308.64 KiB) Downloaded 1317 times

rpnid
Posts: 52
Joined: Sun Nov 15, 2015 11:05 pm
languages_spoken: deutsch, english
ODROIDs: some C1+, C2, XU4, and add-ons (Hifi-Shield, VU, 3"2 TFT, SHOW2, etc.)
Location: Germany
Has thanked: 1 time
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by rpnid » Sun Jul 17, 2016 9:16 pm

Oops... and truly sorry if I added to the confusion with my commenting!

But at the end of the day, I'd much agree you should have a slight look into the basics of the involved electronics first. If you do a web search on sth like "pull-up resistors" you'll find plenty. Then add the C1 wiki and the results of the GPIO test tool, and I assume you'll be well.

Also note that there IS a lot pf people around to help. BUT... especially us Germans often prefer to take "development" by the word, and assume some professionalism over "kindergarden".

Still... let me try a bit for a very quick start, and in simple words:

There's basically two ways to make a switch give a binary/standard signal:
1. via shutting to some "power", or
2. via shutting to the "reverse", ie. the signal ground, often - but NOT always - even identical to the common ground in the assy.

In either case, the device (here: the C1) needs to know which way you go - and to have a defined input for both states of the switch, or things would of course get wobbelywobbely.
The C1 allows you to deal with the default state via configuration (along with telling it that the chosen port shall be an INPUT), even electrically (now cf. the results you found for "pull-up") much reducing your work by internally setting up the according resistors (which are 60k if I remember correctly, but see the wiki).
Leaves 2 things for you:
- connect the switch in the chosen fashion, and
- preferrably also ensure things will not burn if config and wiring do mismatch

For the latter, so-called "protective resistors" are used, to ensure current is below critical in ALL cases. Now THESE do in turn result in a voltage division, ie. the voltage "when shut" at the GPIO depends on both their values, and the ones of any pull-ups/downs (internally or externally). So they need to be chosen wisely to both protect yet still give voltages that make the GPIO trigger.
See "Ohm law" for more.

Now comes "Experience, Policies, and which way to help best":

- Jojo suggested above "variant 1", to stick to the conditions mentioned in your initial question as closely as possible,
- I went for "variant 2".

Both of them will work. The rest is up to you.

have fun,
Ralf

PS. Nice to see you got a decent DMM... now go learn to understand what it says ;)
deepthought:~# make common sense
make: *** No rule to make target `common'. Stop.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 9:38 pm

just a quick response for you Ralf

"Also note that there IS a lot pf people around to help. BUT... especially us Germans often prefer to take "development" by the word, and assume some professionalism over "kindergarden".

As you probably already know, we Americans can be sensitive and ready to fight. Also I easily forget that the Germans can come across very blunt, but the good intention is still there. This I know first hand as our parent company is Germany based and I regularly work with colleagues from Nagold.

So this preference of yours is ok, but I am glad I have convinced you to entertain some kindergarten because I need the "early" confirmation otherwise I get lost in my many unanswered questions.

So in short thanks for the detailed response.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Sun Jul 17, 2016 10:53 pm

I had a look at pullup/pulldown docs, the c1 wiki and 2 laymen posts for ohms law.

Ralf, so how would I illustrate and perhaps calculate "variant 2" ? You said "Why not use internal pull-up, and shut to GND, with a protective resistor for misconfigs?" also maybe a parallel resistor if it was dividing to much.

[strikethrough]5V-----(to GPIO w/internal pullup 60k acive)-----Reed_Contact-----
|----R2_4k7-----|
|----R3_4k7-----|-----GND[/strikethrough]
Last edited by dblade on Mon Jul 18, 2016 4:04 am, edited 1 time in total.

rpnid
Posts: 52
Joined: Sun Nov 15, 2015 11:05 pm
languages_spoken: deutsch, english
ODROIDs: some C1+, C2, XU4, and add-ons (Hifi-Shield, VU, 3"2 TFT, SHOW2, etc.)
Location: Germany
Has thanked: 1 time
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by rpnid » Sun Jul 17, 2016 11:50 pm

Nope, "variant 2" is as simple as this:

GND --- Reed Contact --- R --- GPIO

where R may eg. be your 4k7 in straight fashion, or - IF you find that keypresses are not reliably recognized - two of them in parallel (thus reducing the value).
I am typically using 1k for R, but some do see this a bit at the low side.

In addition, pls. make sure
- that port is indeed configured to "input", "pull-up", and "default HIGH"
- your s/w or config properly handles "inverse logic"

Advantages of this variant:
- electrically safe (if R is close to the GPIO)!
- for the C1, Voltage for calcs is strictly 3V3,
- R may well be shrinkwrapped right into the cable,
- depending on the assy, you might even save yourself "the other wire" - but this is depending on more, and often not applicable
deepthought:~# make common sense
make: *** No rule to make target `common'. Stop.

rpnid
Posts: 52
Joined: Sun Nov 15, 2015 11:05 pm
languages_spoken: deutsch, english
ODROIDs: some C1+, C2, XU4, and add-ons (Hifi-Shield, VU, 3"2 TFT, SHOW2, etc.)
Location: Germany
Has thanked: 1 time
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by rpnid » Mon Jul 18, 2016 12:01 am

"Blunt"... hmmm...

Be happy "our" smartasses do at least get wordy before they blitz you!
Some others we are in turn used to deal with, and this is just "inside or near the EU":

- Vikings: typically calm, and difficult to judge at temps above -10°C and/or below alc levels suited for defrosting much below
- Russians: also typically calm, just don't ever question competence, or even under-challenge... if you miss the signs you may recognize (or not) only after you suddenly find your wife and family vanished, maybe except for some body parts
- and then... nah, already much OT

:D

Remaining question: Have the responses been helpful so far?

cheers,
Ralf
deepthought:~# make common sense
make: *** No rule to make target `common'. Stop.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Mon Jul 18, 2016 1:01 am

absolutely helpful. Though of course I am multitasking and addressing other non-related issues so I will check out this other approach in due time.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Mon Jul 18, 2016 4:15 am

ok attached is a pic of what i think is correct for the connections on variant 2

To handle "- that port is indeed configured to "input", "pull-up""
GPIO.setup(door_pin, io.IN, pull_up_down=io.PUD_UP)

", and "default HIGH""
For default HIGH, well so far that only seems to pertain to an output pin as far as setting it via software. does it mean to have the switch setup as closed when the door is closed?

To handle "- your s/w or config properly handles "inverse logic""
This I think is satisfied by having both NO and NC connections on the reed switch to use as appropriate?
Attachments
variant2.jpg
(627.7 KiB) Downloaded 1304 times

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Mon Jul 18, 2016 5:36 am

I felt confident enough to test variant 2 and had successful results. Switch NO connection was used.

credit for the script goes to the internet

root@odroid:~# cat doorisopen.py

Code: Select all

import time
import RPi.GPIO as GPIO

#GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BOARD)
     
door_pin = 12
   
GPIO.setup(door_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # activate input with PullUp
     
while True:
     if GPIO.input(door_pin):
        print("DOOR OPEN")
     else:
        print ("DOOR CLOSED")

     time.sleep(.5)


Jojo
Posts: 524
Joined: Mon May 18, 2015 12:13 am
languages_spoken: english, german
ODROIDs: C1, C1+, C2, HC1, HC2, VU8C
Location: Germany
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by Jojo » Mon Jul 18, 2016 6:04 am

Hi,
I am glad that you made some progress. Let us know, if you get stuck somewhere.

Greetings
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Mon Jul 25, 2016 3:19 am

All has went well for a few days now. Also I was able to wire up a relay switch with success. Thanks again for your assistance.

jknight2014
Posts: 12
Joined: Wed Apr 29, 2015 6:38 am
languages_spoken: english
ODROIDs: c1
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by jknight2014 » Tue Jan 24, 2017 5:16 am

How did you import RPi.GPIO? I get an error that it can only be used on the Raspberry Pi.

dblade
Posts: 38
Joined: Tue Jan 26, 2016 9:05 am
languages_spoken: english
ODROIDs: C1+
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by dblade » Tue Jan 24, 2017 5:42 am

You used the software listed in the OP Yes? basically RPi-GPIO but for the odroid

Droidzy
Posts: 6
Joined: Wed Apr 11, 2018 12:29 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: reed switch on odroid-c1

Unread post by Droidzy » Mon Apr 16, 2018 1:14 pm

May I know how you import the RPi.GPIO?

User avatar
odroid
Site Admin
Posts: 31363
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 50 times
Been thanked: 184 times
Contact:

Re: reed switch on odroid-c1

Unread post by odroid » Mon Apr 16, 2018 1:59 pm

Refer this topic of the RPi.GPIO port.
viewtopic.php?f=97&t=30577

Post Reply

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 0 guests