Raspberry Pico multiple pwm read/PPM Read #11034
Replies: 1 comment · 7 replies
-
Have a look at https://forum.micropython.org/viewtopic.php?f=21&t=12785&p=69499#p69499 |
Beta Was this translation helpful? Give feedback.
All reactions
-
You might save the cited code as a file pulsestat.py on your computer and put it on the Pico. This is easy with Thonny if you activate the Data view. Then you could try it with a own-generated PWM signal like:
I just observe irregularities though, should there be a bug in my code.. ?? For real inspection of signals like PPM I recommend this cheap device. |
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Well I finally managed to read the separate channels. I've put it on github in case someone tries to do the same thing: https://github.com/AlexandreLarribau/Rasp-Pico-PPM-Reader- I am available if someone wants to talk about it or has a better way of doing this and want to upgrade this code. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Good work! But fir visibility, better leave the topic open. Otherwise people may not find it. Search looks by default only in open discussion. |
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
Hello, Here I am trying to read separate channels with the help of the function. It is at the end. Also, I divide the Max Value by 1000.
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone !
I am struggling with a pwm issue on a raspberry pico.
I want to be able to read 5 input PWM. And depending on what I read I want to write 5 output PWM. However I realized that very few people are reading input PWM. I found this "viewtopic.php?t=308269" which helped me to read 1 input PWM. But I think that I must use interrupt to be able to read 5 because i don't want to loose any informations. So I tried to adapt it to get 5 but I did this but I feel there's a better way because my pwm mooves randomly like some rising or falling are skipped (see the img attached).
My input PWM are between 1000us and 2000us, with a period of 20ms. I am first trying to read the 5 input before trying to do the output in a second step.
Thank you for your help ! I put some code that I wrote to try it.
Edit : I just found out about PPM. My RC receiver does this so i began looking for solutions on pico. Does anyone knows how to proceed with the reading of ppm ? I found "https://github.com/dastultz/micropython-ppm-decoder" but it is not working because of pyb i seem to understand. Anyway if someone is able to make it work it is probably the best way to go
Code:
from machine import Pin, PWM
import time
p1 = Pin(0, Pin.IN)
p2 = Pin(1, Pin.IN)
p3 = Pin(2, Pin.IN)
p4 = Pin(3, Pin.IN)
p5 = Pin(4, Pin.IN)
list_in_pins = [p1, p2, p3, p4, p5]
start = time.ticks_us()
start_time_ = [start]*5
pwm_to_send_out_ = [1500]*5
def handle_pwm_interrupt(pin):
pin_concerned = (int(str(pin)[8]))
if (list_in_pins[pin_concerned].value() == 0):
#falling
#print('p1 falling')
pwm_to_send_out_[pin_concerned]= time.ticks_us() - start_time_[pin_concerned]
else :
#rising
#print('p1 rising')
start_time_[pin_concerned]= time.ticks_us()
for p in list_in_pins :
p.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
while (True) :
machine.idle()
if time.ticks_us() - start > 1000000 :
#for now we just print all output pwm each second
print ("pwm_out", pwm_to_send_out_)
start = time.ticks_us()
Beta Was this translation helpful? Give feedback.
All reactions