shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

how to measure duration of pulse in python

Tue Sep 17, 2019 6:02 am

I want to read a PWM output on a digital pin of the raspberry pi
for that, I need duration of the pulse HIGH LOW in microsecond or second
how can I get it in Python please help me

User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: how to measure duration of pulse in python

Tue Sep 17, 2019 6:47 am

http://abyz.me.uk/rpi/pigpio/examples.h ... ead_PWM_py

That is likely to be the most accurate.

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Tue Sep 17, 2019 7:12 am

actually, I am new to python lang
I want to read this Co2 sensor MH-Z19 with PWM output as showing in image
can you give me any specific code or something
Attachments
CO2pwm.JPG
CO2pwm.JPG (58.77 KiB) Viewed 513 times

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Wed Sep 25, 2019 11:08 am

please help mee

Heater
Posts: 13689
Joined: Tue Jul 17, 2012 3:02 pm

Re: how to measure duration of pulse in python

Wed Sep 25, 2019 12:15 pm

We cannot help you to read.

See the first reply in this thread for an answer to your question.

If it turns out to not be suitable do come back and ask more.
Memory in C++ is a leaky abstraction .

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: how to measure duration of pulse in python

Wed Sep 25, 2019 12:31 pm

Your best bet is to look over a Python3 module and see how they are doing it.
You can then try to implent your own version if you want.

e.g. from a very quick search
https://github.com/UedaTakeyuki/mh-z19

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 5:57 am

i just want to measure PWM single or high low Pulse duration not rx tx

User avatar
B.Goode
Posts: 8897
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 8:05 am

shyam25 wrote:
Thu Sep 26, 2019 5:57 am
i just want to measure PWM single or high low Pulse duration not rx tx

You have had a reply from one of the volunteer helpers in this forum who is, outside of the Raspberry Pi organisation, probably the most knowledgeable person contributing to the forums on this topic. You have been provided a link to their own code implementing a solution to your requirement. The description is "Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle."

If that is not helpful, perhaps you should ask specific questions about focussed issues that are holding you back.

"Just do my project for me" is probably not an approach that will meet with any sympathy, other than in the Wanted subforum, where you will find many people ready to sell you their services.

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 9:22 am

I try with that class monitoring PWM
And get nothing output
Only 0 0 0 output
I don't know where I am going wrong
I try with my sensor and raspberry pi pwm pin but
It is not showing any output

By the way thanks You all for helping..and also thanks to B.Goode for your kind words

It is great platforms i know but still I don't found my solution ..thanks :)

User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 9:40 am

Could you run the following script and tell us the output (if any).

http://abyz.me.uk/rpi/pigpio/examples.h ... monitor_py

Code: Select all

sudo pigpiod
./monitor.py

User avatar
B.Goode
Posts: 8897
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 9:54 am

I try with my sensor and raspberry pi pwm pin but
It is not showing any output


Is the voltage level from the sensor compatible with the gpio pins on the RPi board? (RPi gpio pins are only 3.3v safe.)



By reference to a diagram such as the following, are you connecting/monitoring the correct pin on the RPi? (Pin numbering systems have been known to cause confusion.)
https://pinout.xyz/

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 10:20 am

thank you joan sir
i run monitor.py code
i got following output
but i don't understand which gpio pins are you reading you menation
in comment section 23,24,25 but still in program i can't find anything where i can define whoch gpio pins
pulse i have to measure
sss.JPG
sss.JPG (23.51 KiB) Viewed 339 times

User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 11:17 am

That shows there is activity on GPIO 21 (g=21) and shows how long each is high and low in microseconds (d=).

With that script you specify the GPIO you want to monitor on the command line (e.g. ./monitor.py 21).

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 11:43 am

sir but GPIO21 is last rightbutton pin of raspberry pi which has nothing connected to pi
it is floating that's y b it is showing
i try with my specific GPIO pin but got nothing
program not getting any output blank i wait for 15min
Attachments
dd.JPG
dd.JPG (26.21 KiB) Viewed 316 times

User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 12:12 pm

I'm afraid that is your problem. It is pointless trying to measure pulses if you can't get them into the Pi.

For help you will need to provide clear photos and a description of the connections you have made between the Pi and the device you are using.

shyam25
Posts: 12
Joined: Sat Sep 14, 2019 11:01 am

Re: how to measure duration of pulse in python

Thu Sep 26, 2019 12:25 pm

below is my connection diagram
Attachments
dddd.JPG
dddd.JPG (24.38 KiB) Viewed 303 times

Return to “Python”