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

Reading the value of a GPIO pin works, but onFalling, etc. fail to trigger #141

Open
bottlehall opened this issue Aug 28, 2024 · 0 comments

Comments

@bottlehall
Copy link

bottlehall commented Aug 28, 2024

Board Type

RaspberryPi3 Model B

Operating System

Ubuntu 24.04.1 LTS

Swift Version

Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: aarch64-unknown-linux-gnu

Installed from swiftARM as binary

Description

A KY-038 sound sensor's digital output (triggered when a threshold is reached) is connected to GPIO pin 23. The board can run with 3.3-5V supply. I am running it at 5V without pull-up resistors.

I have cobbled this code from several sources. It executes without error but none of the closures are triggered.

import Foundation
import SwiftyGPIO

let gpios = SwiftyGPIO.GPIOs(for:.RaspberryPi3)
var gp = gpios[.P23]!

gp.direction = .IN
gp.bounceTime = 0.5

gp.onRaising{
    gpio in
    print("Transition to 1, current value:" + String(gpio.value))
}

gp.onFalling{
    gpio in
    print("Transition to 0, current value:" + String(gpio.value))
}

gp.onChange{
    gpio in
    gpio.clearListeners()
    print("The value changed, current value:" + String(gpio.value))
}

RunLoop.main.run()

If I replace the RunLoop.main.run() with:

while true {
    print("GPIO.value=\(gp.value)")
}

Then I can see the value changing from 0 to 1 appropriately. I have tried changing .pull but this has no effect.

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

1 participant