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

Issue with watcher on Pi Zero #1

Open
curiositry opened this issue Apr 18, 2017 · 6 comments
Open

Issue with watcher on Pi Zero #1

curiositry opened this issue Apr 18, 2017 · 6 comments

Comments

@curiositry
Copy link

curiositry commented Apr 18, 2017

Hello Brian,

I’m using the latest Raspbian image on Raspberry Pi Zero + Zero Ws, I can read a pin manually without issue, but I haven’t gotten any action out of the watcher. I have two questions:

  1. Has the library been tested on the Zero / Zero W before? If not, is there any reason to think it might not be compatible?

  2. I’m using BCM pin 7 (physical pin 26) as an input. As far as I understood, the kernel uses BCM numbering; pin := gpio.NewInput(7) works, so is there any reason why watcher.AddPin(7) wouldn’t?

Thanks for your help!

@curiositry curiositry changed the title Clarification about pin numbering Issue with watcher on Pi Zero Apr 18, 2017
@brian-armstrong
Copy link
Owner

Hi @curiositry,

Sorry to hear it didn't work. I don't know if the Zero has been tried but can't think of any specific reason it wouldn't work.

Just to confirm, do you have a /sys/class/gpio directory?

@curiositry
Copy link
Author

Thanks for responding @brian-armstrong — yes, /sys/class/gpio does exist.

@brian-armstrong
Copy link
Owner

@curiositry I can think of one thing, after rereading some of my code. It looks like the Watcher will not fail gracefuly if you Close it before calling Watch. If you did that, Watch would just hang forever.

Just to be sure, could you share the code that uses the Watcher, or make sure that it isn't somehow getting Closed prematurely?

@curiositry
Copy link
Author

curiositry commented Apr 19, 2017

@brian-armstrong Thanks for your help. Here are the relevant portions (I was basically just testing it with what’s in the README):

pin := gpio.NewInput(7)
fmt.Println(pin.Read())
watcher := gpio.NewWatcher()
watcher.AddPin(7)
defer watcher.Close()

for {
    fmt.Println("Starting watcher.")
    pin, value := watcher.Watch()
    fmt.Print("Watcher value: ")
    fmt.Println(pin)
    fmt.Print(value)
}

It would hang at pin, value := watcher.Watch() without printing anything.

@olb17
Copy link
Contributor

olb17 commented Jan 15, 2018

Hi Brian

I had similar experience with go 1.9 and a raspberry pi model 1. I tracked the issue down to the way the fdset is built in the watcher :
fdset.Bits[val/64] |= 1 << uint(val) % 64 is not working on my set-up.

and should be fixed as fdset.Bits[val/64] |= 1 << (uint(val) % 64)

https://play.golang.org/p/HyV6wX-aihG

I propose you a PR to fix this.

@lsdev75
Copy link

lsdev75 commented Oct 17, 2018

Hello,
I've go 1.9.7 and the code is correctly fixed as per last olb17 message, but after some acquisitions the Watcher stops to detect pin changes even if using 'cat' I can see the gpio change.
I want to detect the falling edge so I put Falling instead of Both inside the watcher.

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

4 participants