0

On RPi5, it seems we have to use gpiozero.

In gpiozero, pwm output is available for various devices within a range 0 to 1.

I want to use a piezo transducer with musical frequencies from say c = 130.813 Hz ... a = 440 ... to b = 1975.53. This works fine on RPi3. I don't think that can be directly translated into the range 0 to 1, nor will that range recognise the desired accuracy.

Is there any way to achieve this in gpiozero? Might using hardware pwm be the answer?

Thanks, Trober

Trober
  • 1
  • 2

2 Answers2

1

As far as I am aware gpiozero has no support for hardware timed PWM at the moment.

You will have to use software timed PWM which is unlikely to be suitable.

Note that the Pi5 has new hardware peripherals (e.g. GPIO, PWM etc.) and it will likely be sometime before the software "catches up" with that on earlier Pi models.

joan
  • 71,852
  • 5
  • 76
  • 108
0

I don't have a Pi5 (they are not available in Australia) so I have been unable to test but I have written code using the kernel PWM driver which works fine on Bookworm.

I expect it will work on Pi5 (with a minor change to the correct gpiochip - which is probably gpiochip4 and given the kernel coders foibles will probably be called pwmchip4).

The kernel driver uses a 100MHz clock so allows resolution of period to 10 nSec which should be sufficiently accurate.

See https://raspberrypi.stackexchange.com/a/145186/8697

This code is independent of any library and could be used on its own or included in a gpiozero program.

Milliways
  • 62,573
  • 32
  • 113
  • 225