I am a beginner learning how to operate the gpio of a Raspberry Pi 5. I’ve heard that the gpiod nor many other Pi-5 compatible libraries do not support pwm. This leaves me with not many options but to operate my own makeshift pwm. To do this I set up an led and wrote the code. My code turns on an led, sleeps, then turns the led off:
import gpiod
import time
chip = gpiod.Chip('gpiochip4')
yourline = chip.get_line(17)
yourline.request(consumer="MYDEVICE", type=gpiod.LINE_REQ_DIR_OUT)
while True:
yourline.set_value(1)
time.sleep(0.008)
yourline.set_value(0)
time.sleep(0.008)
The problem is that when I switch the 0.008 frequency to a number slightly slower, like 0.01, I can visibly see the led flashing instead of the smooth light it should be. I think that a lot of toggle delay when communicating to the pins is causing this issue, but I am not completely sure. The main issue with the toggle rate being to slow is that I am worried the makeshift pen will be compatible with more complex systems like motors or servos as they may require more accurate frequency. Could you please help me gain some clarity of this situation? Eg. Details of toggle delay; If I’ll be able to communicate with motors; ect