mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Choosing: Pull Up or Pull Down Resistor

Sun Jun 07, 2020 7:48 pm

Hello,

With consideration to the internal pull-up / pull-down resistor functionally in the raspberry pi; is either better for long distance transmission of a signal? (Or are there any general rule-of-thumb distance limits for each configuration?)

I was hoping to put together a set up that would work for distances up to 1000 ft, however the distance will likely be less than that. I believe the gauge of the wire I have is 22 AWG.

Thanks in advance for the help!

trejan
Posts: 2238
Joined: Tue Jul 02, 2019 2:28 pm

Re: Choosing: Pull Up or Pull Down Resistor

Sun Jun 07, 2020 8:01 pm

1000 feet is going to be too much for a bare GPIO pin even with a pull up or pull down. You'll need to use something like RS485 with line driver/receiver over a twisted pair + ground to cover that distance. This does mean you'll need power at the other end or additional wires to carry power.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Choosing: Pull Up or Pull Down Resistor

Sun Jun 07, 2020 10:59 pm

Internal pullup/pulldown resistors are notoriously weak, at about 50K,(50000 Ohm) so can easily be overcome even with just a few centimetres of wire near a finger it will pickup the hummers' from mains wiring nearby. You need much stronger pullups for longer wires.
For example the I/O pins for I2C on the RPI have 1.6K (1600 Ohm AKA 1K6) resistors (to 3V3). So you might want to try similar low ohmic values for pullup resistors.

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Mon Jun 08, 2020 1:52 am

trejan and mahjongg,

Thanks you for taking the time to respond to my post!

My Setup for Reference:

So the data cables I have are to monitor two limit switches. There isn't much information transferred, just occasional checks that the switches are still connected, and once daily homing. For this setup, I have 5 wires, 2 for "NO", 2 for "NC" and one for GND. (NO = normally open, NC = normally closed)


I guess I was just hoping I could buy some shielded wire and perhaps get some kind of pi attachable amplifier, which would use the 5v GPIO to help the signal reach to the pi and back. This way I wouldn't have to re-write my code. Does this make any sense or am I way off?

And I apologize in advance for my naivete on this subject, but the RS485 and I2C appear to be separate data transfer protocols correct? Would these require complete re-writes of my code, as in I would no longer be using GPIO.LOW and GPIO.HIGH for checking signals?

User avatar
penguintutor
Posts: 386
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Mon Jun 08, 2020 6:46 am

You are correct that serial and I2C are communication protocols. To use those you would need some circuitry at the other end to communicate the status over the serial protocol.

The problem with the length of the cable is down to resistance of the cable and signal to noise ratio.
The resistance of the cable will meant that voltage will be dropped across the cable. By the time it reaches the Pi it may not be enough to guarantee the logic level thresholds. The other problem is noise. The longer the cable the more electrical interference may give false triggers (also depends upon what interference there is).

Using an external resistor may help rather than the internal pull-up / pull-down as mahjongg has suggested.

An alternative is to increase the signal strength by increasing the voltage (eg 12V) and then feeding that into a comparator. This would mean needing additional circuitry.

boyoh
Posts: 1474
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Choosing: Pull Up or Pull Down Resistor

Mon Jun 08, 2020 12:27 pm

Would it be possible to use a higher voltage as the signal wires to the remote limit switches. Then the switch wires back from
the limits switch's , then use opto isolators as voltage levelers 12v to 3.3 v to the GPIOs , Opto Isolaters are very good at
noise isolation and signal isolation

This is only a suggestion

12v-----------( limit switch )--------------( R )---------------( a opto c )------ground
3.3v Rail---------------------------------------------------------------( c O/T e )----------( GPIO )----( 10k )------0v Rail

O /T = Opto Transistor Receiver

10 kr Pull UP Resistor

Calculate R to give 10 ma for OPTO LED Transmitter

No need to common grounds

Regards BoyOh Thi
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Idahowalker
Posts: 508
Joined: Wed Jan 03, 2018 5:43 pm

Re: Choosing: Pull Up or Pull Down Resistor

Mon Jun 08, 2020 12:54 pm

Will you be connecting 2 RPi's together? Will you be placing a sensor remote from the RPi? Have you considered using a micro controller with WiFi to manage the device with the sensor? You can run MQTT on the RPi, and have your remote device publish the device info to the RPi.
Without knowing why you are deleting my postings, I will not know how...

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 2:47 am

Thank you for all the helpful comments. There appears to be more ways than I originally thought to solve this problem.

To minimize the learning curve of a new data transfer protocol and other large changes in code / hardware, I was kind of thinking along the lines that 1 or 2 of you touched on, similar to boyoh idea using octocouplers.

So what if I did this:

Had two completely separate systems of circuits.

Circuit System 1 (The long distance circuit - 100 ft to 1000 ft each):

I use the 5v pins on the raspberry pi and connect directly to the "Normally Open" and "Normally Closed" pins on both the limit switches (4 connections total). For the "Common"'s I connect the appropriate size resistor and then connect them to GND on the pi.

Circuit System 2 (The very short distance circuits - about 1 foot each):

For the second circuit, I use the internal Raspberry Pi pull up resistor, however instead of connecting directly to the limit switch, I connect a relay / octocoupler. This relay / octocoupler will be paired with the corresponding "NO" or "NC" circuit for each limit switches (4 relays in total).

Therefore, when a limit switch is not pressed and in the "NC" position, the associated relay / octocoupler will have that relay closed and the lower voltage internal resistor of the pi will read "LOW" resistance. Then when the limit switch is pressed and the "NO" circuit is closed, the corresponding relay will be tripped and now that secondary circuit will read "LOW" resistance.

Using this configuration, all I have to do is separate the circuits and connect them using 4 relays. This to me will allow the exact same code to be used, which is what I am trying to achieve.

What do you think? Is this a sound idea? Or have I lost my mind? haha

boyoh
Posts: 1474
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 9:33 am

mogo4414 wrote:
Tue Jun 09, 2020 2:47 am
Thank you for all the helpful comments. There appears to be more ways than I originally thought to solve this problem.

To minimize the learning curve of a new data transfer protocol and other large changes in code / hardware, I was kind of thinking along the lines that 1 or 2 of you touched on, similar to boyoh idea using octocouplers.

So what if I did this:

Had two completely separate systems of circuits.

Circuit System 1 (The long distance circuit - 100 ft to 1000 ft each):

I use the 5v pins on the raspberry pi and connect directly to the "Normally Open" and "Normally Closed" pins on both the limit switches (4 connections total). For the "Common"'s I connect the appropriate size resistor and then connect them to GND on the pi.

Circuit System 2 (The very short distance circuits - about 1 foot each):

For the second circuit, I use the internal Raspberry Pi pull up resistor, however instead of connecting directly to the limit switch, I connect a relay / octocoupler. This relay / octocoupler will be paired with the corresponding "NO" or "NC" circuit for each limit switches (4 relays in total).

Therefore, when a limit switch is not pressed and in the "NC" position, the associated relay / octocoupler will have that relay closed and the lower voltage internal resistor of the pi will read "LOW" resistance. Then when the limit switch is pressed and the "NO" circuit is closed, the corresponding relay will be tripped and now that secondary circuit will read "LOW" resistance.

Using this configuration, all I have to do is separate the circuits and connect them using 4 relays. This to me will allow the exact same code to be used, which is what I am trying to achieve.

What do you think? Is this a sound idea? Or have I lost my mind? haha
From BoyOh
Some times writing about it and talking about it ,can be very confusing to get your point across. So in this instance it would
be better if you did a circuit diagram of your project, Then the forum might be able to give you more help

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

pidd
Posts: 724
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 10:03 am

Connecting 1000ft aerials to a digital circuit without isolation and protection is never a good idea.

Using either coaxial cable or twisted pairs and/or a low pull down resistor (say 50 ohm) at the receiving end will help. Noise tends to be voltage related with little current, a low resistance, higher current circuit will be less susceptible to noise. If you have four of these circuits the current builds up (400ma) so you need to make sure you have a supply that can cope.

Opto-iolators are a must.

boyoh
Posts: 1474
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 3:14 pm

pidd wrote:
Tue Jun 09, 2020 10:03 am
Connecting 1000ft aerials to a digital circuit without isolation and protection is never a good idea.

Using either coaxial cable or twisted pairs and/or a low pull down resistor (say 50 ohm) at the receiving end will help. Noise tends to be voltage related with little current, a low resistance, higher current circuit will be less susceptible to noise. If you have four of these circuits the current builds up (400ma) so you need to make sure you have a supply that can cope.

Opto-iolators are a must.

From BoyOh
Yes Opto Isolators are a must, as i suggested in my circuit designee But using 50ohm resistors as Pull Down resisters , is
a total impedance miss match, it will divert the low power signal out of existence

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

pidd
Posts: 724
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 4:50 pm

boyoh wrote:
Tue Jun 09, 2020 3:14 pm
From BoyOh
Yes Opto Isolators are a must, as i suggested in my circuit designee But using 50ohm resistors as Pull Down resisters , is
a total impedance miss match, it will divert the low power signal out of existence

Regards BoyOh
My thinking is 1000ft aerial and a diode (LED) in an optoisolater is going to make a very broadband crystal receiver, you need to dump the noise power somewhere, capacitors can help but if you are not careful they can do the opposite by resonating.

Apart from the plethora of RF sources we have these day there are occasional lightning impulse, appliances switching on and off etc. My fridge across the room blanks my DVI display for a few seconds even after putting chokes on all the lines to the display and everything connected to the display going through a well filtered UPS.

If the switches are driven directly from a 5V power source, 50 ohms would draw 0.1A, I guess that is a bit on the over-precautions side but I'd be reluctant to go below 50mA without expecting some sporadic triggering off that length of wire?

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 10:32 pm

This is my suggested layout. I imagine that there will be some additional components, but this should be the bulk of it.

So as I stated before there are two separate types of circuits. It starts at the 5v pin(s) on the GPIO, these pins run to 4 relays/octo-couplers and then to each of the leads on the limit switches. The common of each are connected and a resistor is placed in series and it returns to GND on the Pi. (This set of circuits are the long distance circuits.)

The next set of circuits are for the GPIO, internal Pull up resistors. For each of the 4 leads on the limit switches there is an associated GPIO data pin. A wire is run from the pin on the board to the relay / octocoupler. When the above circuits are closed, the relay will closed, creating a magnetic field and closing the bottom connection. This results in the same signals being passed to the pi as previously, but allows this secondary circuit to remain very short.

In this configuration, my code should be unaffected. I might only just need to increase the small delay, to allow for the limit switch to be pressed, and also for the relay to react.

Think this will work? Or what else is needed?

Thanks for the help!

Image

User avatar
davidcoton
Posts: 5084
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Tue Jun 09, 2020 10:42 pm

mogo4414 wrote:
Tue Jun 09, 2020 10:32 pm
Think this will work? Or what else is needed?
What is the resistor in the GND lead to the limit switches meant to achieve? I don't think you need or want it, it will just get hot and/or prevent the relays pulling in, depending on its value.

As previously suggested opto-isolators would be better (smaller, cheaper, more reliable) than relays, the circuit would be similar (needing only a resistor for each opto input, and some attention to connecting them with correct polarity).
Signature retired

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Wed Jun 10, 2020 2:33 am

I updated the drawing to show octoisolators (they might be drawn in incorrectly, but that is where it would be), and I included resistors in series before each coupler. I'm not sure what size resistor this should be yet.

If I set up this circuit as shown, do you think it would work as intended?

Image

boyoh
Posts: 1474
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Choosing: Pull Up or Pull Down Resistor

Wed Jun 10, 2020 9:36 am

mogo4414 wrote:
Wed Jun 10, 2020 2:33 am
I updated the drawing to show octoisolators (they might be drawn in incorrectly, but that is where it would be), and I included resistors in series before each coupler. I'm not sure what size resistor this should be yet.

If I set up this circuit as shown, do you think it would work as intended?

Image

I think you have your Opto Isolator connected in reverse , Check this out.

5v/ 12v ---------------( R )----------------( a Opto k )------------------Ground
3.3v-------------------------------------------- -( c T e )---------------- GPIO I/P-----------(10kr )------------Ground

Calculate R to give 10ma for Opto Transmitter LED


Have not shown Limit switches not to confuse things General idea of circuit

Regards BoyOh, Good to see someone with interest in drawing circuits
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

pidd
Posts: 724
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Wed Jun 10, 2020 5:36 pm

You have your optocouplers the wrong way round , the diode (LED) goes to the switches, the transistor end goes to the Pi.

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

Re: Choosing: Pull Up or Pull Down Resistor

Thu Jun 11, 2020 12:06 am

mogo4414 wrote:
Sun Jun 07, 2020 7:48 pm
With consideration to the internal pull-up / pull-down resistor functionally in the raspberry pi; is either better for long distance transmission of a signal?
Pull-up with switch to ground is definitely the way to go. Running positive DC voltages any distance is not smart should any shorts or other issues arise.

Relays, optos, exotic serial devices and protocols, etc are very cool but unlikely serve any real purpose. IME just the built-in Pi pullup is generally more than adequate. If anything a small (100r-1k) series resistor to save the Pi from those evil AM radio stations and other EMI. Twisted pair works a treat to minimize these or coax for really noisy environments. A small ceramic cap to ground for those unfamiliar with debounce routines or couple cheap diodes for protection may make more sense.

I currently have several push-buttons at the end of 150'+ wires using the gpio-key device tree overlay in config.txt. Not shielded or even twisted, just old ribbon cable. No coding or programs needed either. The default 300ms debounce is working flawlessly for many months now. My house is almost two centuries old with unshielded AC in noisiest neighborhood (spot welders next door) yet no problemo.

A long long time ago an engineer friend of mine who owns a security business suggested I wire the premises like that. I told him too much noise and leakage in wire. He said his huge factory and office building installs use miles of foil and wire w/o issue. As a test I had about 4 miles of CAT5 pairs on spools and bet him it wouldn't work. Very surprised the resistance was measures in tens of megohms. The lesson cost me ten bucks but worth it.

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Thu Jun 11, 2020 1:43 am

Hello,

I purchased the opto-isolators last night so I'm going to give that a try.

So i measured the resistance in the wire I'm using. For an approximate 100 ft strand the resistance was 2.5 ohms. So considering the wire back to GND, that would be a total of 5 ohms per 100 ft. (0.05 ohms/ft)

Additionally, I was hoping to design this to be adaptable from say 15ft to 1000 ft. (If this isn't possible, I can adjust to a smaller range.)

This gives me an added wire resistance of .75 ohms (.05*15 ft) for 15 ft, and 50 ohms (.05*1000 ft) for 1000 ft.

Thus if anyone has an accepted amperage range for the opto-isolator, I can determine an acceptable resistor for this range.

The equation to determine a resistor that would work at both wire lengths. (If one exists, that is.):

I = V/R

I (Upper Limit) = 5v / (.75 ohms + selected resistor) --&-- I (Lower Limit) = 5v / (50 ohms + selected resistor)


I included the specs of the optoisolator I bought for reference:

Product description
Part Status:Active
Number of Channels:1
Voltage - Isolation:5000Vrms
Current Transfer Ratio (Min):200% @ 5mA
Current Transfer Ratio (Max):400% @ 5mA
Turn On / Turn Off Time (Typ):-
Rise / Fall Time (Typ):4µs, 3µs
Input Type:DC
Output Type:Transistor
Voltage - Output (Max):80V
Current - Output / Channel:50mA
Voltage - Forward (Vf) (Typ):1.2V
Current - DC Forward (If) (Max):50mA
Vce Saturation (Max):200mV
Operating Temperature:-40°C ~ 100°C
Mounting Type:Through Hole
Package / Case:4-DIP (0.300", 7.62mm)
Supplier Device Package:4-DIP


Any thoughts?

pidd
Posts: 724
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Thu Jun 11, 2020 1:08 pm

Unfortunately the specs don't give you the maximum LED current nor the LED voltage drop.

User avatar
davidcoton
Posts: 5084
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Thu Jun 11, 2020 8:54 pm

mogo4414 wrote:
Thu Jun 11, 2020 1:43 am
Thus if anyone has an accepted amperage range for the opto-isolator, I can determine an acceptable resistor for this range.

I included the specs of the optoisolator I bought for reference:
...
The spec as quoted suggests a design diode current of 5mA, a maximum If of 50mA, and a typical Vf of 1V2.
It is a little confusing trying to separate input and output data, I may have read it wrongly.
To find something more explicit, you will need to find the manufacturer's part number and Google for the data sheet.
Signature retired

pidd
Posts: 724
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Thu Jun 11, 2020 11:15 pm

davidcoton wrote:
Thu Jun 11, 2020 8:54 pm
mogo4414 wrote:
Thu Jun 11, 2020 1:43 am
Thus if anyone has an accepted amperage range for the opto-isolator, I can determine an acceptable resistor for this range.

I included the specs of the optoisolator I bought for reference:
...
The spec as quoted suggests a design diode current of 5mA, a maximum If of 50mA, and a typical Vf of 1V2.
It is a little confusing trying to separate input and output data, I may have read it wrongly.
To find something more explicit, you will need to find the manufacturer's part number and Google for the data sheet.
You could well be right and it looks reasonable, I thought 1.2V vf for the transistor was a bit unusable, I read it differently but as you say they are confusing.

I haven't noticed the transition voltages for the GPIO inputs in my travels yet.

User avatar
davidcoton
Posts: 5084
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Choosing: Pull Up or Pull Down Resistor

Fri Jun 12, 2020 12:17 am

pidd wrote:
Thu Jun 11, 2020 11:15 pm
I haven't noticed the transition voltages for the GPIO inputs in my travels yet.
Try this.
Signature retired

mogo4414
Posts: 56
Joined: Fri Mar 27, 2020 1:10 am

Re: Choosing: Pull Up or Pull Down Resistor

Fri Jun 12, 2020 2:20 am

Update:

I got the opto-isolators in earlier today and got the circuits set up for a small scale test. I just ran my code (un-altered) and it worked perfectly!

For reference I calculated the resistor value to be 1333R (ended up using the 1200R resistors I had) with the following conditions:

Voltage = 5v off pi
Amperage = 5 mA (As specified by the opto-isolator manufacturer.)

For the resistors I calculated the equivalent resistance considering that each of the limit switches would for 99.9% of the time have 1 constant connection, therefore for two limit switches this is two resistors in parallel. (1/Rtotal = 1/R1 + 1/R2)

--

Tomorrow I am going to test the long distance wire, so hopefully that will work as well.

Thank you to everyone that took the time to help me out. I really appreciate it!

If anyone has any comments about things to look out for during an opcto-isolators use, I'd be happy to hear. I'm just hoping I did all my calculations correct and the LED doesn't burn out or I inadvertently fry my pi!

Return to “Beginners”