andies
Posts: 144
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

pigpio and pilight-raw

Tue Dec 20, 2016 10:06 pm

Is there a program similar to

Code: Select all

pilight-raw -L
in the pigpio-library? I am struggling with my garage door opener and need the raw codes. I only partially understand the pilight-library, the code might be well documented but the wiki is not and many things are not well described (what is the difference between pulse, pulse train, pulse length, raw length etc. pp.). The pilight-forum also seems to be a little sleepy. Nevertheless, what I like is the above raw-command but there does not seem to be a similar program in pigpio? There, I could only find piscope but recording the piscope is such a pain because of the only graphical interface (it is not build for recording but watching).
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

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

Re: pigpio and pilight-raw

Tue Dec 20, 2016 10:22 pm

What does pilight-raw do?

andies
Posts: 144
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

Re: pigpio and pilight-raw

Wed Dec 21, 2016 8:16 pm

It seems to send raw data ("noise") to output. The difference to Piscope is that Piscope gives me a picture or a movie, pilight-raw gives me the actual numbers. From the wiki (although the description is a little bit terse):
pilight-raw will output raw numbers representing the time difference in µs (microseconds) between a low-to-high or a high-to-low transition forming a pulse. Depending on the protocol code a set of multiple pulses, typically two or four pulses, are representing a logical ZERO or ONE condition. A pulsetrain is a series of logical bits normally terminated by a footer pulse (last long distinct pulse).

pilight-raw can print raw data in two different formats:

pilight-raw -L or pilight-raw –linefeed:

....
433gpio: 1180 590 590 1180 1180 590 1180 590 1180 590 590 1180 590 1180 1180 590 1180 590
590 1180 1180 590 590 1180 590 1180 590 1180 590 1180 590 1180 1180 590 1180 590
1180 590 1180 590 590 1180 590 1180 590 1180 590 1180 590 1180 590 1180 1180 590
590 1180 590 1180 1180 590 590 1180 1180 590 590 6785 -#: 66
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

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

Re: pigpio and pilight-raw

Wed Dec 21, 2016 8:22 pm

Okay the following script will capture the raw information. It would have to be post processed to make it pretty.

Code: Select all

#!/usr/bin/env python

# monitor.py
# 2016-09-17
# Public Domain

# monitor.py          # monitor all GPIO
# monitor.py 23 24 25 # monitor GPIO 23, 24, and 25

import sys
import time
import pigpio

last = [None]*32
cb = []

def cbf(GPIO, level, tick):
   if last[GPIO] is not None:
      diff = pigpio.tickDiff(last[GPIO], tick)
      print("G={} l={} d={}".format(GPIO, level, diff))
   last[GPIO] = tick

pi = pigpio.pi()

if not pi.connected:
   exit()

if len(sys.argv) == 1:
   G = range(0, 32)
else:
   G = []
   for a in sys.argv[1:]:
      G.append(int(a))
   
for g in G:
   cb.append(pi.callback(g, pigpio.EITHER_EDGE, cbf))

try:
   while True:
      time.sleep(60)
except KeyboardInterrupt:
   print("\nTidying up")
   for c in cb:
      c.cancel()

pi.stop()

andies
Posts: 144
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

Re: pigpio and pilight-raw

Fri Dec 23, 2016 10:22 am

Thank you, great code. May I ask you again: I would like to stop the recording after a defined amount of time. I do see that the particular step to be changed is

Code: Select all

while True:
but unfortunately I do not understand the rest of the code (for example: where is tick defined? Could I add a counter without corrupting the speed and hence the time accuracy of the program etc.). Could you help me with that matter?

What I want is the following. I want to record signals after I press a button at my Garage door opener. I do know that the opener sends a wake-up signal as long as I press the button down (around 400us "high" and around 400us "low"). If I release the button the signal unknown to me is transmitted. But if I stop the program manually I add around 50k or more of "noise" and that makes it very hard for me to analyse anything. Stopping the program automatically after 0.5sec would be helpful.
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

andies
Posts: 144
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

Re: pigpio and pilight-raw

Fri Jan 06, 2017 7:45 pm

I have used the code for a while and compared it to pilight-raw. Unfortunately, python (or the RPi) seems to be too slow. The values differ a lot, as far as I can see from actual values that I recorded, in particular using histograms, pilight-raw gives more reliable results. If I am transmitting a 50microsec-LOW-50microsec-HIGH stream to any sender and record the result using this code the histogram is very distorted (contains values of 300 and above) whereas with pilight-raw all values are between 40 and 60.
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

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

Re: pigpio and pilight-raw

Fri Jan 06, 2017 8:18 pm

andies wrote:I have used the code for a while and compared it to pilight-raw. Unfortunately, python (or the RPi) seems to be too slow. The values differ a lot, as far as I can see from actual values that I recorded, in particular using histograms, pilight-raw gives more reliable results. If I am transmitting a 50microsec-LOW-50microsec-HIGH stream to any sender and record the result using this code the histogram is very distorted (contains values of 300 and above) whereas with pilight-raw all values are between 40 and 60.
If that is with pigpio you are not using it properly. pigpio has no problems capturing a 50 µs level change on a GPIO.

andies
Posts: 144
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

Re: pigpio and pilight-raw

Fri Jan 06, 2017 8:40 pm

joan wrote:If that is with pigpio you are not using it properly.
You are right (and it has nothing to do with python): I made a mistake in my breadboard. Now I am capturing 50-50-signals correctly with both software codes.
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

Return to “Automation, sensing and robotics”