Comments (7)
Hi,
I think this is the same issue as #35,
There is already a warning comment in the documentation of EdgeDetect
:
// WARNING: this might make your Pi unresponsive, if this happens, you should either run the code as root,
// or add `dtoverlay=gpio-no-irq` to `/boot/config.txt` and restart your pi,
Problem is that normally the edge events produces interruptions, which are not handles by the system, and after some number of unhandled interruptions the pi freezes.
We are trying to disable the interruptions, but it only works with root:
Lines 383 to 387 in a36b96d
If you don't call
EdgeDetect(noEdge)
Close()
before your program ends, the interruptions will stay disabled until next restart of your pi, this explains the "interesting" behavior you observed.
@stianeikeland
We should probably find some better way to solve this issue.
from go-rpio.
Hm, pretty strange. When I do the same but manually using pin.Read() in cycle inside go routine - then no stuck.
But stuck only by using EdgeDetected in go routine.
And when I try to put everything inside go routine, then the device is getting stuck immediately after application runs.
go func() {
pin := rpio.Pin(10)
pin.Input()
pin.PullUp()
pin.Detect(rpio.FallEdge)
lastTime := time.Now().UnixNano() / 1000000
for {
if pin.EdgeDetected() {
now := time.Now().UnixNano() / 1000000
diff := now - lastTime
lastTime = now
fmt.Println("Heyhey!", diff)
}
time.Sleep(time.Millisecond * 35)
}
}()
UPD: strange. After reboot the stuck is happening not always after run.
The kind of random...
UPD2: for now I'm using this "rakes" to keep it working.
package main
import (
"fmt"
"github.com/stianeikeland/go-rpio"
"log"
"time"
)
// This function getting my device stuck!
func pinWatcher(pinNum uint, ch *chan int64) {
pin := rpio.Pin(pinNum)
pin.Input()
pin.PullUp()
pin.Detect(rpio.FallEdge)
lastTime := time.Now().UnixNano() / 1000000
for {
if pin.EdgeDetected() {
now := time.Now().UnixNano() / 1000000
diff := now - lastTime
lastTime = now
*ch <- diff
}
time.Sleep(time.Millisecond * 35)
}
}
// Plan B for a while...
func pinWatcher2(pinNum uint, ch *chan int64) {
pin := rpio.Pin(pinNum)
pin.Input()
pin.PullUp()
lastTime := time.Now().UnixNano() / 1000000
lastState := rpio.High
for {
state := pin.Read()
if state == rpio.High {
} else if state == rpio.Low {
if lastState == rpio.High {
now := time.Now().UnixNano() / 1000000
diff := now - lastTime
lastTime = now
*ch <- diff
}
}
lastState = state
time.Sleep(time.Millisecond)
}
}
func main() {
err := rpio.Open()
if err != nil {
log.Fatal(err)
}
ch := make(chan struct{})
gpio10pulses := make(chan int64)
go pinWatcher2(uint(27), &gpio10pulses)
go func() {
log.Println("Init reader")
for {
select {
case pin10Diff := <-gpio10pulses:
fmt.Println("Pulse", pin10Diff)
}
}
}()
fmt.Println("init")
<-ch
}
from go-rpio.
I'm wondering if this could be related how gpio memory is accessed.
Lines 634 to 637 in a36b96d
Are you running as root or regular user?
Could you try to run as root if not?
from go-rpio.
@stianeikeland I have made some experiments.
Yes, the stuck possible only if I run application as regular user. With root everything is stable.
But I found one interesting behaviour. If I run firstly with root, but then re-run with regular user - then everything good.
Pretty strange
from go-rpio.
Yes, that's it. Now everything clear.
Thank you for support and help. Basically I don't think this issue is related somehow to the library, more to raspberry workflow.
I think the issue might be closed.
from go-rpio.
And I have faced with one mandatory bug.
We are using on our terminals this displays: https://www.waveshare.com/wiki/10.1inch_HDMI_LCD#Driver
The resistive touchscreen is connecting through the GPIO pins. So, when I'm running with sudo my application with edge detection - the touchscreen is not working.
In this case I have to use manual reading inputs, no other solution for me right now.
Just FYI, or maybe for someone who will face with the same issue.
from go-rpio.
Yes, unfortunately, disabling the IRQ may cause some other GPIO libs/drivers to not working. I forgot to mention that.
from go-rpio.
Related Issues (20)
- strangely, does *not* work with sudo HOT 8
- SPI Locking? HOT 2
- Nice library but seems PWM is behaving a bit strangely HOT 3
- Dockerize? HOT 3
- [BUG] Issues using SPI and GPIO with HOT 1
- RPI 4 B PWM not working HOT 8
- cannot find package "github.com/stianeikeland/go-rpio/v4" HOT 1
- pullup does not work on RPI 4 B HOT 4
- Seems not work on Raspberry Board 4 and ubuntu server 20.04 HOT 1
- New release HOT 1
- Pico HOT 1
- Pi4 PWM frequency wrong HOT 2
- Add support for PWM "Balanced" algorithm (default BCM mode) HOT 8
- Hardlock when EdgeDetect is used HOT 5
- "Undefined: syscall"
- How to call async
- Interrupt/event based edge detection HOT 1
- seg fault on Read() HOT 2
- Misleading SPI to GPIO pin mapping in code documentation: CE0 should be mapped to GPIO 8 HOT 1
- Raspberry Pi 5 Support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-rpio.