Build an open future with us.

Invest in Mycroft and become a community partner.

GPIO pins working on Pi 3


#1

I downloaded the new image of Picroft from the Mycroft website, and have been able to use it smoothly. However, recently I have been attempting to run GPIO pins in my custom skill and have had no success. For testing purposes, I decided to try downloading and running the Picroft_example_skill_gpio skill from https://github.com/MycroftAI/picroft_example_skill_gpio which I found from some documentation here: https://docs.mycroft.ai/skill.creation/advanced-topics/gpio

I installed the skill by running the command msm install https://github.com/MycroftAI/picroft_example_skill_gpio.git

However, when I tried running the skill there was no output coming from the GPIO27 pin (or pin 13 if you use the GPIO.BOARD layout). Specifically, I have been using the ‘Turn LED ON’ command, which is supposed to send a high signal out of the GPIO27 pin, however I am only getting a low signal coming out of that pin no matter what command I use. I have a Raspberry Pi 3, and noticed there was an unanswered post about this same issue in the Mycroft forums (Mycroft and GPIO Raspberry pi 3).

Has anyone been able to use the GPIO pins with their Picroft? Or gotten this example skill working?

UPDATE:
I have been able to figure out that I am unable to locate a module named RPi.GPIO

I have made a python file called version.py that contains the lines:

import RPi.GPIO as GPIO
a = GPIO.VERSION
print a

When I attempt running this script that should simply tell me what GPIO version I have, I get the following as a result:

Traceback (most recent call last):
File "version.py", line 1, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO'

I tried adding a PYTHONPATH to my ‘env’, and made this path the same as my original PATH…this did not work

Any ideas?

UPDATE 2:

I was able to install pip, and use pip to install python-rpi.gpio, and now my simple version script is working. However, the example skill I downloaded does not recognize the intent anymore. For example, when I say “Turn LED ON” Mycroft responds with “Sorry I didn’t catch that, please rephrase your request”. It seems like installing the ‘rpi.gpio’ module or pip itself has caused this mycroft skill to not recognize its intent, but that does not seem like a likely cause to me.

Any ideas are appriciated


Using Buttons to control a Skill
#2

Hi @dleweyiv, thanks for posting this - and thanks for having a go hacking around the GPIO pins! I’m going to tag my colleagues @forslund and @steve.penrod, who are more knowledgeable about RPi and pip and python dependencies.

Kind regards,
Kathy


#3

Hi,

following in your steps installing the GPIO module I also ran into trouble. Checking the /var/mycroft-skills.log I found

  File "/usr/local/lib/python2.7/site-packages/mycroft_core-0.9.7-py2.7.egg/mycroft/skills/core.py", line 126, in load_skill
    skill_descriptor["name"] + MainModule, *skill_descriptor["info"])
  File "/opt/mycroft/skills/picroft_example_skill_gpio/__init__.py", line 41, in <module>
    import GPIO
  File "/opt/mycroft/skills/picroft_example_skill_gpio/GPIO.py", line 57, in <module>
    GPIO.setup(27,GPIO.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!

This was fixed by adding the mycroft user to the gpio group:

sudo useradd mycroft gpio

and then restarting the skills service

/etc/init.d/mycroft-skills stop
/etc/init.d/mycroft-skills start

(This was done using the GPIO example skill on the latest picroft image)

Hope this helps!

Regards
/Åke


#4

Hello again @forslund ,

Thank you for your original reply, that solved my issue with that example skill. However, I seem to be running into another. I have a custom skill made (located here: https://github.com/dleweyiv/TourGuideSkill). The goal of this custom skill is to be able to answer all questions pertaining to our university that a tour guide would be willing to answer. I thought that once I got the example skill working, I could easily implement it in my custom skill.

The issue I am running into is when I change the header of my inity.py file to include the import GPIO then nothing inside the skill works anymore. For example, with import GPIO being commented out I could say “Hey Mycroft, what is the retention rate here?” and it would respond accordingly. However, when I try to add the import GPIO line at the top to attempt to import the GPIO to my init file, everything stops working (aka when I ask about the retention rate, it asks me to rephrase my request.

To be clear, I am trying to set certain GPIO pins in the handlers of some of the intents, but I cannot seem to import the GPIO. If you have any insights again, I would greatly appreciate it


#5

The thing here I think is that the GPIO.py file is in the local directory (which is not in the path). In the example skill, the skill directory is added to the path before import GPIO

See https://github.com/MycroftAI/picroft_example_skill_gpio/blob/master/init.py#L30 for how it’s done in the example skill.

basically what you need would be

import sys
from os.path import abspath, dirname
sys.path.append(abspath(dirname(__file__)))
import GPIO

Let me know if this works, if not I’ll continue to troubleshoot.

/Åke


#6

Åke,

You are the best. Thank you for all your help, I cannot promise I won’t be reaching out again.

Thanks again!


Picroft button?
#7

Glad to be of help, feel free to reach out if you hit more trouble. :slight_smile:


#8

Åke,

Conceptual question for you: When running a self.speak_dialog command, there always is a delay before the speech starts. Are there already flags that exist that mark when the actual speech starts and stops? If not, do you know of any way to retrieve these timings?


#9

It’s a slight delay while the audio is generated and then speech starts but there is no way to get the times reliably right now.

There is however a function called wait_while_speaking that can be imported from mycroft.audio which will wait until speech is complete. Not sure if it’s something like that you’re interested in?


#10

Hello again Åke,

I am working more on my custom skill and cannot seem to figure out some of the strange issues I am having.

When running my custom skill, inside a intent handler I set GPIO pins(sometimes I set them multiple times). However, the states of the GPIO pins do not always stay constant when I am reading them in using another pi and its GPIO pins. When I test this by hooking the outputs of my first pi’s GPIO pins to LEDs on a breadboard, the LEDs never flicker, causing me to be uncertain whether the output signals are actually fluctuating. Do you believe (I know you probably cannot know for sure) the output states of the GPIO are fluctuating when I have not changed them? If so, ifs there any way to stop this fluctuation without implementing hardware such as pull-down resistors?

Any insights will be appreciated immensely


#11

I have very little experience of the raspberry Pi GPIO so I’m just guessing (and googling) here.

I would probably recommend having a pull up or pull down resistor between the devices. There seem to be a GPIO.setup function that can set the internal pull up/down of the Pi.

To really see what’s going on the best would be to use an oscilloscope and monitor the signal.

Sorry for not being more helpful.