I'm running pigpiod on the Pi, with a Windows PC using the pigpio Python module. I create a connection to the Pi with pigpio.pi() and then send the wave repeat command to create a straightforward frequency output. When I need to change the frequency I create a new wave, stop the previous wave, and send the new one (with wave repeat). This works great, most of the time.

The problem I'm seeing is that periodically the Pi hangs after a new wave repeat command.

The mystery is that it works "most of the time" (like 200 times I can change the frequency by sending a new wave repeat command) but every once in a while the wave repeat command results in a network timeout. I have a display hooked up to the Pi and I can correlate the new wave repeat command with the display going blank -- so I know it's this wave command that is killing the Pi.

Has anyone seen this behaviour? I have heard that power adapters have been problematic on some Pis, but I've been using this same adapter for other work on the same Pi, and so far haven't seen an issue (other than this one of course).

I'd love to hear any ideas!

Edit: Added code

import time
import pigpio
import ventureredlion

FREQUENCY_GENERATOR_BIT = 25    # this is a BroadComm number

class AutomatedIO:
    def initialize(self, skipCommunications=False, skipPowerCycle=False):
        # now connect to the pigpiod daemon running on the Pi
        piHost = ""
        startTime = time.time()
        self.pi = pigpio.pi(host=piHost)
        elapsed = time.time() - startTime
        print "Connected to pigpiod on %s OK in %.3f s" % (piHost, elapsed)

    def close(self):

    def simulateFrequencyInput(self, frequencyHz):
        if frequencyHz > 0:
            period = 1.0 / frequencyHz
            period_us = 1E6 * period
            half_period_us = int(period_us / 2 - US_FUDGE_FACTOR)

            pulses = [pigpio.pulse(1<<FREQUENCY_GENERATOR_BIT, 0, half_period_us), 
                      pigpio.pulse(0, 1<<FREQUENCY_GENERATOR_BIT, half_period_us)]

            waveform = self.pi.wave_create()


    def _initPi(self):
        self.pi.set_mode(FREQUENCY_GENERATOR_BIT, pigpio.OUTPUT)


    def _deInitPi(self):

if __name__ == "__main__":
    A = AutomatedIO()
    print "created OK"

    print "initialized OK"

    for f in range(50, 5000, 50):
        print "\rsimulated frequency %d" % f,


    print "closed OK"
  • When you get a chance post your code and I'll see if I can duplicate the fault or identify a mistake. If it is a fault then github.com/joan2937/pigpio/issues is the most appropriate place to log the error (if you have a github account).
    – joan
    Feb 7 '17 at 9:13
  • @joan Code added, thanks for looking into this. Apologies for the formatting, I could not figure out how to get the entire code block formatted right. The Pi hangs usually at frequency 700 or so (after about 15 iterations).
    – Rich
    Feb 7 '17 at 17:08

That does appear to be a bug. I'll need to look more carefully at the code to be sure.

In the meantime I suggest you use

self.pi.wave_send_using_mode(waveform, pigpio.WAVE_MODE_REPEAT_SYNC)

rather than


The using mode call has the advantage of seamlessly changing from one frequency to the next as well as appearing to work properly.

When you have finished with a waveform it is best to delete it, that allows for the resources to be reused. See the update() method of Wave PWM 2 for an example of what I mean.

  • Awesome, I will try the using-mode method. I looked at the update() method as you suggested, and this makes sense. I will switch to that. FYI, after posting the code I tried one small change which was to add a self.pi.wave_clear() call before sending a new waveform, and so far the Pi hasn't locked up. I will still use your recommended method though, and let you know how it goes.
    – Rich
    Feb 8 '17 at 0:25
  • You will eventually run out of resources if you don't delete waves you no longer need. I don't think that was the problem you are seeing though, that was just an aside. I'll cut down your script and see if I can isolate the problem with the calls you are currently making.
    – joan
    Feb 8 '17 at 8:33
  • Your suggestion worked (of course!) so I'm out of the woods. I don't plan on switching back to wave_send_repeat() since I have something that works. But, if you need any help reproducing the problem just let me know. I ran my new code adapted from your example about 50,000 times, with no issue so I think I've got the resource management figured out. I appreciate your tips.
    – Rich
    Feb 9 '17 at 0:23
  • @Rich I can reproduce the lock-up and it does seem to be a bug. I will look into it.
    – joan
    Feb 9 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.