Build an open future with us.

Invest in Mycroft and become a community partner.

Major Picroft Update - Moving to Raspbian Stretch


#1

Originally published at: https://mycroft.ai/blog/major-picroft-update-moving-to-raspbian-stretch/

It’s Alive!


There’s a brand new Picroft image available! Click here to get setup instructions. Read on to learn more.

In late 2016 I created the original Picroft as a way for anyone to interact with Mycroft, not just those who were able to purchase the Mark 1. Since then, Picroft has been downloaded more than 35,000 times. It has become the basis for numerous Raspberry Pi projects, like Magic Mirrors, home automation systems, robots, and hundreds of other wonderful testaments to creativity.

Picroft was designed to self-update, and we did publish some new versions periodically to simplify moving to major new releases. It has held up well and essentially remained the same for the last two years.

However, the new Raspberry Pi 3B+ introduced new chipsets that broke Picroft. The original Pi 3 is still available, but this was a good reason to show Picroft some love and introduce some cool new stuff.

[caption id=“attachment_40527” align=“alignnone” width=“1316”]The electricity that gave Picoft life will be how Picroft gives life to your Raspberry Pi projects. This was the sky the night I started rebuilding the Picroft image. Fitting, right?[/caption]

What’s New?

Lots of little things, and a few big things. Once things are up and running, it will still be Mycroft -- a voice interface. The main changes are at the setup and “plumbing” level. We also listened to the findings of our Picroft survey -- thanks to all who participated!

Stretch’ing ourselves

With the release of the Raspberry Pi 3B+ hardware changes required a new release of the Raspbian operating system. The new version is referred to as “Stretch” (following the tradition of Toy Story references). Picroft is now based on this latest version of Raspbian, allowing support for both the Raspberry Pi 3 and the 3B+.

No more packages, go Git it

To simplify and unify the Mycroft experience on the various platforms, we rethought how Mycroft should sit on the Raspberry Pi. At the low level, we switched from a Debian package install (which was originally a hack of the Mark 1 package that just disabled the faceplate) to a Github-based install that can be set to automatically update.

This unifies the Picroft environment with what most desktop developers are using, allowing us to simplify documentation.

Wizards!

One of the recurring issues users encounter is difficulty in configuring the audio pieces. Linux is incredibly flexible, but nobody wants to deal with the audio subsystems if they can avoid it. Configuring sound drivers is full of alchemy and dark magic. Connecting to all the different kinds of wifi security protocols is a whole different book of incantations. So we are including a Wizard with Picroft to help cast these spells!

During the initial setup, the user is now presented with a series of simple questions to configure the network connection, pick the type of microphone and audio output they want to use, and configure security options based on their intended use. Configuration happens automatically, and tests immediately verify the speaker output and sound levels, and the microphone input.

MOAR Microphones

We have a great community who have proven that Mycroft can operate with nearly any kind of hardware. Over the next few days, the Picroft image will incorporate support for the Google AIY Voice Kit array microphone. In the future, there will be an easy path for automating the install of other microphones, such as the Matrix Creator and Seeed ReSpeaker.

Environment Helpers

As I developer, I feel justified in making fun of every time one of us answers a question by saying something like:

Oh, that is really simple. First pip install pyjokes. Then just type python -m test.integrationstests.skills.runner. You are in the virtual environment, right? Oh, well you just need to do source /opt/venvs/mycroft-core/bin/activate before that. Still not working? Oh, were you in the venv when you did the pip install? …

I’ll let you in on a secret – this is also a pain for us and we probably mistype these commands half the time.

As part of this overhaul, we’ve unified most Mycroft related commands under a mycroft- prefix. This is particularly helpful because you can now take advantage of Linux’s excellent auto-completion by typing my<TAB> to get to mycroft-, then hit TAB two more times to see all the options available for you.

Helpers include:

  • mycroft-help Get brief summaries of the commands
  • mycroft-pip Install Python packages inside the Mycroft venv
  • mycroft-msm Invoke the Mycroft Skills Manager
  • mycroft-msk Mycroft Skill Kit, submit and manage skills in the community repos
  • mycroft-speak Make mycroft speak for you (handy inside scripts)
  • mycroft-say-to Send a string to Mycroft, just like you spoke it (also handy for scripts)
These same tools are also available under all other environments now.

What Else Can You Look Forward To?

We’ll be providing Skills that are unique to the Picroft environment, allowing you to attach buttons to the GPIO pins to emulate the Mark 1 button. Or use this example to do whatever else you might want to do -- this is your Picroft!

As mentioned above, we’d like to expand the microphone and audio hardware supported by Picroft. With a little help from community members, I expect we’ll have support for various USB and Bluetooth mics and speakers soon. Join us on the forums to give feedback on AIY integration, how to pipe in new mics, and what you’d like to connect over GPIO.

Gimme, Gimme, Gimme!!!

You can download the new Picroft image from https://mycroft.ai/to/picroft-image. Learn all about it (including exactly how it was built) from https://github.com/MycroftAI/enclosure-picroft/tree/stretch.

Go, download, and hack!


Hardware recommendations (Picroft)
#2

I’m look for feedback on how this image is working for you – I only have a few mics myself!

I know the AIY setup isn’t up to snuff yet, but decided to push this since AIY wasn’t supported by the previous stable image, and this is definitely an improvement when using the supported mics. I could use help from anyone who can assist in getting AIY, Matrix, Respeaker or any other non-standard mics running. Same for Bluetooth speakers (I’m not sure if anyone has that working well yet).

Thanks all!


#3

P.S. This article got pushed before I had updated the picroft-image link. So if you downloaded the image before this message, you probably need to re-download it. The new image shows ASCII-art “Mycroft” and “Picroft” at boot, so it is easy to distinguish.


#4

@steve.penrod thanks for creating the picroft images and updating to Stretch. They make setting up a picroft really simple thanks!

Do you have a checksum for the raspbian-stretch_Picroft_2018-09-12.zip? I could only find them for the previous releases on the enclosure-picroft github. I’ve already had a failed download attempt (stopped at 2.097 GB) so would like to check the image when I manage to get it to download fully.

I’m hoping to get a bluetooth speaker/mic to connect to this new version. I couldn’t get raspbian_Picroft_2018-03-14.zip (which I normally used with a PS Eye and analogue speakers) to find any bluetooth devices (the scan kept timing out no matter what trickery I tried to apply from the web). I have another Stretch rpi (a reropie) which connects to bluetooth without any hassle so I hope to compare them like-for-like if I run into any problems.

EDIT: I found the checksum on the enclosure-picroft github. Not sure how I missed it earlier sorry. (failed to download twice now :frowning:)


#5

I have a cople of Google AIY’s and as soon I get the time i will install this, and try to get it to work whith mic an audio.


#6

Awesome! If you do get that working I’d really appreciate it if you can document the steps exactly so we can make this a one-click operation for everyone.


#7

AIY v.1. Pi 3B+ 3A m-c 18.8.1
On the AIY option (3) it pulls lots of stuff in, looking similar to the google assistant version. The speaker comes up in a google voice model, but nope, no microphone. Best of luck with this part. The button light/function, is not triggering either. I’ve tried a variety of fresh installs, with a Samson USB mic as well, but not so much. That one throws errors.


#8

I have made a PR whith changes to auto_run.sh so installation of Google AIY works :slight_smile: It also make some changes to config.txt and mycroft.conf and add a asound.conf.

I think it works….


#9

Thanks so much @andlo!


#10

@steve.penrod After a week of grappling with bluez5 and pulseaudio here’s what I’ve learned.

TL;DR Speaker probably works on bluetooth, microphone may or may not. Overall not really consistent enough for general use.

Here are the steps to connect

  1. Install pulseaudio-module-bluetooth:
    1. sudo apt-get install pulseaudio-module-bluetooth
  2. Remove the audio device assignment in mycroft.conf:
    1. Change "play_wav_cmdline": "aplay -Dhw:0,0 %1", to "play_wav_cmdline": "aplay %1",
    2. Change "play_mp3_cmdline": "mpg123 -a hw:0,0 %1", to "play_mp3_cmdline": "mpg123 %1",
  3. To make the last connect audio device be the active one type pactl load-module module-switch-on-connect (this module can be added to /etc/pulse/default.pa so that it is automatically loaded)
  4. I initially thought the file /etc/bluetooth/audio.conf had to be created with the following contents but it still worked for me after I removed the file.
[General]
Enable=Source,Sink,Headset,Gateway,Control,Media,Socket
  1. Pair/trust/connect bluetooth speaker:
    1. Type bluetoothctl
    2. Put bluetooth speaker in pairing mode and type scan on.
    3. When the mac address (<mac>) of the speaker is found type:
      1. pair <mac>
      2. trust <mac>
      3. connect <mac>
      4. exit

Sound should now come from the bluetooth speaker. This is where it gets more complicated. There are two main profiles a speaker can have: a2dp_sink and headset_head_unit. a2dp_sink provides high fidelity stereo playback (speaker only) with a sample rate of around 44 kHz whereas headset_head_unit provides bidirectional mono audio (ie. both microphone and speaker which are referred to as source and sink, respectively) with a sample rate of only 8 kHz each. The available cards and their profiles can be viewed with the command pactl list cards | grep -edescrip -eHSP -eA2DP -eActive -eCard and set with the command pactl set-card-profile <card> <profile>.

The headset_head_unit profile is split into two sub-profiles: headset profile (HSP) and hands-free profile (HFP). With pulseaudio 10 HSP is natively supported but for HFP ofono must be installed. The features available for the connected bluetooth device can be found with the command info <mac> executed within bluetoothctl.

Here arises the problem I have been contending with: the available features of the device are not always seen as available by pactl. For some devices the combination of a2dp_sink and headset_head_unit availability is random and for others the availability is dependant on whether the device was connected automatically or manually with bluetoothctl. A profile can only be set when pactl thinks it’s available. When a device is reconnected and the profile it was previously connected with is not available it will be set to off and must be manually set to an available profile.

I have two bluetooth devices I’ve been testing with: a headset (Philips SHB7000) and a speaker (Sephia A2). The available profiles for the headset are random but when they both show as available both profiles work fine. The speaker however always has a2dp_sink and only has headset_head_unit when it’s connected manually. When I finally found the “manual connection” trick to set the speaker profile as headset_head_unit I thought I finally found how to get the speaker’s microphone working. Unfortunately this was not the case and when I use the speaker in the headset_head_unit profile I get nothing from the speaker or microphone - I can only hear the background hum on the speaker. I have not found a solution to this so even if the headset_head_unit profile is available it might not work. In my opinion, not being able to use the microphone drastically reduces the usefulness of using a bluetooth speaker with Mycroft.

A separate issue is that when headset_head_unit does work it sounds absolutely terrible! This is not due to the low sample rate but cause by a bad bit of code in pulseaudio 10. It has been fixed in later versions but for it to work with picroft I had to patch version 10 as described here. This produced libbluez5-util.so which can replace the original in /usr/lib/pulse-10.0/modules/. With this patch the audio sounds as it should with a sample rate of 8 kHz and mycroft can then recognise commands. It works for both rpi3b and rpi3b+ models.

I focussed more on HSP rather than HFP in my research because the added dependency of ofono for HFP seemed to add yet another layer of complexity and because the most recent version of pusleaudio concentrates more on HSP. I may try to look more into HFP to see if it’s any better or reliable.


#11

Thanks for that detailed analysis! I’ve suspected the Bluetooth solution isn’t likely ready for prime-time – the speaker side is pretty well defined but the Mic side is still messy. Android phones are still finicky, and I’m sure they have hundreds of hard-coded cases built in there.

Part of the new Picroft approach is to provide very specific menu options for hardware that we know works, then making that hardware super easy to install. This makes it obvious that trying that $2 usb mic you pulled out of the drawer may not work but there is a $7 option that is guaranteed to work. Users can then decide if their time is worth the $7 – and if it is I hope they share the details and so we can add the new mic to the the “supported” list.

Until I see a scriptable and repeatable process for a specific Bluetooth speaker, I will consider this a wish-list item. I’m happy to help with making the script seamless, but I’m going to leave the time consuming research side in capable hands such as yourself! As you get close to a solution, start a PR and we can get it in.


#12

I copied and pasted Andlo’s script to get AIY working onto the 9/12 image and have not been able to get MyCroft working on my Pi 3 B+. The error messages are:
“sed: couldn’t open temporary file /boot/sedHUUDo6: Permission denied” (So I manually changed config.txt.)

“sed: couldn’t open temporary file /boot/sedHUUDo6: Permission denied” (So I manually copied AIY-asound.conf to /etc/asound.conf.)

“Level [1-9/T/D/R]: 7amixer: Unable to find simple control ‘PCM’,0” (And I had no idea what to do.)

The test at the above prompt works, despite the error, but the subsequent microphone test does not work. The error is:
"Playing WAVE ‘/tmp/test.wav’ : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
aplay: set_params:1299: Sample format non available
Available formats:

  • S32_LE
    An error occured while playing back audio (1)"

Hopefully all these messages have the same root cause and hopefully it isn’t me. (Maybe I did not do quite what sed would have?)

But if I should try installing from Git on a Raspian image, let me know and I will give it a shot.

Thanks


#13

Hi guys, I got a question.
I have a google AIY kit with Raspberry pi 3. I’m using this new picroft image and I have problems with sound. On the image it does not give options to use Google VoiceHAT (v1) as your speaker.

I found instructions from google that you need to install pulseaudio to get it working - https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/HACKING.md. and changed /boot/config.txt by adding this:

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
dtoverlay=i2s-mmap
dtoverlay=googlevoicehat-soundcard 

I can hear the sound in speaker, but I cant control the volume level, What do I need to do to be able to change volume?


#14

Hi there @Aculimic, the first errors sound like filesystem permission errors.
Are you able to run the command ls -las on the directory where those files are so we can see if the errors relate to filesystem permissions. Are you running the script as sudo?


#15

Hi @Raiko
I have the same issue as you describe - PiCroft Stretch with Google AIY kit works, but volume can not be controlled. I also have a SD card with PiCroft Jessie where I (accidently - don’t remember what I did) got Google AIY working including volume control. Right now I am comparing the Jessie and the Stretch installations, but this is a tedious task…


#16

Hi @Dominik
Is it possible that on Jessie you used alsa and not pulseaudio?
Or maybe you used the VoiceHATs older drivers and way of installing it. I think they worked with alsa.

On Stretch I was thinking that maybe you need to install pulseaudio and configure in a specific way. As with instructions provided they dont really set up pulseaudio. At least on my image I have no daemon running. I installed pulseaudio-utils and when running pactl list it doesn’t work. Says connection refused. Also pacmd is not showing anything anymore.
Equally I havent found anything yet that suggests how to do it properly.


#17

Hi @KathyReid,

The script is running at boot, so it is running however it is invoked.

My file permissions are below (I omitted all the files older than my attempt and auto_run1.sh is the original file).

4.0K drwxr-xr-x 9 pi pi 4.0K Sep 21 01:17 .
4.0K drwxr-xr-x 3 root root 4.0K Jun 27 00:17 …
4.0K -rw------- 1 pi pi 860 Sep 19 04:28 AIY-asound.conf
4.0K -rw-r–r-- 1 pi pi 197 Sep 21 01:17 audio_setup.sh
24K -rw-r–r-- 1 pi pi 22K Sep 12 07:15 auto_run1.sh
24K -rwxr-xr-x 1 pi pi 23K Sep 20 03:08 auto_run.sh
4.0K -rw------- 1 pi pi 2.8K Sep 21 01:06 .bash_history
4.0K -rw-r–r-- 1 pi pi 220 Jun 27 00:17 .bash_logout
4.0K drwx------ 3 pi pi 4.0K Sep 21 01:16 .config
4.0K drwxr-xr-x 5 pi pi 4.0K Sep 20 03:50 .mycroft
4.0K -rw-r–r-- 1 pi pi 155 Sep 21 03:24 .mycroft_cli.conf
48K -rw-r–r-- 1 pi pi 48K Sep 20 04:05 sit
4.0K drwx------ 2 pi pi 4.0K Sep 12 07:27 .ssh
72K -rw-r–r-- 1 pi pi 69K Sep 20 04:05 there<Blockquote


#18

hey guys is this in an image somewhere? https://github.com/MycroftAI/enclosure-picroft/commit/5408b807a15a9c7b3d3c8d18cdca6daeb5fab9cb @andlo @steve.penrod

Even if this is just a dev image.

this is what I worked out that is needed to get the voice hat working and recording

Assuming SSH is already enabled.


#this should add i2c-dev to /etc/modules

sudo raspi-config
Interfacing options -> I2C -> Enable

echo "deb https://dl.google.com/aiyprojects/deb stable main" | sudo tee -a /etc/apt/sources.list.d/aiyprojects.list

wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

sudo apt-get update
sudo apt-get upgrade
sudo reboot

sudo mkdir /usr/lib/systemd/system

sudo apt-get install aiy-dkms leds-ktd202x-dkms pwm-soft-dkms aiy-voicebonnet-soundcard-dkms aiy-voicebonnet-routes aiy-python-wheels

sudo apt-get install pulseaudio pulseaudio-utils -y 
mkdir -p ~/.config/pulse/
echo "default-sample-rate = 48000" > ~/.config/pulse/daemon.conf

sudo reboot 

# load mic default

sudo leafpad /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored

i2c-dev

sudo leafpad /boot/config.txt

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
dtoverlay=i2s-mmap
dtoverlay=googlevoicehat-soundcard

sudo leafpad /etc/pulse/default.pa
uncomment and change:
load-module module-alsa-sink device="hw:0"
load-module module-alsa-source device="hw:0,0"

sudo reboot

#19

I did the above before running the mycroft-setup-wizard.


#20

Re auto_run.sh, I added “sudo” to the sed and cp commands for config.txt and asound.conf and that resolved the permission errors.

But after @Raiko’s steps (some of which are in auto_run.sh) I am still getting the following errors:

Let’s test and adjust the volume:
1-9) Set volume level (1-quietest, 9=loudest)
. . .
Level [1-9/T/D/R]: 7amixer: Unable to find simple control ‘PCM’,0

and

Press any key to begin the test…
Playing WAVE ‘/tmp/test.wav’ : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
aplay: set_params:1299: Sample format non available
Available formats:

  • S32_LE
    An error occured while playing back audio (1)

Addendum test.wav is created and 312k, but it has no audio.

EDIT: SOLVED (PEBKAC): I copied and pasted auto_run.sh incorrectly somehow. The mic now works, and Mycroft answers questions. I am still getting the PCM error and cannot fix the volume—so onward.