HI there, I have a script running in the pi pico using Micropython but I need it in Circuitpython. I have try several ways to read the duty cycle of a RC receiver using Circuit python but I can't make it work. These is the Micropython version. Can someone make it work in Circuit python pease?
from machine import Pin, PWM
import time
input_pin1 = Pin(17, Pin.IN) # this is GP17
while True:
for duty1 in range (3):
while input_pin1.value() == 0:
pass
start = time.ticks_us()
while input_pin1.value() == 1:
pass
end = time.ticks_us()
duty1 = end - start
print (str(duty1))
PWM dutycycle read in Circuitpython.
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- rooppoorali
- Posts: 98
- Joined: Sat Jul 16, 2022 12:04 pm
Re: PWM dutycycle read in Circuitpython.
Hi, have you seen this? https://learn.adafruit.com/circuitpytho ... python-pwm
- Kc2021
- Posts: 28
- Joined: Mon Jul 19, 2021 11:42 am
Re: PWM dutycycle read in Circuitpython.
Hi, thanks for your reply. The article explains how to output PWM while I am attempting to read PWM duty cycle.
- Rcayot
- Posts: 321
- Joined: Sat Feb 08, 2020 6:48 pm
Re: PWM dutycycle read in Circuitpython.
you can use a pin on the PICO with either pulseio, or countio. The pulseio will report the times of pulses, countio will tell you how many pulses (use time to get frequency)
Roger
Roger
- Kc2021
- Posts: 28
- Joined: Mon Jul 19, 2021 11:42 am
Re: PWM dutycycle read in Circuitpython.
That actually may work, I will try it. Thanks
- Rcayot
- Posts: 321
- Joined: Sat Feb 08, 2020 6:48 pm
Re: PWM dutycycle read in Circuitpython.
KC,
I have used both for monitoring the tachometer output of a fan controlled by PWM.
Here is the code I use with countio:
Be aware that for countio to work, you need to put it on an ODD number pin. That took me a while to figure out! Also, you will need the latest version of circuit python. The version I loaded on my PICO when I got is did not support these functions.
Good luck. Hope it works.
Roger
I have used both for monitoring the tachometer output of a fan controlled by PWM.
Here is the code I use with countio:
Code: Select all
pin_counter = countio.Counter(board.GP1, edge=countio.Edge.RISE)
async def fanspeed(interval):
initial = time.monotonic()
pin_counter.reset()
while True:
if time.monotonic() - initial >= fan_speed_time:
revs = (pin_counter.count)/2
rps = revs/(time.monotonic() - initial) #fan_speed_time
fan_speed = str(rps*60)
print("fan speed = ", fan_speed)
F2tag =str(8)
F2packet = str(F2tag + fan_speed)
initial = time.monotonic()
pin_counter.reset()
if not rfm9x.send_with_ack(F2packet.encode("utf-8")):
print("No Ack F")
await asyncio.sleep(interval)
Good luck. Hope it works.
Roger
Please be positive and constructive with your questions and comments.