Intel Z83 mini PC setup (still MusicalPi) - Linwood-F/MusicalPi GitHub Wiki
These are the steps I used for my Mini PC setup, based on the Z83 (min was specifically one from "jack'shop" on Amazon, 2G X5-Z8350 for $99, which really seems associated with minisforum as a brand). I believe it to be fairly typical of Z83 systems though the accompanying sound and wifi chips may vary.
I use Dell Touchscreen (S2240T) hooked up via HDMI and USB and a bluetooth pedal for page turns. The Piano I used has a midi player built in (it is a PianoDisc system), and the program can (optionally) support one via ALSA and a USB Midi port. I also used the media capabilities in Linux for playing Pianodisc music (which is audio-encoded midi, for which they have a large collection).
I had previously used Ubuntu Mate, but with 18.04 and 18.10 the OnBoard keyboard is totally broken (https://bugs.launchpad.net/ubuntu-mate/+bug/1792787), so I switched to Ubuntu (plain) and its pretty limited keyboard, which while VERY limited at least works. Update: The bug appears moved to gnome, but last I looked still not addressed (https://gitlab.gnome.org/GNOME/gtk/issues/945).
I also found that 18.10 fixed some issues with sound and wifi that were widely reported on this board (vs. 18.04 or earlier, see http://www.minisforum.com/showthread.php?tid=201 ).
Note that the supplier has distributions that might work out of the box, but as of this writing (Oct 2018) they appeared to be a work in progress so I decided to use the standard distros, and fix what I needed directly. This should be more compatible with updates as well.
It's worth noting that you can do the development in Hyper-V as I described for the Pi, though you can also actually do some development right on the mini-PC, especially if you have more memory (at the time I bought it, they were coming with Windows 10, and I think it outgrew 2gb systems, so they were much cheaper than 4gb systems). You need at least 32gb; you can use the SD expansion available in most variants of the Z83 though you have to work out what to put there.
One more hardware note: I had to boot with HDMI for a standard, HD sized monitor. When I tried a larger monitor I got no video. I think this particular hardware is limited to what resolution(s) it will support. I understand VGA will work with any monitor but did not try it.
Note that in the below, the scripts can be copied and pasted as you go, but there are some replacemens you should do first. The simple way is to copy this entire script and then replace as follows:
MYACCT = your unix account (and in the CIFS section the file server account)
MYDOMAIN.COM = your local DNS domain (if applicable, or use IP addresses)
MYFILESERVER = the server name portion of the CIFS server
MYDISKDRIVE = the drive share name of your CIFS share
MYSSID = Wifi SSID to auto-connect to
MYWIFIPASSWORD = password to the above SSID
MYSMBPASSWORD = password for file share
Configure USB drive to boot
-
Download Ubuntu AMD 64 bit (they recommend 32 bit for 2G but I used 64) (general download page )
-
Copy the ISO file to a formatted USB stick. I used Win32Disk Manager (Win32 Disk Imager download page )
-
You will want a keyboard plugged in to get started (the touchscreen makes for a decent mouse though you might prefer a real one) notably if you need bios changes, or to do the initial install.
-
Put the USB Drive in the PC and boot from the USB. This requires you hit F7 at a particularly lucky moment, so keep trying until you can manage to hit it. After a few times, I set mine to boot first from USB to make future installs easier. Note that you also need to play around with the hard disk boot priorities, it seems to want (post install) the Ubuntu option not the EFI option first, and once in a great while it seems to randomly change back. You cannot do the bios changes with a touch screen, you need a real keyboard.
-
Start the install, I used Minimal Installation, Download updates and 3rd party software, erase disk, Install without LVM (you may want it if you think you might change configurations), no encryption of disk.
-
Change the hard disk boot order if it goes into a boot loop when done (I found it helps to alternate with escape though I do not know why).
Ubuntu Configuration
-
After first boot, you can open a terminal window and use:
ip addr # note address sudo apt install ssh
-
This assumes you have a wired Ethernet plugged in, which I recommend as the wifi probably does not work at this point. Pick up the ip address here so you can ssh to it.
-
At this point you can do the rest of the configuration from ssh from a real computer if you prefer, or continue from the touchscreen and/or a keyboard plugged in.
-
If you may need the on-screen keyboard; log in to wayland (must be wayland) and you can swipe up from the bottom. The login choice is the small gear under the login prompt.
-
Get to a shell prompt and run the following (you should not try to copy/paste the entire thing as some may prompt and will screw up the paste-in):
sudo apt update sudo apt dist-upgrade sudo reboot now
-
There were a lot of issues in 18.04 (NOT the 18.10 I am using) with sound on this card. I use only the headphone jack, not HDMI. One fix for issues was to blacklist snd_hdmi_lpe_audio in /etc/modprobe.d/blacklist_snd_hdmo_lpe_audio.conf. But hopefully it will just work in 18.10 and forward. So take a break now, plug in a headphone or speakers, and use the Sound, Output to send a test to left and right speakers. Make sure they are separate (one error was for them to come out as a mix in mono).
-
Because I stashed some needed files in the project, let's pull down the project now but not yet build it.
cd ~ sudo apt install git git clone https://github.com/Linwood-F/MusicalPi.git
-
To get Wifi working you need a file that I found referred to in this thread http://www.minisforum.com/showthread.php?tid=125 but since that might disappear, I put it in git.
sudo cp ~/MusicalPi/brcmfmac43455-sdio.txt /lib/firmware/brcm/ sudo apt install git bcmwl-kernel-source sudo sed -i 's!blacklist brcmfmac!#blacklist brcmfmac!g' /etc/modprobe.d/blacklist-bcm43.conf
-
It's not completely clear but this blob may be useful, at least it makes errors go away if loaded, but it does not seem to actually make anything function differently, but it gets rid of an error. As above I stashed it in my git in case you need it, the original source was https://github.com/armbian/firmware.git
cd ~ sudo cp ~/MusicalPi/brcmfmac43455-sdio.clm_blob /lib/firmware/brcm/ sudo modprobe brcmfmac ip link
-
You should see wlan0 now, pick up its mac address, and edit the above file (/lib/firmware/brcm/brcmfmac43455-sdio.txt) and change the mac address embedded to the actual address. Don't reboot yet, there are still issues.
-
Change from network manager to netplan and hardcode the IP addresses (you do not HAVE to do this, but it makes management easier). To do so:
sudo nano /etc/netplan/50-my-netplan.yaml network: version: 2 renderer: networkd ethernets: enp1s0: dhcp4: true dhcp6: true wifis: wlan0: dhcp4: yes dhcp6: yes access-points: "MYSSID": password: "MYWIFIPASSWORD" sudo mv /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.save
-
Sometimes a reboot sets a soft block on the wifi, at least it did for me. You can see it with just the command rkfill. Create the following file so it will get cleared each reboot.
sudo nano /etc/crontab
-
Add a line at the end and exit:
@reboot root /home/MYACCT/onReboot > /home/MYACCT/onReboot.log
-
then
cp ~/MusicalPi/onReboot ~/ sudo sed -i 's!INSTALLACCOUNT!MYACCT!g ' ~/onReboot chmod +x onReboot
-
Put a reservation in your DHCP server if desired. You could also change the above to hard code the IP address in addition to the SSID/password. Obviously you could choose wired over wifi if needed (I wanted less wires coming from the piano).
-
I found it necessary to turn the wifi "on" switch in the settings to get the system to boot properly sometimes. Being off sets "soft blocked" which you can un-set, but it still appears to need help on boot to get up and get an IP.
-
OK, now let's see if the configuration works. Try this. NOTE: This may log you out via SSH, you might want to do it from a console terminal session.
sudo netplan --debug try
-
See if it appears to work, if you get syntax errors fix the netplan file above until this works properly. It probably will NOT work right for the wifi (it will likely not pull an address). I found it needs not just a reboot but a power cycle at this point, so shut down, power off, wait a few seconds, and reboot. Also, the above command may log you off (you should be able to just reconnect).
-
After the reboot see if the network comes back up properly with both wired (if still connected - probably best) and wifi. If not, try removing the kernel source and redoing that second again, and try another power off reboot.
-
The following commands generally update the lock screen, etc. :
nano dodbus # add the following lines #!/usr/bin/env bash gsettings set org.gnome.nautilus.desktop trash-icon-visible false gsettings set org.gnome.desktop.screensaver lock-enabled false gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing' gsettings set org.gnome.desktop.screensaver idle-activation-enabled false gsettings set org.gnome.desktop.session idle-delay 1800 chmod +x dodbus # from the touch screen (terminal or run from the file browser) ./dodbus
-
Let's start installing prerequisites.
sudo apt install cifs-utils qt5-default git cmake libfreetype6-dev libfontconfig1-dev libjpeg-turbo8-dev libopenjp2-7-dev libpoppler-qt5-dev libasound2-dev qtcreator libpoppler-qt5-dev
Configure Calibre share
-
If you have Caibre on a windows system, set up a share for it. This example points to a drive, and then lets the path be defined in the program; you could put to the explicit folder with Calibre in this as well, just adjust the code as appropriate for the path name. This is not a terribly secure way to put in the password, but you can use other techniques if needed:
sudo mkdir -p /mnt/MYFILESERVER/MYDISKDRIVE sudo nano /etc/fstab # and add the line: //MYFILESERVER.MYDOMAIN.COM/MYDISKDRIVE /mnt/MYFILESERVER/MYDISKDRIVE cifs vers=3.0,username=MYACCT,password=MYSMBPASSWORD,iocharset=utf8,uid=MYACCT,gid=MYACCT,nobrl 0 0
-
See if it works
sudo mount -a # check for errors
-
The "nobrl" (No Byte Range Locking) is required for write access to the database. It is worth noting that concurrent write access to a SQLite database on a share is not recommended, and using the write feature may introduce a corruption risk to the shared database, especially if you update Calibre at the same instant MusicalPi updates it. MusicalPi reduces that risk by holding the database open only for the instant it needs to write.
Pull down software and build
-
You will need MidiFile, which is a project at Github at craigsapp/midifile, but I made some slight changes, so unless it has been updated, use my fork and branch as follows. The change is addition of two more logical functions for determining midi item types:
# if in root exit out to unprivileged mode cd ~ git clone https://github.com/Linwood-F/midifile.git cd midifile git checkout addKeyTimeSignatures make library -j4
-
If you are using a development system, you may want to copy software from there to this system. If not, you can just clone the git repository to this system and build directly. Or if you fork my release, you can clone that. We pulled this down earlier, so let's build:
cd ~/MusicalPi qmake make -j4
In your Calibre library:
-
Put in PDF's that are music
-
When scanning PDF's, crop TIGHT around the music to provide the largest image on screen
-
Tag each PDF that is musing with the tag "Music" (you can change this if desired in the constants)
Try It
-
Now if you run the project you should see your library appear and be able to display music. You should run it the first times from terminal (e.g. open terminal, then ./MusicalPi/MusicalPi) as the debug info will appear in this window, and any problems may be more readily apparent.
-
Note that most settings are not in piconstants.h but in the settings file, which has defaults contained in the oursettings.cpp file. However, rather than changing them there, just run the program (let it fail on the library -- hopefully it will at least run), and go into settings and correct paths, midi ports, etc. Midi port only matters if you have an external midi keyboard.
Kodi and Pianodisc music
Here begins a long story I will just skip, of trying to get this computer to take the place of the Apple Airport Express that comes with every Pianodisc system. Instead just some solutions. I decided we wanted to move our Pianodisc music library (over 1000 songs of piano or piano + accompaniment) onto the new MusicalPi system, so one could play not only Midi from there, but also the purpose-arranged Pianodisc music. That music is audio, not midi, and no converter (other than their hardware) could be found for changing to Midi. Plus many tracks have accompaniment, e.g. orchestra, and that requires audio. The Pianodisc standard is iTunes, through Airplay.
I experimented with various iTunes look-alike, but Apples encryption made actually using the Airplay problematic, so I shifted to using the Pi's output itself, and playing directly there. Doing that offered several alternatives, like Rhythmbox (in the distro), Audacious, etc. I settled on the relatively straightforward path of Rhythmbox at first, then later (as mentioned far below) ended up using Media Monkey as an organizer, and Kodi as a player.
apt install kodi sqlite3 libdbd-sqlite3-perl
If using Kodi for Pianodisc music, where one channel is encoded midi and one is audio, you can use the balance to change the relative loudness of the piano and the included audio.
Setup Desktop and to start automatically
Create the desktop entries for Musical Pi:
mkdir -p ~/.local/share/applications
mkdir -p ~/.config/autostart
nano ~/.local/share/applications/startMusicalPi.desktop # create file and add lines as follows
[Desktop Entry]
Type=Application
Path=/home/MYACCT/MusicalPi
Exec=/home/MYACCT/MusicalPi/MusicalPi
X-MATE-Autostart-enabled=true
Name=MusicalPi
Comment=Sheet Music Reader
Icon=/home/MYACCT/MusicalPi/MusicalPi.gif
Categories=Utility
This should put the program as an application (we'll autostart in a minute).
I wanted a remote controllable media player and used Kodi, and wanted it to auto-start also:
nano ~/.local/share/applications/startKodi.desktop
[Desktop Entry]
Type=Application
Exec=/usr/bin/kodi
Name=Kodi
Comment=Kodi Pianodisk Player
Categories=Utility
Icon=/usr/share/icons/hicolor/48x48/apps/kodi.png
The above put the items in as applications, now set as executable, and auto-start.
chmod +x ~/.local/share/applications/startMusicalPi.desktop
chmod +x ~/.local/share/applications/startKodi.desktop
ln ~/.local/share/applications/startMusicalPi.desktop ~/.config/autostart/MusicalPi.desktop
ln ~/.local/share/applications/startKodi.desktop ~/.config/autostart/Kodi.desktop
You can put them (and only them) in favorites on the dock bar by:
gsettings set org.gnome.shell favorite-apps "['org.gnome.Nautilus.desktop', 'startMusicalPi.desktop', 'startKodi.desktop', 'org.gnome.Terminal.desktop', 'gnome-control-center.desktop']"
Set Auto-Login
If you did not during setup, you may want to set auto-login so it is just ready and waiting at all times.
sudo nano /etc/gdm3/custom.conf
Uncomment and set lines as:
AutomaticLoginEnable = true
AutomaticLogin = MYACCT
Then
sudo nano /var/lib/AccountsService/users/MYACCT
Make sure that "XSession=ubuntu-wayland"
Clean up
sudo apt autoremove
Reboot and try it
Initially I found this was necessary to suppress MANY error messages, reportedly due to PHP installing an SNMP module but not installing SNMP (presumably you may be able to remove PHP but I think it might be there for a reason).
sudo apt-get install snmp
You may want to remove the Ethernet if you plan to count on wifi for a final test. Hopefully it will start and run, and see the library.
If using Kodi, I also suggest:
- Skin - use the estouch (touch mode)
- Zero config off
- Control via HTTP 8080 username kodi password kodi (or as you prefer)
- Screensaver: none
- Add the pianodisc music share
- System, Display mode = windowed
- Hit search under music, load the global search addin
- Under the skin, remove everything but music
- Media, set to scan library on startup
Other info
I used the following program to build playlists (which then also builds scripts for Home Assistant):
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
#use File::Basename;
use DBI;
#use lib dirname($0);
my $playlistPath = "/home/ferguson/.kodi/userdata/playlists/music/";
my $mm5Path = "/mnt/lef/t/MediaMonkey 5/portable/MM5.db";
my $pdPath = '\\mnt\\lef\\t\\';
my $dbh = DBI->connect('dbi:SQLite:dbname='.$mm5Path,'','',{AutoCommit=>1,RaiseError=>1,PrintError=>0});
# Get rid of existing playlists (all!)
my $errors;
while ($_ = glob($playlistPath . "*" ) )
{
next if -d $_;
unlink($_) or ++$errors, warn("Can't remove $_: $!");
}
exit(1) if $errors;
# Get a list of playlists
my $stmt1 = qq(select IDPlaylist,replace(pl.PlaylistName," ","_") from Playlists pl where PlaylistName like 'Pianodisc%');
my $sth1 = $dbh->prepare( $stmt1 );
my $rv1 = $sth1->execute() or die $DBI::errstr;
while(my @row1 = $sth1->fetchrow_array())
{
my $alias = $row1[1]; # Call it "Piano" not "Pianodisc" in Home Assistant for the activate command
$alias =~ s/Pianodisc/Piano/g;
$alias =~ s/_/ /g;
print "play_". lc $row1[1] . ":\n";
print " alias: " . $alias . "\n";
print " sequence:\n";
print " - data:\n";
print " method: Player.Open\n";
print " entity_id: media_player.notes\n";
print " item: { file: \"special://profile/playlists/music/" . $row1[1] . ".m3u\"}\n";
print " service: kodi.call_method\n\n";
# Dump into the playlist all the titles
my $filename = $playlistPath . $row1[1] . ".m3u";
open (my $fh, ">", $filename) or die "Could not open file $filename due to $!";
my $stmt2 = "select replace(replace(s.SongPath,':\\',\"$pdPath\"),'\\','/') " .
"from Playlists pl " .
"inner join PlaylistSongs ps on ps.IDPlaylist = pl.IDPlaylist " .
"inner join Songs s on s.ID=ps.IDSong " .
"where pl.IDPlaylist = " . $row1[0] . " " .
"order by ps.SongOrder";
my $sth2 = $dbh->prepare( $stmt2 );
my $rv2 = $sth2->execute() or die $DBI::errstr;
while(my @row2 = $sth2->fetchrow_array())
{
print $fh $row2[0]. "\n";
}
close $fh;
}
$dbh->disconnect();
Review this (https://www.leferguson.com/musicalpi-piano-sheet-music-display-qt-version-runs/) for some running tips.
This (as of this writing unanswered) question relates to the difficulty of using the touchscreen and a workaround with Wayland (https://unix.stackexchange.com/questions/476576/disable-device-removed-from-touchscreen-hid-on-ubuntu-18-10)
I later started having wifi issues after I switched to wireless, and upgraded to 19.10 and they persisted. I found that I was getting errors from wpa_supplicant about two processes running. I ended up going back to wired. I suspect that networkmanager is still running, so I disabled it as follows:
sudo systemctl stop NetworkManager.service
sudo systemctl disable NetworkManager.service
sudo systemctl stop NetworkManager-wait-online.service
sudo systemctl disable NetworkManager-wait-online.service
sudo systemctl stop NetworkManager-dispatcher.service
sudo systemctl disable NetworkManager-dispatcher.service
sudo systemctl stop network-manager.service
sudo systemctl disable network-manager.service
That didn't fix my wifi issues but did cause it to stop giving the supplicant duplication errors, and actually the errors were worse, but that allowed me to track down that it was power management which seems difficult to turn off:
sudo nano /etc/rc.local
iwconfig wlan0 power off ### this line added
exit 0
This enables power management on each boot (systemd appeared, at least in my install, to automatically call rc.local (you can check here: sudo systemctl edit --full rc-local )
Home Assistant and Remote Control
In late 2019 I decided to redo some of this to get remote control of the playback from the pianodisc library, notably from Home Assistant, which I had been using for automation. This turned out to be surprisingly difficult. My goal was to have a media library somewhere, and be able to play it from a decent UI on the piano, but also to play items from it from something Home Assistant could control. And Rhythmbox did not look controllable, at least not with anything out of the box.
I went through a number of attempts - mopidy had an awful user interface, and did not seem to bring much to the party, though it did have a renderer that I could access. I tried setting up the attached linux box as itself a renderer with gmediarender without success -- it would just hang. I then tried the source version (gmrender-resurrect) which was a bit later, and it worked fine so long as I was running it manually, I could not get it working as a server (pulse audio issues). I did get to work, but decided it did not really solve my problem, as it was not itself a client. I could probably have made it work, somehow extracting info from Rhythmbox, building static lists in Home Assistant, but I would still be using Rhythmbox also. See, I wanted a media library that I could incorporate regular music into as well, for use on other speakers but with Home Assistant.
Clementine -- it had a Home Assistant control but... astoundingly... it could not play tracks. Why someone thought a remote control that ONLY could do volume, etc. was useful, but no track selection, boggles my mind.
Plex - I spent a lot of time on plex, and besides being incredibly aggressive at wanting me to set up an account, it just did not solve my problems. I could play music locally from it, with a 3rd party player, but I could not seem to remote control that player. And you cannot (as best I can tell) tell the server to play music on its own. Pass.
I finally ended up with good ole Kodi, and MediaMonkey (beta 5.0). I had been using MediaMonkey for a while for regular audio tracks, and thought I could finagle it to solve this problem. Ideally I would use their server, and a MM linux client, and have remote control... yeah, they are FAR from that. But, I can use MM5 to be an organizer, then with a bit of SQL magic and overlaying the library folders, let Kodi handle the pianodisc tracks and playing.
Anyway, the above has been modified a bit to include Kodi in it, for that reason, and remove Rhythmbox.
Along those lines, it is convenient at times for the piano to be a DLNA server also, so I can play to it directly. I found this works:
cd ~ # be sure in non-priv
sudo apt install git build-essential autoconf automake libtool pkg-config libupnp-dev libgstreamer1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav
git clone https://github.com/hzeller/gmrender-resurrect.git
cd gmrender-resurrect
./autogen.sh
./configure
make
So it will run automatically on GUI login:
nano ~/.local/share/applications/startRender.desktop
[Desktop Entry]
Type=Application
Path=/home/ferguson/gmrender-resurrect/src/
Exec=/home/ferguson/gmrender-resurrect/src/gmediarender -f "notesRender" --gstout-initial-volume-db -20 --logfile=/tmp/gmrender-resurrect.log >> /tmp/gmrender-resurrect.log 2>&1
Name=GMediaRender
Comment=Run background renderer (DLNA server)
Categories=Utility
chmod +x ~/.local/share/applications/startRender.desktop
ln ~/.local/share/applications/startRender.desktop ~/.config/autostart/startRender.desktop
I found running this as a service, or even a deamon, to be problematic. It needs to be running under the ID of the logged in user, and seemed most stable to just run it directly on login (which that location does).