Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set() and output() always return 1 when using gpio.HIGH and gpio.LOW #6

Closed
ghuband opened this issue Oct 3, 2017 · 3 comments
Closed
Labels

Comments

@ghuband
Copy link

ghuband commented Oct 3, 2017

# python
Python 2.7.11 (default, Feb 15 2017, 21:16:35) 
[GCC 5.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gpio
>>> ch="43"
>>> gpio.setup(ch,gpio.OUT)
DEBUG:gpio:Setup 43: out
DEBUG:gpio:writing: <open file '/sys/class/gpio/gpio43/direction', mode 'w+' at 0x769da180>: out
DEBUG:gpio:Write 43: 0
DEBUG:gpio:writing: <open file '/sys/class/gpio/gpio43/value', mode 'w+' at 0x769da128>: 0
>>> gpio.set(ch,gpio.HIGH)
DEBUG:gpio:Write 43: 1
DEBUG:gpio:writing: <open file '/sys/class/gpio/gpio43/value', mode 'w+' at 0x769da128>: 1
>>> gpio.set(ch,gpio.LOW)
DEBUG:gpio:Write 43: 1
DEBUG:gpio:writing: <open file '/sys/class/gpio/gpio43/value', mode 'w+' at 0x769da128>: 1

Using True and False works correctly.

@vitiral
Copy link
Owner

vitiral commented Oct 3, 2017

what do you mean "return 1" -- do you mean the pin value is 1? set() doesn't return anything...

Set is defined as:

def set(pin, value):
    '''set the pin value to 0 or 1'''
    value = int(bool(value))
    ...

Both gpio.IN and gpio.OUT are "truthy" in python, which is why it is always one.

There could be an assertion that makes sure the value is 0 or 1 instead of the int(bool(value)) that is going on -- although that is a breaking change so I don't think I'm interested in it.

@vitiral vitiral closed this as completed Oct 3, 2017
@ghuband
Copy link
Author

ghuband commented Oct 3, 2017

From the python raspberry pi gpio documentation:
https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/

Output
To set the output state of a GPIO pin:
GPIO.output(channel, state)
(where channel is the channel number based on the numbering system you have specified (BOARD or BCM)).
State can be 0 / GPIO.LOW / False or 1 / GPIO.HIGH / True.

Your set() and output() functions do not work correctly when using gpio.HIGH and gpio.LOW. At least document that these functions only work when using True or False.

@vitiral
Copy link
Owner

vitiral commented Oct 3, 2017

oh, I misread. Thanks for the bug and sorry about the confusion.

@vitiral vitiral reopened this Oct 3, 2017
@vitiral vitiral added the bug label Oct 3, 2017
@vitiral vitiral closed this as completed in 9f62007 Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants