m3istr
Posts: 5
Joined: Tue Jan 29, 2019 8:50 am

5V TTL to GPIO

Wed Feb 06, 2019 12:37 pm

Hi guys,
I know that I can't connect a 5V TTL to the GPIO without a series resistor. But to calculate the resistor, do I need the input resistance of the GPIO. I can't find this specification in the datasheet of the RPi or the BCM2835. Can somebody tell me, wher I can find this spec. Thank you.

pcmanbob
Posts: 9465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 5V TTL to GPIO

Wed Feb 06, 2019 12:46 pm

You don't want a series resistor you need a potential divider , that is 2 resistors connected in series between the 5v TTL output and ground with the pi gpio connected between the 2 resistors.



This is an example of a potential divider

Image

there are several sites that will help you select the resistors

https://www.electronics2000.co.uk/calc/ ... ulator.php

https://www.random-science-tools.com/el ... ivider.htm
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: 5V TTL to GPIO

Wed Feb 06, 2019 12:47 pm

No, you can ignore the input resistance of the GPIO, it is so high it doesn't matter. What you need to do is use two resistors to form a divider to bring the voltage down to about 3V.

5v -[2K2]---GPIO---[3K3]---0V

That should provide sufficient voltage on the GPIO pin to register from the 5V input. Total current flow through the resistors will be about a little under 1mA maximum.
[edit]
pcmanbob did a better diagram than me ;-)
His resistor values will work too, with an even lower current.
Unreadable squiggle

pcmanbob
Posts: 9465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 5V TTL to GPIO

Wed Feb 06, 2019 12:52 pm

rpdom wrote:
Wed Feb 06, 2019 12:47 pm

pcmanbob did a better diagram than me ;-)
only because in true Blue Peter fashion here's one a did earlier... showing my age now.. :lol: :lol:
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: 5V TTL to GPIO

Wed Feb 06, 2019 1:36 pm

pcmanbob wrote:
Wed Feb 06, 2019 12:52 pm
only because in true Blue Peter fashion here's one a did earlier... showing my age now.. :lol: :lol:
I still remember my 1967 Blue Peter Annual :-)
Unreadable squiggle

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

Re: 5V TTL to GPIO

Wed Feb 06, 2019 2:14 pm

m3istr wrote:
Wed Feb 06, 2019 12:37 pm
I know that I can't connect a 5V TTL to the GPIO without a series resistor.
We have been told the Pi does not have the input pin characteristics which many microcontrollers have so current limiting an over-voltage input using an in-line resistor is not suitable for a Pi.

That is what we've been told so I am not going to pick a fight arguing otherwise.

LTolledo
Posts: 3430
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: 5V TTL to GPIO

Wed Feb 06, 2019 9:10 pm

A level shifter would be nicer...
level shifter.jpg
level shifter.jpg (125.15 KiB) Viewed 1125 times
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

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

Re: 5V TTL to GPIO

Wed Feb 06, 2019 11:09 pm

Bidirectional level shifters are only needed for bidirectional signals (like I2C, but only if the I2C peripheral device demands 5V levels, most don't, and work fine with the 3V3 levels of an RPI).
for most other uses the resistor divider is the simpler, thus preferred solution.

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

Re: 5V TTL to GPIO

Thu Feb 07, 2019 8:42 am

I would be very much inclined to use a OPTO ISOLTOR to switch
The 5v TTL to the Pi 3.3v IN/PUT, and not use a divider
This will keep Bothe voltages separate, there will be no common
Connection, TTL 5v--------( R )-------( a-led k )----0v-TT
Pi 3.3v Rail--------------------------------( c T e )------3.3v( GPIO)----( 10k )---0v
R = 470r
a— led—k =.opto I/R
c T e = opto transistor
10kr Pulldown
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Return to “Beginners”