I am new to Mycroft. I am running picroft on a Raspberry Pi 4 Model B Rev 1.2 with mycroft-core: 20.2.4 and using Python 3.7.3.
I have connected an Arduino Uno to the Raspi via USB cable and created a “stupid simple” device that has a single pot (short for potentiometer aka a dial). The Arduino code reads the analog input and sends over serial. The Raspi successfully reads the serial information (see screenshot and code). That’s not what I need help with. (NOTE: the “p3” command is just a bash alias I setup for ‘python3’)
The code being run is:
#!/usr/bin/python3 import serial ser = serial.Serial('/dev/ttyUSB0', 115200) read_uno=(ser.readline()).decode('utf-8') print(read_uno)
Here is where I am stuck: I want to be able to say “Hey Mycroft, what is the sensor reading?” and have it reply (i.e. verbalize) the current reading at that moment. I have two problems here:
I have “What is the sensor reading?”, “Read the sensor.” And “What is the sensor level?” in the /opt/mycroft/skills/read-arduino-pot-skill/locale/en-us/pot.arduino.read.intent file but Mycroft does not associate the utterances with this skill. I even tried mycroft-say-to “What is the sensor reading?” from the command line but it doesn’t know what I mean. I have read up on the Adapt Intents (https://mycroft-ai.gitbook.io/docs/skill-development/user-interaction/intents/adapt-intents) but from the examples on the page, I am not certain how that would help here. Perhaps the noobie is wrong. Wouldn’t be the first time.
Let’s assume that Problem #1 is solved. How do I code the skill’s __init__.py to actually speak the reading? If I assign the current value from the serial stream to a variable, how do I get Mycroft to say “The sensor reads $VALUE” where $VALUE is the variable storing the current reading? Right now, I have the following. If only I could test it but I still have Problem #1.
from mycroft import MycroftSkill, intent_file_handler import serial class ReadArduinoPot(MycroftSkill): def __init__(self): MycroftSkill.__init__(self) def initialize(self) ser = serial.Serial('/dev/ttyUSB0', 115200) read_uno=(ser.readline()).decode('utf-8') @intent_file_handler('pot.arduino.read.intent') def handle_pot_arduino_read(self, message): self.speak_dialog('pot.arduino.read' + read_uno) def create_skill(): return ReadArduinoPot()
Thanks to all for your help.
EDIT: I corrected the markdown above to use a code block instead of a blockquote so the indentation and formatting is corrected now.