Mycroft with Google AIY Voice kit - Button Not Working after the first press


#1

Hello,

I am using Mycroft with Google AIY Voice kit (BLUE BUTTON).

AIM: Every time the button is pressed, I want to Activate the “hello-world skill” and say something to the user.

WHAT I TRIED: Modified the “button.py” code as follows:

------START OF CODE----------------------------------------------------------------
import subprocess
import time
import RPi.GPIO as GPIO
from subprocess import call

gpio_pin = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
if GPIO.input(gpio_pin) == False: # Listen for the press
call([‘python’, “/home/pi/say_command.py”, “localhost”, “Emergency”])
GPIO.cleanup()
----------END OF CODE-----------------------------------------------------------

Note: Emergency is the intent in the “vocab/en-us” folder

PROBLEM: When the button is pressed after reboot,
the “skill-hello-world” skill is activated and speaks out what is present in the dialog folder of “skill-hello-world”, but ONLY ONCE (sometimes twice).
After which when the button is pressed, there is no response from the R-Pi.

Can somebody please give me a solution to this?

Best regards,
Wesley


#2

Hi there @vailshery, thanks for reaching out to us, and huge well done on extending Mycroft so far!
I’m going to ping my colleague @forslund here to see if he may have any advice.

What would be useful here is if you have the mycroft-skills.log available for us to review?

Best, Kathy


#3

Hi,

it’s hard to say since the formatting of the code is missing. But I tried the say_command.py from the commandline and the first time I ran it it hanged. This might be what’s causing your issue. The call() method hangs and blocks subsequent calls.

Try the command from the command line and see if you get similar behaviour. You could try using the send function in the mycroft.messagebus.send instead of using the subprocess.call


#4

Hey @KathyReid , Thank you for your response. I am travelling right now and can try to get the logs on Monday.

Best,
Wesley


#5

Hi @forslund ,

Sorry for the improper formatting since I just did a copy+paste.
When I run “say_command.py Emergency”, my skill is activated and runs once or sometimes at least for 5 times.
The behaviour is similar when i use the call() method in “button.py”

I will try using the send function and check the results.

Best regards,
Wesley


#6

Hello Team,

I fixed the issue. I will share the details tomorrow.

Best,
Wesley


#7

hey,
Any updates on how to fix this issue?

best,
Juan


#8

Awesome news @vailshery! We’d love to share your write-up / video when it’s done! :+1:


#9

Hello,

I edited the code in the “button.py” script as mentioned in the code section below.
I also edited the skill folders (cd skills) as mentioned just below this line under the NOTE section.

NOTE:

  1. “introduction” is the utterance which should be in the “/home/pi/skills/skill-intro/vocab/en- us/intro.voc”.
    (1.a) Change the contents of the .dialog file in the dialog folder of the particular skill you are using as per
    your requirments. (what the assistant speaks ;)).

  2. “call” is the utterance which should be in the “/home/pi/skills/skill-call/vocab/en-us/call.voc”.
    (2.a) Change the contents of the .dialog file in the dialog folder of the particular skill you are using as per
    your requirements. (Lights up the LED in my case;)).
    (2.b) In my case, the GPIO which provides LOGIC HIGH as output is used to trigger a GSM module.

I will attach the video of the same.

The solution to the problem is

"call([‘python’, ‘-m’, ‘mycroft.messagebus.send’, ‘recognizer_loop:utterance’, ‘{“utterances”: [“call”]}’])"
PS: Use without quotes :stuck_out_tongue:

CODE SECTION:
------------------START-------------------------------------------------------------------------------------------------

while True:
    time.sleep(0.2)
    if GPIO.input(gpio_pin) == False: # Listen for the press, the loop until it steps
        print "Started press"
        pressed_time=time.time()
        while GPIO.input(gpio_pin) == False:
            time.sleep(0.2)
        pressed_time=time.time()-pressed_time
        print "Button pressed %d" % pressed_time
        if pressed_time<longpress_threshold:
            call(['python', '-m', 'mycroft.messagebus.send', 'recognizer_loop:utterance', '{"utterances": ["introduction"]}'])
            time.sleep(10)
            call(['python', "/home/pi/mbus.py", "localhost", "mycroft.mic.listen"])  
        else: 
            GPIO.output(27,GPIO.HIGH)
            call(['python', '-m', 'mycroft.messagebus.send', 'recognizer_loop:utterance', '{"utterances": ["call"]}'])
            time.sleep(5)
            GPIO.output(27,GPIO.LOW)

-------------------------END --------------------------------------------------------------------------

PS: Sorry for the bad editing of the code :frowning:
Feel free to post any further questions

Cheers!!
Wesley


#10

Hey,

Please look below.

Best,
Wesley


#11

Thanks enormously for such a great writeup, @vailshery! We really appreciate it! Hope you don’t mind, I made a small edit to the formatting of the post so that the code displays as a code block :wink:

Again, many thanks both for figuring this out and also for writing it up so that others can learn from your work.


#12

Hello @KathyReid,

No issues at all. I tried formatting but failed :wink:
Thanks for the edit.

Always happy to contribute :slight_smile:

Best,
Wesley