Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Basic connections to GPIO pins

Fri Feb 08, 2019 10:56 am

I’m new to Raspberry Pi and I initially want to experiment with using the GPIO pins to switch low voltages and to sense open or closed circuits. I have done this before with BBC micros etc but am aware there is no protection interface if I connect directly to GPIO pins. I have bought a P2711A Pi-EzConnecr Terminal Block HAT.
So, for a start, I want to be able to get the Pi to switch a small relay and to sense whether a LDR is on or off. The relay will switch a small 12v motor.
- I’m assuming I can’t connect a relay actuation coil directly to a pair of GPIO pins. How would I safely make an interface?
- I made a bit of electronics to turn the LDR into a simple ON/OFF. Can I connect this directly to GPIO pins?
- once I’ve safely set these two items up, I then need to discover how to write a short loop of code to do the control bit.

[Pi 3 model B+] On the steep bit of the learning curve. I have the Raspberry Pi User Guide by Eben Upton & Gareth Halfacree.
Any very basic guwidance will be greatly appreciated.

B.Goode
Posts: 7699
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Basic connections to GPIO pins

Fri Feb 08, 2019 12:16 pm

This Raspberry Pi Foundation documentation might be a little beneath your level of knowledge and experience, but perhaps it will provide some background and 'levelling-up'?

https://projects.raspberrypi.org/en/pro ... -computing

Andyroo
Posts: 2834
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Basic connections to GPIO pins

Fri Feb 08, 2019 12:23 pm

Welcome to the world of burnt fingers :D (Still have to learn which end of the iron is hot some days :oops: )

A great free resource is the past magazines https://www.raspberrypi.org/magpi/issues/ - you can buy printed copies locally in magazine shops or set up a subscription and get a free PI at the moment

For very basic electronics connected to the PI - https://www.raspberrypi.org/magpi/issue ... o-zero-v1/ and a quick search on this forum will turn up advice about Ohms Law and starting simply.

You may like to have a look at the CamJam kits - great value for the money and you end up with some solid knowledge https://thepihut.com/collections/raspbe ... les/CamJam (stocked by other suppliers as well)

Do not be afraid to go through some of the tutorials on this site either https://projects.raspberrypi.org/en - they look at little childish but are full of knowledge :lol:

Also find out if you have a local Maker group or Raspberry Jam - you may have to fight off 7-12 year olds for a seat (they bite) but the organisers will make you welcome and help you through the worksheets. If you time it right they often have free cake as well :o
Need Pi spray - these things are breeding in my house...

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Sat Feb 09, 2019 8:25 am

Hi again. Thanks for these replies. I’m now working through the links given. The Python syntax isn’t miles away from BBC BASIC so it’s not going to be a problem although I’ve yet to find a list of syntax. Hopefully, one of those links will lead me to something. I could really benefit from a local user group but there’s nothing near.
Does anyone know if there’s a HAT that will work as a buffer-box so that items such as relays, motors and input devices can be directly connected?
Thanks again.

B.Goode
Posts: 7699
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Basic connections to GPIO pins

Sat Feb 09, 2019 10:09 am

. The Python syntax isn’t miles away from BBC BASIC so it’s not going to be a problem although I’ve yet to find a list of syntax.

https://docs.python.org/3/reference/

markkuk
Posts: 92
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: Basic connections to GPIO pins

Sat Feb 09, 2019 10:22 am

Sidintheshed wrote:
Sat Feb 09, 2019 8:25 am
Does anyone know if there’s a HAT that will work as a buffer-box so that items such as relays, motors and input devices can be directly connected?
Adafruit CRICKIT HAT: https://learn.adafruit.com/adafruit-cri ... -computers
Pimoroni Automation HAT: https://shop.pimoroni.com/products/automation-hat

B.Goode
Posts: 7699
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Basic connections to GPIO pins

Sat Feb 09, 2019 10:24 am

Does anyone know if there’s a HAT that will work as a buffer-box so that items such as relays, motors and input devices can be directly connected?

Examples:
https://rasp.io/prohat/

http://www.sf-innovations.co.uk/custard-pi-5.html

https://www.diymat.co.uk/product/8x-adc ... rsal-zero/

That's just to demonstrate that solutions are available, no doubt there are others. As @markkuk has shown while I was typing this...


(I have the Rasp.io version. I have no experience of the other products.)

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Sun Feb 10, 2019 7:44 am

Many thanks for these replies. Lots of useful stuff here. I can see that I need to develop my knowledge and understanding of the pi and of Python considerably before I can make an informed choice of a HAT to do the things I want. There’s a massive gap between my current knowledge and the knowledge level I need to understand the specifications of these modules. I need to bridge that gap in manageable steps.
I can see that some of the suggested HATs can have relays, motors and inputs connected directly to them and that a separate 5v supply will power these items. (Am I right, of have I misunderstood?) I quite like the idea of the board that includes indicator LEDs to show when inputs/outputs are working.
Having connected something, I then need to write a short piece of code that can then (for example) switch on/off a motor. I need to find an example piece of code that will do this so that I have a starting point. To (hopefully) help with this, I have bought a robot kit from PiHut to get me started. I am also working through the tutorials on the .org website.
When I bought the pi, I had no clue that it was so capable and that so much was possible.
Thanks again.

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

Re: Basic connections to GPIO pins

Mon Feb 11, 2019 4:42 pm

The Raspberry Pi is not PLUG & PLAY. Only experiment
With the GPIOs when you know what you are doing
I suggest you use the GPIOs low current /low voltage
Out/puts to switch buffer stages that need higher
Voltage and Current, Employ some OHMS LAW
In your project, Do some work on a breadboard
Using 3.3v DON’T use the Pi power for this.
Regards BoyOH Retired Electrical / Electronic Technician
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Mon Feb 11, 2019 10:16 pm

boyoh wrote:
Mon Feb 11, 2019 4:42 pm
The Raspberry Pi is not PLUG & PLAY. Only experiment
With the GPIOs when you know what you are doing
I suggest you use the GPIOs low current /low voltage
Out/puts to switch buffer stages that need higher
Voltage and Current, Employ some OHMS LAW
In your project, Do some work on a breadboard
Using 3.3v DON’T use the Pi power for this.
Regards BoyOH Retired Electrical / Electronic Technician
Thanks for your reply. I certainly don’t want plug and play. To be honest, my main objective with the pi is to learn some stuff and use that learning to do something a bit imaginative during the dark winter evenings. I have just discovered how to connect breadboard to Pi from watching some YouTube. The example I watched simply showed control of an LED using 3.3v from GPIO. I can see how I can develop from there using a potential divider to switch an independent current. Does that sound okay?
I reckon I’ll be ordering some breadboard and jumper wires soon. I’ll also need to find somewhere to buy electronic components in small quantities. Pity about Maplin.
Whenever I have started to learn something new before, I have always had someone with a bit more experience to talk with and answer my seemingly obvious questions. A local user group would be good but there’s nothing here.
Thanks again for your reply.

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

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 12:07 am

Sidintheshed wrote:
Mon Feb 11, 2019 10:16 pm
boyoh wrote:
Mon Feb 11, 2019 4:42 pm
The Raspberry Pi is not PLUG & PLAY. Only experiment
With the GPIOs when you know what you are doing
I suggest you use the GPIOs low current /low voltage
Out/puts to switch buffer stages that need higher
Voltage and Current, Employ some OHMS LAW
In your project, Do some work on a breadboard
Using 3.3v DON’T use the Pi power for this.
Regards BoyOH Retired Electrical / Electronic Technician
Thanks for your reply. I certainly don’t want plug and play. To be honest, my main objective with the pi is to learn some stuff and use that learning to do something a bit imaginative during the dark winter evenings. I have just discovered how to connect breadboard to Pi from watching some YouTube. The example I watched simply showed control of an LED using 3.3v from GPIO. I can see how I can develop from there using a potential divider to switch an independent current. Does that sound okay?
I reckon I’ll be ordering some breadboard and jumper wires soon. I’ll also need to find somewhere to buy electronic components in small quantities. Pity about Maplin.
Whenever I have started to learn something new before, I have always had someone with a bit more experience to talk with and answer my seemingly obvious questions. A local user group would be good but there’s nothing here.
Thanks again for your reply.
I’m not a great believer in using potential dividers as voltage levellers
I like to use opto isolators or transistor circuits, no guesswork.
If you use a potential divider to switch current above low signal
Level, make sure the current through the divider is ten times
Greater than you want to take off it. You can’t have 10ma through
The divider and expect to take 20ma off it’

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

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 278
Joined: Fri Jan 06, 2012 7:46 pm

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 5:45 am

Sidintheshed wrote:
Sun Feb 10, 2019 7:44 am
Many thanks for these replies. Lots of useful stuff here. I can see that I need to develop my knowledge and understanding of the pi and of Python considerably before I can make an informed choice of a HAT to do the things I want. There’s a massive gap between my current knowledge and the knowledge level I need to understand the specifications of these modules. I need to bridge that gap in manageable steps.
I can see that some of the suggested HATs can have relays, motors and inputs connected directly to them and that a separate 5v supply will power these items. (Am I right, of have I misunderstood?) I quite like the idea of the board that includes indicator LEDs to show when inputs/outputs are working.
Having connected something, I then need to write a short piece of code that can then (for example) switch on/off a motor. I need to find an example piece of code that will do this so that I have a starting point. To (hopefully) help with this, I have bought a robot kit from PiHut to get me started. I am also working through the tutorials on the .org website.
When I bought the pi, I had no clue that it was so capable and that so much was possible.
Thanks again.
Have a look at the documentation for the Gpiozero library. It has lots of code snippets to get you started:

https://gpiozero.readthedocs.io/en/stable/index.html

This section specifically looks at motors:

https://gpiozero.readthedocs.io/en/stab ... tml#motors

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

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 5:53 am

Sidintheshed wrote:
Mon Feb 11, 2019 10:16 pm
I’ll also need to find somewhere to buy electronic components in small quantities. Pity about Maplin.
I buy most of my components via ebay now. Some of the prices are so low that I can often buy ten or more for what one would have cost at Maplin. That means I have plenty of spares for if anything goes wrong. It is always handy to have a stock of certain values of resistors, for example.
Signature is on holiday.

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 7:43 am

boyoh wrote:
Tue Feb 12, 2019 12:07 am
]

I’m not a great believer in using potential dividers as voltage levellers
I like to use opto isolators or transistor circuits, no guesswork.
If you use a potential divider to switch current above low signal
Level, make sure the current through the divider is ten times
Greater than you want to take off it. You can’t have 10ma through
The divider and expect to take 20ma off it’

Regards BoyOh
Thanks. I’ll think again.

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 7:45 am

rpdom wrote:
Tue Feb 12, 2019 5:53 am
Sidintheshed wrote:
Mon Feb 11, 2019 10:16 pm
I’ll also need to find somewhere to buy electronic components in small quantities. Pity about Maplin.
I buy most of my components via ebay now. Some of the prices are so low that I can often buy ten or more for what one would have cost at Maplin. That means I have plenty of spares for if anything goes wrong. It is always handy to have a stock of certain values of resistors, for example.
Hmmm. I’ll have a look at eBay.
Thank you.

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 7:48 am

Forris wrote:
Tue Feb 12, 2019 5:45 am
Sidintheshed wrote:
Sun Feb 10, 2019 7:44 am
Many thanks for these replies. Lots of useful stuff here. I can see that I need to develop my knowledge and understanding of the pi and of Python considerably before I can make an informed choice of a HAT to do the things I want. There’s a massive gap between my current knowledge and the knowledge level I need to understand the specifications of these modules. I need to bridge that gap in manageable steps.
I can see that some of the suggested HATs can have relays, motors and inputs connected directly to them and that a separate 5v supply will power these items. (Am I right, of have I misunderstood?) I quite like the idea of the board that includes indicator LEDs to show when inputs/outputs are working.
Having connected something, I then need to write a short piece of code that can then (for example) switch on/off a motor. I need to find an example piece of code that will do this so that I have a starting point. To (hopefully) help with this, I have bought a robot kit from PiHut to get me started. I am also working through the tutorials on the .org website.
When I bought the pi, I had no clue that it was so capable and that so much was possible.
Thanks again.
Have a look at the documentation for the Gpiozero library. It has lots of code snippets to get you started:

https://gpiozero.readthedocs.io/en/stable/index.html

This section specifically looks at motors:

https://gpiozero.readthedocs.io/en/stab ... tml#motors
Thanks. I will have a look it this later today.

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

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 6:07 pm

Just one more bit of advice, Learn coding by all means,
But not at the expense of learning electronics. In future
Coder’s will be “ Two A Penny.” Electronic engineers will be
Worth their weight in Gold
Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

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

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 8:42 pm

boyoh wrote:
Tue Feb 12, 2019 6:07 pm
Just one more bit of advice, Learn coding by all means,
But not at the expense of learning electronics. In future
Coder’s will be “ Two A Penny.” Electronic engineers will be
Worth their weight in lead-free solder ;-)
The main reason for the Pi existing was the shortage of people learning to code.
Coders will never be "two a penny".
Signature is on holiday.

Sidintheshed
Posts: 10
Joined: Mon Feb 04, 2019 3:46 pm

Re: Basic connections to GPIO pins

Tue Feb 12, 2019 9:23 pm

rpdom wrote:
Tue Feb 12, 2019 8:42 pm
boyoh wrote:
Tue Feb 12, 2019 6:07 pm
Just one more bit of advice, Learn coding by all means,
But not at the expense of learning electronics. In future
Coder’s will be “ Two A Penny.” Electronic engineers will be
Worth their weight in lead-free solder ;-)
The main reason for the Pi existing was the shortage of people learning to code.
Coders will never be "two a penny".
Hi everyone. My main objective here is just the ‘learning’. Both coding and electronics present some exciting possibilities. The pi seems to offer opportunities for both. I also like the idea that a combination of both can be great for complex problem solving. I am too old to be thinking about career or my own future. I’m very grateful for the guidance that this forum is able to offer.
:)

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

Re: Basic connections to GPIO pins

Wed Feb 13, 2019 2:28 pm

Sidintheshed wrote:
Tue Feb 12, 2019 9:23 pm
rpdom wrote:
Tue Feb 12, 2019 8:42 pm
boyoh wrote:
Tue Feb 12, 2019 6:07 pm
Just one more bit of advice, Learn coding by all means,
But not at the expense of learning electronics. In future
Coder’s will be “ Two A Penny.” Electronic engineers will be
Worth their weight in lead-free solder ;-)
The main reason for the Pi existing was the shortage of people learning to code.
Coders will never be "two a penny".
Hi everyone. My main objective here is just the ‘learning’. Both coding and electronics present some exciting possibilities. The pi seems to offer opportunities for both. I also like the idea that a combination of both can be great for complex problem solving. I am too old to be thinking about career or my own future. I’m very grateful for the guidance that this forum is able to offer.
:)
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

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

Re: Basic connections to GPIO pins

Wed Feb 13, 2019 2:32 pm

Sidintheshed wrote:
Tue Feb 12, 2019 9:23 pm
rpdom wrote:
Tue Feb 12, 2019 8:42 pm
boyoh wrote:
Tue Feb 12, 2019 6:07 pm
Just one more bit of advice, Learn coding by all means,
But not at the expense of learning electronics. In future
Coder’s will be “ Two A Penny.” Electronic engineers will be
Worth their weight in lead-free solder ;-)
The main reason for the Pi existing was the shortage of people learning to code.
Coders will never be "two a penny".
Hi everyone. My main objective here is just the ‘learning’. Both coding and electronics present some exciting possibilities. The pi seems to offer opportunities for both. I also like the idea that a combination of both can be great for complex problem solving. I am too old to be thinking about career or my own future. I’m very grateful for the guidance that this forum is able to offer.
:)
Rpdom” I see you have altered my post. Be a man and have
The guts to put your signature at the end .I see you have
Put you Photo
Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
simonov
Posts: 3
Joined: Tue May 14, 2019 3:45 pm
Location: Reno, NV, USA

Re: Basic connections to GPIO pins

Thu May 23, 2019 10:23 pm

Sidintheshed wrote:
Tue Feb 12, 2019 9:23 pm
My main objective here is just the ‘learning’. Both coding and electronics present some exciting possibilities. The pi seems to offer opportunities for both.
Next month I will turn 57 and I just bought a Pi and some books and I am teaching myself Python and how to make things move. During the day I design gun parts.

When you stop learning you stop growing. When you stop growing you stop living.
Nunc est bibendum

Return to “Beginners”