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

Read operation toggles GPIO port value to 0 during read operation. #16

Open
ravimindstix opened this issue Apr 21, 2014 · 4 comments
Open
Assignees

Comments

@ravimindstix
Copy link

While using the library i found out that the read operation toggles the high value of gpio port to low. I looked further in the issue, it seems that when we want only read operation , we open the port but this sets the direction to OUT by default. This causes the automatic toggle of gpio port value from 1 to 0 . I tested the issue with gpio-admin commands and when i just export the port and read the value and close port, it works fine. The moment i set the direction after exporting and try to read to the gpio port value, it changes the value of the port to 0 somehow.

The issue occurs when we try to read the port with value high or 1. It doesn't affect ports with value already 0.

@rakeshpai
Copy link
Owner

Hey @ravimindstix. It sounds like you want to set the direction to in to avoid this issue. Does that seem to work?

@ravimindstix
Copy link
Author

Hey Rakesh,

I tried all the possibilities it still turn the value of port to 0.
If you use gpio-admin commands to to read the way you have written your
library it will generate the error.
The way i checked it using gpio-admin is ,

export port, set direction , read port , close . this way it generates the
error .

if you do gpio-admin export read port and close port, it works fine.

and in your library in open function you set the direction and read
function is separate.
so by default it follows the first approach i mentioned which generates the
error.

I guess it will be good if after open we have an option to call set
direction or not , reason being read operation only read the value of the
port irrespective of the port direction.
so we don't need the set direction operation.

i guess the bug is in gpio-admin module.

Thanks & Regards
Ravi

On Mon, Apr 21, 2014 at 6:42 PM, Rakesh Pai [email protected]:

Hey @ravimindstix https://github.com/ravimindstix. It sounds like you
want to set the direction to in to avoid this issue. Does that seem to
work?

Reply to this email directly or view it on GitHubhttps://github.com//issues/16#issuecomment-40934248
.

@8eecf0d2
Copy link

Also having this issue, every time I gpio.read I need to be inside of gpio.write like so..

gpio.open(16, "output", function(err) {     // Open pin 16 for output
    gpio.write(16, 1, function() {          // Set pin 16 high (1)
    gpio.read(16, function(err, value) {
        if(err) throw err;
        console.log(value); // The current state of the pin
        gpio.close(16);
    });                    // Close pin 16
    });
});

or have a setTimeout of 600 or greater to avoid gpio-admin: could not flush data to /sys/class/gpio/*: Device or resource busy.

Either way I still end up broken as gpio.read with input set seems to toggle the value to 0 at gpio.close in all cases, which actually makes sense, but I always get a 0 when reading on output.. A method to get reliable output time after time is below but it intermittently changes the value so for the majority of projects this is pointless.

gpio.open(16, "input", function(err) {     // Open pin 16 for output
    gpio.read(16, function(err, value) {
        if(err) throw err;
        console.log(value); // The current state of the pin
        gpio.close(16);
        gpio.open(16, "output", function(err) {     // Open pin 16 for output
            gpio.write(16, 1, function() {          // Set pin 16 high (1)
                gpio.close(16);                     // Close pin 16
            });
        });
    });
});

This all seems a lot messier than gpio.read should be, hopefully I'm missing something.

@tjanson tjanson self-assigned this Oct 25, 2014
@emnik
Copy link

emnik commented Dec 15, 2015

I had the same problem while driving a relay board. Try to put a (pull down) resistor between the pin and the ground. Begin at 1KOhm and go lower. This can't do any harm so just try it ;-) Hope this helps you. I've spend much much time until I solve this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants