czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

GPIO not going all the way LOW [solved]

Mon Nov 27, 2017 5:21 am

I'm controlling several GPIO pins with a Python script.

Code: Select all

import RPi.GPIO as GPIO
import time
from LS7366r import LS7366R
from time import sleep

encoder = LS7366R(1, 1000000, 4)

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

##### setup RPi GPIO pins
GPIO.setup(12, GPIO.OUT) #PWM_A
GPIO.setup(33, GPIO.OUT) #PWM_B
GPIO.setup(16, GPIO.OUT) #Low1 - Low4
GPIO.setup(15, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)

pwm1 = GPIO.PWM(33, 1000)
pwm2 = GPIO.PWM(12, 1000)

GPIO.output(16, GPIO.LOW)
time.sleep(4)

###TURN LEFT
def Left():
   GPIO.output(11, GPIO.HIGH)
   GPIO.output(13, GPIO.LOW)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(16, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)
   
###GO BACK
def Back():
   GPIO.output(11, GPIO.LOW)
   GPIO.output(13, GPIO.HIGH)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(16, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)
  
def Forward():
   GPIO.output(11, GPIO.HIGH)
   GPIO.output(13, GPIO.LOW)
   GPIO.output(16, GPIO.LOW)
   GPIO.output(15, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)

print "running"
while True:

   print "Encoder: ", encoder.readCounter()
   Left()
   time.sleep(4)
   Back()
   time.sleep(4)
   Forward()
   time.sleep(4)
pwm1.stop(pwm1)
pwm2.stop(pwm2)
GPIO.cleanup()      
When I run the script, GPIO 16 goes HIGH, but when I set it to LOW, it only goes down to 2.7 volts and therefore still reads as HIGH. If I run Python as an application in console and turn the pin LOW and HIGH, it works as expected. I've tried running without GPIO.cleanup(), but that doesn't seem to make any difference. Does anyone have any ideas why this might happen or how to fix it?

Thanks!

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

Re: GPIO not going all the way LOW

Mon Nov 27, 2017 8:25 am

Perhaps the thing connected to GPIO16 is pulling it high?

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: GPIO not going all the way LOW

Tue Nov 28, 2017 7:33 am

I was thinking that was a possibility, but it's connected to a voltage translator that merely reads the voltage then sends a different voltage to a motor driver. That also wouldn't explain why it works fine when I run Python in the console but doesn't work when I run the script.

User avatar
RaTTuS
Posts: 10381
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: GPIO not going all the way LOW

Tue Nov 28, 2017 7:41 am

show your circuit
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: GPIO not going all the way LOW

Thu Nov 30, 2017 1:06 am

Image

You can see where GPIO16 goes straight into the voltage translator. It's a fairly standard TI Bidirectional voltage translator commonly used on motor capes. I can't see any reason that it would be pulled high.

PhilBr
Posts: 61
Joined: Tue Oct 31, 2017 5:28 pm

Re: GPIO not going all the way LOW

Thu Nov 30, 2017 10:44 am

I think I would try and simplify.
Disconnect your motor stuff and run a simple program to switch that gpio pin.
If you get differences in different environments then maybe environment variables, permissions etc are the culprit.
Do let us know the outcome.
Phil

drgeoff
Posts: 9641
Joined: Wed Jan 25, 2012 6:39 pm

Re: GPIO not going all the way LOW

Thu Nov 30, 2017 12:05 pm

czyskows wrote:
Mon Nov 27, 2017 5:21 am
I'm controlling several GPIO pins with a Python script.

Code: Select all

import RPi.GPIO as GPIO
import time
from LS7366r import LS7366R
from time import sleep

encoder = LS7366R(1, 1000000, 4)

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

##### setup RPi GPIO pins
GPIO.setup(12, GPIO.OUT) #PWM_A
GPIO.setup(33, GPIO.OUT) #PWM_B
GPIO.setup(16, GPIO.OUT) #Low1 - Low4
GPIO.setup(15, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)

pwm1 = GPIO.PWM(33, 1000)
pwm2 = GPIO.PWM(12, 1000)

GPIO.output(16, GPIO.LOW)
time.sleep(4)

###TURN LEFT
def Left():
   GPIO.output(11, GPIO.HIGH)
   GPIO.output(13, GPIO.LOW)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(16, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)
   
###GO BACK
def Back():
   GPIO.output(11, GPIO.LOW)
   GPIO.output(13, GPIO.HIGH)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(16, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)
  
def Forward():
   GPIO.output(11, GPIO.HIGH)
   GPIO.output(13, GPIO.LOW)
   GPIO.output(16, GPIO.LOW)
   GPIO.output(15, GPIO.HIGH)
   pwm1.start(90)
   pwm2.start(90)

print "running"
while True:

   print "Encoder: ", encoder.readCounter()
   Left()
   time.sleep(4)
   Back()
   time.sleep(4)
   Forward()
   time.sleep(4)
pwm1.stop(pwm1)
pwm2.stop(pwm2)
GPIO.cleanup()      
When I run the script, GPIO 16 goes HIGH, but when I set it to LOW, it only goes down to 2.7 volts and therefore still reads as HIGH. If I run Python as an application in console and turn the pin LOW and HIGH, it works as expected. I've tried running without GPIO.cleanup(), but that doesn't seem to make any difference. Does anyone have any ideas why this might happen or how to fix it?

Thanks!
I don't fully understand what you are trying to do and what you mean by "When I run the script, GPIO 16 goes HIGH, but when I set it to LOW". Your script runs all of Left(), Back(), Forward(). Some of those have GPIO16 set to HIGH and some have it set to LOW. So how are you determining that "it only goes down to 2.7 volts"? Voltmeter or oscilloscope?

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: GPIO not going all the way LOW

Thu Nov 30, 2017 4:34 pm

I'm using a voltmeter on the pins.

User avatar
Burngate
Posts: 5939
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO not going all the way LOW

Thu Nov 30, 2017 6:01 pm

czyskows wrote:
Tue Nov 28, 2017 7:33 am
... connected to a voltage translator ...
czyskows wrote:
Thu Nov 30, 2017 1:06 am
(image)
You can see where GPIO16 goes straight into the voltage translator. It's a fairly standard TI Bidirectional voltage translator commonly used on motor capes.
Can you provide any information regarding this chip?
It's difficult enough trying to decipher the circuit from just a board lay-out, without having to guess part numbers!


drgeoff
Posts: 9641
Joined: Wed Jan 25, 2012 6:39 pm

Re: GPIO not going all the way LOW

Fri Dec 01, 2017 6:22 pm

czyskows wrote:
Thu Nov 30, 2017 4:34 pm
I'm using a voltmeter on the pins.
A voltmeter shows the average voltage. 2.7 volts could mean that the GPIO is going down to 0 volts for 18% of the time.

User avatar
Burngate
Posts: 5939
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO not going all the way LOW

Fri Dec 01, 2017 7:08 pm

Looking at the data sheet, I note there's a couple of packages, with different pin-outs. It looks like you've got the PWR package.
Pins.png
Pins.png (26.9 KiB) Viewed 3091 times
Your layout appears to send GPIO pin 16 to pin 2 of the chip, which is correct for the DQS package, but not for the PW package.
Could that be your problem?

Also, the inner workings of that chip are strange. They have a 4k source impedance, and a one-shot to drive it. That means the output side might be detecting a source, and causing the input side to be driven.
Architecture of TXB0108 I-O Cell.png
Architecture of TXB0108 I-O Cell.png (10.67 KiB) Viewed 3091 times

gordon77
Posts: 4081
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO not going all the way LOW

Fri Dec 01, 2017 7:13 pm

It would be good to see a schematic of that part of the design.

Why is pin 1 of the chip wired to pin 10?

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: GPIO not going all the way LOW

Sat Dec 02, 2017 5:53 am

It appears that GPIO16 is getting some amount of voltage from GPIO15, though I don't know why this is happening. It seems like I can still use the board if I set 15 and 16 to the same settings all the time, which is possible since they can be attached to different sides of the dual h-bridge. Thank you for the suggestions!

gordon77
Posts: 4081
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO not going all the way LOW

Sat Dec 02, 2017 11:10 am

"Your layout appears to send GPIO pin 16 to pin 2 of the chip, which is correct for the DQS package, but not for the PW package.
Could that be your problem?"

I am confused by the design as the DQS package shows pin 5 as Vcca when it appears to come from the GPIO pin 11.

User avatar
Burngate
Posts: 5939
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO not going all the way LOW

Sat Dec 02, 2017 12:03 pm

gordon77 wrote:
Sat Dec 02, 2017 11:10 am
I am confused
You and me, both.
Looking further at that image, almost nothing seems to go where I would have expected.
We'd all get along better if we could see a proper circuit diagram, rather than a board layout, and more than just the bit we're allowed to see.

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

Re: GPIO not going all the way LOW

Sat Dec 02, 2017 12:42 pm

its seems to me that pin 11 is connected to GND, meaning you are using the PW package of this eight-fold level converter chip, that means that PIN 16 of the GPIO header, which goes to pin 2 of the IC, actually goes to its Vcca-pin, the power supply pin of the IC.
So I don't wonder why you cannot pull the GPIO of pin 16 low.
It seems something is very wrong with your schematic, or layout here.

The operation principle of this chip seems to be that a bidirectional driver pin drives both its "left" and "right" bus pin, (each of which can both be an input and an output) weakly except for the first millisecond or so (so you still get steep flanks). the pin that drives a high impedance then takes the role of output pin, while the pin that is driven by a signal, and thus is probably the input, takes the role of the input. Its an ingenious design, the fact that a pin, and thus the bus is only driven at full force the first millisecond or so means that no transistor driving the bus heats up enough to burn out.

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: GPIO not going all the way LOW

Sun Dec 03, 2017 5:20 am

So, turns out I'm an idiot - and not that good at paying attention to details. I did in fact wire the voltage translator incorrectly. Guess I'm getting new boards printed. ; )

Image

Return to “Troubleshooting”