uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

How do I output power to GPIO pin?

Tue Mar 07, 2017 9:44 am

I have GPIO to USB adaptor (https://shop.pimoroni.com/products/usb- ... oCm9fw_wcB). There is a small light connected to the USB end. I have 4 TTL cables Red, Black, Green and White. By black cable is in pin 6 (ground) , white in pin 8 and green in pin 10. I wrote a script to control the GPIO14 and GPIO15, but the light is not switching on. It does switch on when I connect red wire to 3v3 power or 5v power but I read that individual GPIO ports do provide 3v3 power, but how do I make it work?

Code: Select all

import RPi.GPIO as io
import time

io.setmode(io.BCM)
io.setwarnings(False)

ioG = [14, 15] #14 - white / 15 - Green

io.setup(ioG, io.OUT)
io.output(ioG, True)
print "LED on"

time.sleep(5)

io.output(ioG, False)
print "LED off"

io.cleanup()

PiGraham
Posts: 3932
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 10:02 am

You plug it into a USB port. Do you understand what the cable is for? I provides a serial interface for your PC (or other USB host device). The wires at the other end of the cable are the serial data wires, a ground and a power supply drawn from the USB port that can be used to power low current devices. The red wire will not power a Pi and you should leave it disconnected. You would connect the data wires Rx and Tx to the Pi's UART pins Tx and Rx. Connect ground to Pi Ground (0V). Run a serial terminal program (e.g. putty) on your PC and, if you set the baud rate correctly, you should see boot messages from the Pi and be able communicate with the Pi command line from the serial terminal on your PC.

That Pimoroni page you linked to shows the Pi connections. It shows the red wire connected to Pi 5V but I recommend you do not connect it.
Image

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 10:32 am

PiGraham wrote:You plug it into a USB port. Do you understand what the cable is for? I provides a serial interface for your PC (or other USB host device). The wires at the other end of the cable are the serial data wires, a ground and a power supply drawn from the USB port that can be used to power low current devices. The red wire will not power a Pi and you should leave it disconnected. You would connect the data wires Rx and Tx to the Pi's UART pins Tx and Rx. Connect ground to Pi Ground (0V). Run a serial terminal program (e.g. putty) on your PC and, if you set the baud rate correctly, you should see boot messages from the Pi and be able communicate with the Pi command line from the serial terminal on your PC.

That Pimoroni page you linked to shows the Pi connections. It shows the red wire connected to Pi 5V but I recommend you do not connect it.
Image
I do understand the purpose of the cable. But I want to control power given to one of my USB's, as there is no possibility to turn on and off individual USB ports through Raspberry Pi, I bought this cable to switch off and on a lamp attached to the USB with the use of software. I do not want to power or communicate with the Pi through this cable. I just want to output power to the lamp and be able to switch it on on off with a code running in the background, or a sensor which would be in next development phase.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 11:25 am

uzierek wrote: I just want to output power to the lamp and be able to switch it on on off with a code running in the background, or a sensor which would be in next development phase.
Then you have purchased the wrong thing. The device you have purchased is a USB to Serial adaptor.
If you wish to control the power to external devices then you have a few options.
1. A Bipolar Junction Transistor
2. A Field Effect Transistor (FET)
3. A Relay (Electro-mechanical switch)
And there are several other more specialized 'switches' depending on what you want to power, how much power it needs, AC or DC etc.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

PiGraham
Posts: 3932
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 11:37 am

uzierek wrote: I do understand the purpose of the cable. But I want to control power given to one of my USB's
Then you don't understand the what that cable is for. It won't do that.

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 11:55 am

scotty101 wrote:
Then you have purchased the wrong thing. The device you have purchased is a USB to Serial adaptor.
If you wish to control the power to external devices then you have a few options.
1. A Bipolar Junction Transistor
2. A Field Effect Transistor (FET)
3. A Relay (Electro-mechanical switch)
And there are several other more specialized 'switches' depending on what you want to power, how much power it needs, AC or DC etc.
How do I then connect this transistor to USB? Could you send me a link to a device that will output 5v to USB and I can connect it to Raspberry Pi and program the switch? I can't find appropriate solution.

PiGraham
Posts: 3932
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 12:00 pm

uzierek wrote: How do I then connect this transistor to USB? Could you send me a link to a device that will output 5v to USB and I can connect it to Raspberry Pi and program the switch? I can't find appropriate solution.
You don't. What are you trying to do? The power to the USB ports is not switched. If you just want to switch something on and off you can use a transistor on gpio to switch 5V supply (or other voltage)

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 12:07 pm

PiGraham wrote:
You don't. What are you trying to do? The power to the USB ports is not switched. If you just want to switch something on and off you can use a transistor on gpio to switch 5V supply (or other voltage)
I have USB lamp like this: http://www.ikea.com/gb/en/products/ligh ... C%7C%7C%7C, which I want to switch off and on using python code from Raspberry Pi, How to achieve this in a simplest form?

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 12:10 pm

PiGraham wrote:
Then you don't understand the what that cable is for. It won't do that.
Alright I though the cable could serve for range of purpose, as it can technically give out power, and I thought I could control GPIO ports by switching them on and off. But I realised that power and ground pins are not controllable and that different GPIO can also give out power so I thought I could control the power through them.

PiGraham
Posts: 3932
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 12:18 pm

You could wire transistor awitched power to a USB socket
You could cut the USB plug off the lamp and wire it direct to a transistor switch.
https://www.sparkfun.com/products/12700

Image

Leave D+ and D- unconnected and just wire to the VCC and GND connections.

Some soldering will be required.

Search for "raspberry transistor" and you should get lots of hits.

Takke a look at Using an NPN transistor here: http://elinux.org/RPi_GPIO_Interface_Circuits

Image

Connect your lamp as the "load" in that diagram.
Last edited by PiGraham on Tue Mar 07, 2017 12:21 pm, edited 1 time in total.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 12:21 pm

uzierek wrote:

Alright I though the cable could serve for range of purpose, as it can technically give out power - It can supply power but it is not controllable


and I thought I could control GPIO ports by switching them on and off. - You can control GPIO pins by switching them on and off, just not with that USB-Serial converter. There are many software libraries to control the Pi's GPIO pins.

But I realised that power and ground pins are not controllable - Correct

and that different GPIO can also give out power so I thought I could control the power through them - The GPIO pins can supply a very small amount of power, milliamps of power, the idea is that you use the pins to control devices such as transistors which then allow you to control the flow of power to devices requiring more power
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 2:08 pm

PiGraham wrote:You could wire transistor awitched power to a USB socket
You could cut the USB plug off the lamp and wire it direct to a transistor switch.
https://www.sparkfun.com/products/12700

Image

Leave D+ and D- unconnected and just wire to the VCC and GND connections.

Some soldering will be required.

Search for "raspberry transistor" and you should get lots of hits.

Takke a look at Using an NPN transistor here: http://elinux.org/RPi_GPIO_Interface_Circuits

Image

Connect your lamp as the "load" in that diagram.
As the cable that I already have, is able to provide power through black and red cable, if I can connect it to the transistor and the other part to the lamp, then attach the transistor to GPIO pins (Base) to control if it is high or low. Would that workaround work? Do I need the resistor? I do not have a breadboard and rather not use it as, this will be mounted on production line where I we do not want many more cables.

Would these transistors be alright? https://www.amazon.co.uk/d/Home-Kitchen ... npn+2n2222

Ernst
Posts: 1334
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 2:20 pm

uzierek wrote: As the cable that I already have, is able to provide power through black and red cable, if I can connect it to the transistor and the other part to the lamp, then attach the transistor to GPIO pins (Base) to control if it is high or low. Would that workaround work? Do I need the resistor? I do not have a breadboard and rather not use it as, this will be mounted on production line where I we do not want many more cables.
You must understand that you do not have a cable, what you got is a delicate electronic device created to interface 3.3V level serial port signals to a computer using an serial to USB converter in the USB plug.

The purpose of the black/red cables is to supply 5V from the computer to the device with the serial interface, the same supply is also used to power the digital circuit in the USB plug.
The road to insanity is paved with static ip addresses

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 2:48 pm

Ernst wrote: You must understand that you do not have a cable, what you got is a delicate electronic device created to interface 3.3V level serial port signals to a computer using an serial to USB converter in the USB plug.

The purpose of the black/red cables is to supply 5V from the computer to the device with the serial interface, the same supply is also used to power the digital circuit in the USB plug.
Alright so what i need is https://www.sparkfun.com/products/12700. This to connect lamp to the NPN transistor.

Transistor: https://www.amazon.co.uk/d/Home-Kitchen ... npn+2n2222. Which will be connected to the Female USB Breakout (VCC and GND) and any GPIO Pin on Raspberry Pi.

With the use of those cables: http://www.ebay.co.uk/itm/3Pcs-40P-20cm ... SwNRdYBBzc.

Is this correct?

PiGraham
Posts: 3932
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: How do I output power to GPIO pin?

Tue Mar 07, 2017 3:19 pm

I think you should start as simple as possible. Work through the tutorials:
https://www.raspberrypi.org/learning/ph ... th-python/

uzierek
Posts: 63
Joined: Tue Mar 07, 2017 9:35 am

Re: How do I output power to GPIO pin?

Fri Sep 22, 2017 2:25 pm

PiGraham wrote:
Tue Mar 07, 2017 3:19 pm
I think you should start as simple as possible. Work through the tutorials:
https://www.raspberrypi.org/learning/ph ... th-python/
I agree this will help me a lot with my understanding. After a couple of months, I realise how stupid I was asking the question multiple times instead of thinking and understanding.

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

Re: How do I output power to GPIO pin?

Fri Sep 22, 2017 4:28 pm

uzierek wrote:
Fri Sep 22, 2017 2:25 pm
After a couple of months, I realise how stupid I was asking the question multiple times instead of thinking and understanding.
That is not necessarily stupid, it's part of the learning process. Especially when you have a wrong understanding to unlearn, so that the new answers conflict with what you think you know. :roll: :o :shock: :? :lol:
Signature retired

Return to “Beginners”