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

Software PWM fails to work on Pi 1 #268

Open
hackerjimbo opened this issue Mar 3, 2023 · 9 comments
Open

Software PWM fails to work on Pi 1 #268

hackerjimbo opened this issue Mar 3, 2023 · 9 comments

Comments

@hackerjimbo
Copy link

Yes, I still have an original Pi 1.

I'm porting the last piece of my Pi4J v1 software to the latest v2.3.0. It all works apart from the software PWM.

I set it up as follows:

final PwmConfig config = PwmConfigBuilder.newInstance (ctx)
                    .id ("BCM17")
                    .name ("PWM")
                    .address (17)
                    .pwmType(PwmType.SOFTWARE)
                    .initial (50)
                    .provider ("pigpio-pwm")
                    .shutdown (0)
                    .build ();
            
pwm = ctx.create (config);
            
pwm.on ();

And then move from the initial 50% duty cycle. I can print out the values of pwm.actualFrequency(), pwm.address(), pwm.dutyCycle() and pwm.isOn () and they seem to change fine.

However, it appears that the output pin is just left floating!

Any ideas? Setting the id to BCM17 was something else I found in the issues, but that doesn't seem to have helped.

@FDelporte
Copy link
Member

FDelporte commented Mar 3, 2023

I'm not sure on which pin PWM is supported on Pi 1.
We are working on a library with this info + a way to visualize it, can you check please if the provided info here can help?
https://api.pi4j.com/web/

Or does this help?
https://raspberrypi.stackexchange.com/questions/23130/defining-pwm-ports-to-be-used-on-the-gpio

@hackerjimbo
Copy link
Author

hackerjimbo commented Mar 3, 2023

Hardware PWM isn't supported on that pin, hence the use of the software one. Perhaps there is an issue with the software PWM? It worked with Pi4J v1…

@FDelporte
Copy link
Member

ah sorry, indeed I missed the PWM type setting you are using ;-)
sorry, can not immediately think of a possible cause.
I guess this page also doesn't provide a solution?
https://pi4j.com/documentation/io-examples/pwm/

@taartspi
Copy link
Collaborator

taartspi commented Mar 3, 2023

I believe Pi4j V1 used wiringPi for the native interface. V2 uses Pigpio native interface. Pigpio website says it works with any version of the Pi. I also verified your code work expectantly on a Pi4.
As you had this working with V1 we can assume your wiring is correct.
The Pi4j PWM software is not aware of the model/rev you are using, just calls the same native code on all cases.

Is your Pi1 the 26 or 40 pin connector ?

@hackerjimbo
Copy link
Author

hackerjimbo commented Mar 3, 2023

It's the original 26 pin connector. The documentation page is where I got the original code from. I'm still quite surprised at the name having to be BCM17 (in my case). That was reported as a requirement some time ago.

@hackerjimbo
Copy link
Author

hackerjimbo commented Mar 3, 2023

Well that took a long time, but I have a solution.

In the non-working code I called pwm.on () and then pwn.duty (percent). Turns out what actually works is just calling pcm.on (percent, 100) (100 Hz works for me and it's only a Pi 1).

It would appear that duty on it's own doesn't turn it on properly.

@FDelporte
Copy link
Member

Good find @hackerjimbo! Is this a missing part in the documentation, or do you think an error in the implementation?

@FDelporte
Copy link
Member

and as always, thanks for the support @taartspi :-)

@hackerjimbo
Copy link
Author

I would say it's an error in the implementation. In the non-working code I set it to be on and then just changed the duty cycle. It had an initial duty cycle (from the configuration) of 50% so I think most users would expect the on to produce an output. Changing the duty cycle using duty should continue to work.

Oh, hang on! I've just releasised. The on method isn't a request to turn it on but an inspector method to query the status. I should have done an on (true) to make it work.. So maybe it's my fault after all!

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