Using MicroPython v1.19 on 2022-06-23; linux [GCC 9.4.0] on a Raspberry Pi 4b #11224
Unanswered
FlydGitHub
asked this question in
Other
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi can someone help? I have tried all day to get some Mp code to run on a Raspberry pi 4b, 32 bit, current version.
I can't get past machine.Pin or use gpiozero, or Rpi.GPIO.
The code seems simple enough...
My aim is to generate a PWM interrupt as fast as the RP 4b can reasonably handle.
I'll provide two versions #1:
import time
import RPi.GPIO as GPIO
Define the maximum achievable PWM frequency in Hz
pwm_freq = 100000
Define the duty cycle (0-100)
duty_cycle = 50
Define the GPIO pin for the PWM output in BOARD mode
pwm_pin = 40
Set up the GPIO library to use board numbering mode
GPIO.setmode(GPIO.BOARD)
Configure the PWM output with the specified frequency and duty cycle
GPIO.setup(pwm_pin, GPIO.OUT)
pwm = GPIO.PWM(pwm_pin, pwm_freq)
pwm.start(duty_cycle)
Wait indefinitely
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
pwm.stop()
GPIO.cleanup()
Beta Was this translation helpful? Give feedback.
All reactions