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

Exception using PWM #445

Open
DieterHolz opened this issue Feb 27, 2025 · 6 comments
Open

Exception using PWM #445

DieterHolz opened this issue Feb 27, 2025 · 6 comments
Assignees

Comments

@DieterHolz
Copy link

I tried to get the PWM example "BuzzerApp" from "pi4j-example-components" working according to blogpost https://www.pi4j.com/blog/2024/20240423_pwm_rpi5/

Code is on branch "Pi5"

As far as I remember it worked sometimes, but now it throws this exception when calling pwm.off().

The rest seems to work (the buzzer makes the expected noise)

[main] ERROR com.pi4j.plugin.linuxfs.provider.pwm.LinuxFsPwm - Invalid argument
java.io.IOException: Invalid argument
at java.base/sun.nio.ch.UnixFileDispatcherImpl.write0(Native Method)
at java.base/sun.nio.ch.UnixFileDispatcherImpl.write(UnixFileDispatcherImpl.java:65)
at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:137)
at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:102)
at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:72)
at java.base/sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:300)
at java.base/sun.nio.ch.ChannelOutputStream.writeFully(ChannelOutputStream.java:68)
at java.base/sun.nio.ch.ChannelOutputStream.write(ChannelOutputStream.java:105)
at java.base/java.nio.file.Files.write(Files.java:3510)
at java.base/java.nio.file.Files.writeString(Files.java:3727)
at java.base/java.nio.file.Files.writeString(Files.java:3667)
at com.pi4j.plugin.linuxfs.internal.LinuxPwm.setEnabled(LinuxPwm.java:244)
at com.pi4j.plugin.linuxfs.internal.LinuxPwm.disable(LinuxPwm.java:221)
at com.pi4j.plugin.linuxfs.provider.pwm.LinuxFsPwm.off(LinuxFsPwm.java:161)
at com.pi4j.catalog.components.Buzzer.off(Buzzer.java:77)
at com.pi4j.catalog.components.Buzzer.(Buzzer.java:44)
at com.pi4j.catalog.applications.BuzzerApp.main(BuzzerApp.java:56)
Exception in thread “main” com.pi4j.io.exception.IOException: Unable to disable (OFF) PWM [2] @ </sys/class/pwm/pwmchip2/pwm2>; Invalid argument
at com.pi4j.plugin.linuxfs.provider.pwm.LinuxFsPwm.off(LinuxFsPwm.java:168)
at com.pi4j.catalog.components.Buzzer.off(Buzzer.java:77)
at com.pi4j.catalog.components.Buzzer.(Buzzer.java:44)
at com.pi4j.catalog.applications.BuzzerApp.main(BuzzerApp.java:56)

pi4j.com
PWM Hardware Support on RPi5 - Pi4J
Java IO Library for the Raspberry Pi
5:11

@taartspi taartspi self-assigned this Feb 27, 2025
@taartspi
Copy link
Collaborator

taartspi commented Mar 1, 2025

@DieterHolz I set up my Pi5 using your Pi5 branch. I can go to the Application package BuzzerApp and run your app. As I don't have a buzzer just watching a connected LED and I see the program functions. This is working ok.

Is there a different manner I should us to run the application ?
Or is it just repeat execution and see if I hit the exception ?
thanks

@DieterHolz
Copy link
Author

@taartspi
It must be a setup problem of the Pi, then. The exception occurs every single time if you call pwm.off()

I've just added

dtoverlay=pwm-2chan

to the config.txt.

Is there anything else to do?

@taartspi
Copy link
Collaborator

taartspi commented Mar 3, 2025

pi@rasp5Dev:/sys/class/pwm/pwmchip2 $ ls
device export npwm power subsystem uevent unexport
pi@rasp5Dev:/sys/class/pwm/pwmchip2 $ ls
device export npwm power pwm2 subsystem uevent unexport
pi@rasp5Dev:/sys/class/pwm/pwmchip2 $

Of significance, the channel has been enabled, so pwm.off() can function.

This is my bug. If the first thing attempted is off, I do not enable channel. So, while I fix this, If your team wants to make progress on this test, in the Buzzer class, after creating the configBuilder, comment out the off().

I am busy much of Monday and Tuesday and may find it difficult to fix this that soon. Tom...

So the other night when I could not duplicate you error, I first used a pwm tests of my own and it enabled the channel, so than your tests would function for me.

@DieterHolz
Copy link
Author

Take your time.

Avoiding an initial pwm.off() is an easy, good enough workaround.

@taartspi
Copy link
Collaborator

taartspi commented Mar 3, 2025

The bug Dieter hit is specific to my provider so this case in pigpio needs separate attention

@FDelporte
Copy link
Member

@taartspi thanks, deleted, will make separate ticket

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

3 participants