Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Negativ output on GPIO's

Mon Jan 14, 2013 7:05 pm

Hello

I'm trying to get a little program working and I'm not sure whether it is my program or my circuit.
I will start with my script:

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

for i in range(1,26):
    try:
        GPIO.setup(i,GPIO.OUT)
    except:
        continue
time-sleep(1)

GPIO.cleanup()
(I tried other constellations as well)

After cleanup I do have ~-0.1V on the pins (think it's normal when positive), when running program it's -4.8V.

So GND -> Resistor -> LED -> GPIO is working.
And GPIO -> Resistor -> LED -> GND is not. (Or working with transistor)

I don't think there's something wrong with my cabling since I build a lot of other circuits.
But I don't think the script is wrong also.

Someone has any idea?

The board is Mark1 btw.

User avatar
joan
Posts: 14671
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Negativ output on GPIO's

Mon Jan 14, 2013 7:31 pm

You appear to have set the pins as outputs but have not set a level (on or off).

Also I'm not sure why you are looping over 26 pins, there aren't that many which should be used.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Mon Jan 14, 2013 7:58 pm

LED's have an anode (+) and cathode (-) pin. This means they require a specific polarity to light. When driving from the GPIO pin, you must correctly connect the LED to have it illuminate for a particular logic level. On a schematic, the anode side is represented by a triangle and the cathode is a bar (line).

To have the LED illuminate for a logic 0 (low) output, connect the anode to 3v3, the cathode to the resistor, and the other side of the resistor to the GPIO.

To have the LED illuminate for a logic 1 (high) output, connect the cathode to GND, the anode to the resistor, and the other side of the resistor to the GPIO.

Image from http://www.societyofrobots.com/electron ... rial.shtml
electronics_led_diagram.png
LED
electronics_led_diagram.png (14.31 KiB) Viewed 4154 times
Make certain your resistor is sized appropriately for the LED and voltage. A 470 ohm resistor is a good choice. Depending on the LED, a value in the range of 330 ohm to 1K ohm will work.

Enjoy!
Bill

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Mon Jan 14, 2013 9:23 pm

@bgreat:
Thanks for your post, but I have knowledge about electronics and how components work.
The voltmeter is showing negative 4.8V from GPIO output to GND.

@joan:
Sry, I had to type cause I could not copy and missed a loop.
The whole one:

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

for i in range(1,26):
    try:
        GPIO.setup(i,GPIO.OUT)
    except:
        continue

for i in range(1,26):
    try:
        GPIO.output(i,GPIO.True)
    except:
        continue
time-sleep(1)

GPIO.cleanup()
I'm looping through all, to easy work on any output.
Does not work with setting a single pin to output as well.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Negativ output on GPIO's

Mon Jan 14, 2013 10:16 pm

Sounds like voltmeter leads back to front or your gnd is not actually the same gnd as the Pi
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Negativ output on GPIO's

Mon Jan 14, 2013 10:22 pm

You are using a 5V source as your ground. Use TP2 (not TP1) as the ground for your meter.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Mon Jan 14, 2013 11:41 pm

Your code will set the pins to output, set the output to high (~3v3) and then wait one second and reset all of the pins. The GPIO.cleanup() returns the pins to an input high impedance. If you are using a typcial LCD meter, the response time is low enough that you will likely not capture the output level of the pin. It may even be possible in the high impedance state that you could have a negative potential on the pins (though unlikely it would last long enough to be measured).

If you want to test the pin levels as an output, you could use Python interactively and type the commands for each pin as you measure with the meter. Another option would be to remove the GPIO.cleanup() call at the end of your code. The next execution of the program will warn you about the pins possibly being in use, but this can be safely ignored while you are testing.

Enjoy!
Bill

User avatar
Grumpy Mike
Posts: 931
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Negativ output on GPIO's

Tue Jan 15, 2013 4:25 am

Hundi wrote:@bgreat:
Thanks for your post, but I have knowledge about electronics and how components work.
The voltmeter is showing negative 4.8V from GPIO output to GND.
No it is not. This is an imposable thing to happen. You must either have the voltmeter leads the wrong way round or you are measuring from 5V to the GPIO pin which is sat at zero volts.

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Tue Jan 15, 2013 10:28 pm

From Pin1(+3.3V) to GND or Pin2(+5V) to GND it is fine with right values.
Now measuring from GPIOx to GND is giving me the negative value.
Ground for me is Pin6.
Voltmeter is fine on every other measuring and fast enough (but tested with time 100 instead of 1 as well).
Also LEDs light up when connected GND->GPIO or V++->GND, but not GPIO->GND, tested with every constellation (All Pins output and output=true, all Pins output and output=false, all Pins input ...)

Bad thing I can't start my Pi any more.
I had it up running yesterday (without any wireing and without GPIOs connected).
I shut it down and tried to start it up today and it gets to an end very fast.
Last thing on console is:
"PANIC: Attempted to kill init!
Entering kdb (current=0xcb82ac80. pid 1) due to Keyboard Entry
"
I did that every day, but without any error until today..

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Negativ output on GPIO's

Wed Jan 16, 2013 12:07 am

Either you are counting pins wrong or have some wiring fault or some other fault in your measurements.

There is NO voltage converter on board to create any negative voltage even under fault conditions.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Wed Jan 16, 2013 12:24 am

Seems you have a corrupted SD card.

After you have your Raspberry Pi booting again, please try the following from a command prompt:

Code: Select all

[email protected] ~ $ sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(18,GPIO.OUT)
>>> GPIO.output(18,0)
>>> # Measure DC voltage on pin 12 of connector (expect 0v0 to 0v8)
...
>>> GPIO.output(18,1)
>>> # Measure DC voltage on pin 12 of connector  (expect be 2v8 to 3v3)
...
>>> GPIO.cleanup()
>>> # Measure DC voltage on pin 12 of connector (high impedance input ?v?)
...
>>> quit()
[email protected] ~ $
Also, please confirm you are measuring at the correct pins on P1 with nothing else connected to the GPIO.
Pins.jpg
Test points
Pins.jpg (25.84 KiB) Viewed 4044 times
Enjoy!
Bill

User avatar
KiltedPi
Posts: 29
Joined: Sun Nov 04, 2012 9:06 pm

Re: Negativ output on GPIO's

Thu Jan 17, 2013 7:01 pm

I would agree that if you have tried re-installing whatever linux distro you are using and on a different SD card, then the problem is not hardware, nor electronics. Its nice to see so many electronics people chiming in to help here! As I know very little about electronics and it gives me hope for my new Rpi!

I do strongly feel however this poor chap knows his silicon. So here's what I think the problem could be, from a software/networking engineer:

Could this line in the python program you are using be the problem?

Code: Select all

for i in range(1,26):
You said it was behaving like you were missing a pin by the looks of the voltage reading (I'm assuming you're reading it off a multimeter?) Well- That would be consistent with the 'for loop' error I think I have spotted here.

Code: Select all

for i in range(1,26):
Although it seems like the code here would loop through "1...2...3...->26." I don't believe this is what the code would do. You should try increasing your 'maximum' value there to the number 27.

So! Correct code! :

Code: Select all

for i in range(1,27):
I used to struggle with 'for' loops, until my lecturer explained to me to think of for loops like a ticket dispenser in a chip shop, and each ticket has a number on it. It really is a great analogy. you could have a ticket dispenser that gave numbers like "10" "20" or "30", but the iteration is always one after the other.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Thu Jan 17, 2013 9:04 pm

Good thought process, but the numbers refer to the Broadcom BCM numbering which is from GPIO 0 through GPIO 25 for Rev. 1 Raspberry Pi and GPIO 2 through 27 for Rev. 2 Raspberry Pi boards.

For reference, physical P1 pin number versus BCM GPIO number:

Code: Select all

RasPi P1 Pin   BCM GPIO R1   BCM GPIO R2   RasPi Name
============   ===========   ===========  ==========
       3           0             2           SDA0
       5           1             3           SCL0
       7           4             4           GPIO7
      11          17            17           GPIO0
      13          21            27           GPIO2
      15          22            22           GPIO3
      19          10            10           MOSI
      21           9             9           MISO
      23          11            11           SCLK
       8          14            14           TxD
      10          15            15           RxD
      12          18            18           GPIO1
      16          23            23           GPIO4
      18          24            24           GPIO5
      22          25            25           GPIO6
      24           8             8           CE0
      26           7             7           CE1
The remaining pins are 3.3v, 5v, GND, and no connection (Rev. 1 only).

Since the example was using the BCM numbering, to give complete coverage you would need:

Code: Select all

# Rev 1
for i in range(0,26):
...

# Rev 2
for i in range(0,28):
...
Or, even better:

Code: Select all

# Rev 1
for i in [0,1,4,7,8,9,10,11,14,15,17,18,21,22,23,24,25]:
...

# Rev 2
for i in [2,3,4,7,8,9,10,11,14,15,17,18,21,23,24,25,27]:
...
In BCM order for the second example... I would probably do it in P1 pin order for manual testing.

Enjoy!
Bill

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Fri Jan 18, 2013 6:40 pm

I reinstalled everything and got it running. (This time I've done a backup on another sd card..)
Just don't now why, but it is working like I expected.
I think I used the wrong pin for V++, would explain why output False would light the Leds.
Btw: Are there only two V++ (Pin 1 & 2) and one GND (pin 6) or are there more (Pin 4, 9, 14, 17, 20, 25)?
Got two images, one with these pins not set, one with V++ and GND set.
Which is correct?

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Fri Jan 18, 2013 7:12 pm

Great to see you have things working now!

Pin 1 --> 3.3 VDC
Pin 2 --> 5 VDC
Pin 6 --> GND

Both pin out images are correct. ;)

For Rev. 1 boards, pins 4, 9, 14, 17, 20, 25 were listed as "do not connect", but tied to ground. They were reserved for future use. With the Rev. 2 boards, these pins became listed as "official" ground pins.

So...
Pin 4 --> GND
Pin 9 --> GND
Pin 14 --> GND
Pin 17 --> GND
Pin 20 --> GND
Pin 25 --> GND

Enjoy!
Bill

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Negativ output on GPIO's

Fri Jan 18, 2013 7:23 pm

bgreat wrote:Great to see you have things working now!

Pin 1 --> 3.3 VDC
Pin 2 --> 5 VDC
Pin 6 --> GND

Both pin out images are correct. ;)

For Rev. 1 boards, pins 4, 9, 14, 17, 20, 25 were listed as "do not connect", but tied to ground. They were reserved for future use. With the Rev. 2 boards, these pins became listed as "official" ground pins.

So...
Pin 4 --> GND
Nope Pin 4 has always been +5V, Rev 1 and Rev 2

Even the circuit diagrams show that.

If that was not the case I have some strange Rev 1s that shorting pins 2 and 4 does NOT blow anything.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Sat Jan 19, 2013 3:18 pm

Pin 4 is +5V and Pin 17 +3.3V in this image.
Then maybe I've got a mark 2 image there.
So just using Pin 1, 2 & 6 then, thanks :)

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Negativ output on GPIO's

Sat Jan 19, 2013 4:34 pm

Yep. Error in the sheet I quickly looked at. Pin 4 is 5 VDC. I even use it for powering one of my Pi's.

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Mon Jan 21, 2013 6:57 pm

Hm, I always get an error "'module' objects has no attribute 'setmode'" when I try to set mode with

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
Haven't had it before reinstalling.

User avatar
croston
Posts: 704
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Negativ output on GPIO's

Mon Jan 21, 2013 7:02 pm

Hundi wrote:Hm, I always get an error "'module' objects has no attribute 'setmode'" when I try to set mode with

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
Haven't had it before reinstalling.
I suspect that you have installed a very old version of RPi.GPIO!

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Mon Jan 21, 2013 7:21 pm

I did that first

Code: Select all

$ wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.1.0.tar.gz
$ tar zxf RPi.GPIO-0.1.0.tar.gz
$ cd RPi.GPIO-0.1.0
$ sudo python setup.py install
And I did that after getting the problem

Code: Select all

$sudo apt-get update
$sudo apt-get install python-dev
$sudo apt-get install python-rpi.gpio
"$sudo apt-get install python-rpi.gpio" saying newest version.

User avatar
croston
Posts: 704
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Negativ output on GPIO's

Mon Jan 21, 2013 7:26 pm

Hundi wrote:I did that first

Code: Select all

$ wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.1.0.tar.gz
$ tar zxf RPi.GPIO-0.1.0.tar.gz
$ cd RPi.GPIO-0.1.0
$ sudo python setup.py install
And I did that after getting the problem

Code: Select all

$sudo apt-get update
$sudo apt-get install python-dev
$sudo apt-get install python-rpi.gpio
"$sudo apt-get install python-rpi.gpio" saying newest version.
You have both versions installed and the old version needs removing. You can find files using:

Code: Select all

$ find /usr | grep -i gpio
You need to delete the files for version 0.1.0

Hundi
Posts: 11
Joined: Mon Jan 14, 2013 6:45 pm

Re: Negativ output on GPIO's

Mon Jan 21, 2013 8:47 pm

Ok, I used a backup file where python wasn't installed.
I installed again with this part:

Code: Select all

$sudo apt-get update
$sudo apt-get install python-dev
$sudo apt-get install python-rpi.gpio
Now I got setmode running, but I can't get GPIOs running now..
3.3V and 5V are running, but just with 1V and 2.5V.
Not an easy one to get GPIO running..

Return to “Python”