No Comments

Powering a Pi Zero (2) from your laptop

{}
November 12th, 2021

The new quad-core Pi Zero 2 has a lot more horsepower than the original Zero and as a consequence it does require more power than the original Zero.

But that doesn’t necessarily means that you cannot power it from an USB port from your laptop.

Can you still power a Raspberry Pi Zero from an USB port of a laptop?

Let’s try. Be reminded all Pi’s are cleverly designed to throttle down, when they experience a power shortage.

To check if your Pi has throttled down:

> vcgencmd get_throttled
throttled=0x0

If you see some other output then 0x0 yes then you’ve had power problems. Otherwise you’re OK.

For the moment, running Raspberry Pi OS Bullseye on a Raspberry Pi Zero 2 powered form an USB port doesn’t show problems by just installing programs and updating the OS.

No Comments

No display after update to LibreElec 10.0.1 on a Raspberry Pi 4

{}
November 9th, 2021

Last weekend I did an upgrade on my Kodi/LibreElec 10.0.0 RPI4 to 10.0.1.

All went well initially, I also did a firmware upgrade, but after rebooting I got a blank screen.

For a moment I thought Kodi didn’t boot at all, but on my Kore remote app, I saw that it was connected.

Also I could hear the GUI sounds. I disconnected my monitor, tried different HDMI inputs and different settings on the monitor. To no avail. Rebooted my Pi again. Shut it down, disconnected the power, connected it again, and rebooted. Still a blank screen. Could see the blown up pixel for a while, but blank screen afterward.

Still I could hear the GUI sounds, and I could even start a DVB-T TV channel.

So Kodi was working, but there was no HDMI output! Then intuitively I changed the audio-output from IQAudioDAC to HDMI and suddenly it started working! I changed it again to IQAudioDAC and screen output kept working.

And it did since!

Somehow changing the audio output fixed the blank screen output on my Raspberry Pi 4. Weird.

And don’t ask me why, but I’m still happy with this LibreElec / Kodi setup on my Raspberry Pi 4.

Changing Audio output remotely on Kodi

To change the audio output for Kodi remotely, instead of using the GUI or the Kore remote app and a lot of clicks, you can use these commands from another PC or phone:

Change to HDMI

curl -v -H "Content-type: application/json" -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"PI:HDMI"},"id":1}' http://yourpi.local:8080/jsonrpc

Change to analogue

curl -v -H "Content-type: application/json" -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"PI:Analogue"},"id":1}' http://yourpi.local:8080/jsonrpc

 

Remember to change the domain/hostname ot an IP-address if you wish to run the command from your Android phone.

Above commands work great as Termux Widget shortcuts on your Android Phone.

No Comments

Playing 4K smoothly on the Pi4, compiling Kodi 19 on Raspberry Pi OS

June 24th, 2021

Kodi is the best software to watch video on a Raspberry Pi. The Raspberry Pi 4 supports 4K, but the only software that can play it well is Kodi. That’s a bit disappointing, knowing the the Pi4 is already available since early 2019.

On the other hand, Kodi is nice open source software, with a thriving community.

Playing video in a browser is energy-wise, (privacy-wise IMHO) and performance-wise a bad thing. Try playing YouTube movies in a browser and in Kodi (unofficial YouTube plugin), and see the differences. Stuttering play, and high CPU usage in the browser, smooth play and lower CPU usage in Kodi.

The best performance for Kodi is offered by LibreELEC, a lightweight ‘Just enough OS’ Linux distribution. if you wanna run the latest Kodi on Raspberry Pi OS, you’ll need to compile it yourself at the moment.

Compile instructions Kodi 19

There isn’t yet an updated version Kodi 19 in Raspberry Pi OS, so you’ll need to compile Kodi 19 yourself. Big underlying changes in the way video and hardware-accceleration is done in the new kernel 5.10 broke Kodi 18.7 and

On the Kodi forum there are several attempts to compile a working version, but apparently that is not so simple. Still I used those instructions as a base, but added the kernel-header packages ` as a dependency and use a patched version of Kodi.

# sudo apt update && sudo apt full-upgrade -y


sudo apt install                                                     \
autoconf automake autopoint autotools-dev cmake cpp curl default-jre \
g++ gawk gcc gdc gettext git gperf libasound2-dev libass-dev             \
libavahi-client-dev libavahi-common-dev libbluetooth-dev             \
libbluray-dev libbz2-dev libcdio-dev libcec4 libcec-dev              \
libcrossguid-dev libcurl4-openssl-dev libcwiid-dev libdbus-1-dev     \
libdrm-dev libegl1-mesa-dev libenca-dev libflac-dev libfmt3-dev      \
libfontconfig-dev libfreetype6-dev libfribidi-dev libfstrcmp-dev     \
libgbm-dev libgcrypt-dev libgif-dev libgles2-mesa-dev libglew-dev    \
libglu1-mesa-dev libgnutls28-dev libgpg-error-dev libgtest-dev       \
libinput-dev libiso9660-dev libjpeg-dev liblcms2-dev liblirc-dev     \
libltdl-dev liblzo2-dev libmariadb-dev libmicrohttpd-dev libnfs-dev  \
libogg-dev libomxil-bellagio-dev libpcre3-dev libplist-dev           \
libpng-dev libpulse-dev libshairplay-dev libsmbclient-dev            \
libsqlite3-dev libssl-dev libtag1-dev libtiff5-dev libtinyxml-dev    \
libtool libudev-dev libunistring-dev libva-dev libvdpau-dev          \
libvorbis-dev libxkbcommon-dev libxmu-dev libxrandr-dev libxslt1-dev \
libxt-dev lsb-release meson nasm ninja-build python3-dev python3-pil \
python-support rapidjson-dev raspberrypi-kernel-headers swig unzip \
uuid-dev wayland-protocols yasm zip zlib1g-dev

Then you need a special GBM version of Kodi, but instead of this version.

wget https://github.com/popcornmix/xbmc/archive/gbm_matrix.zip

I used a patched version:

wget https://github.com/graysky2/xbmc/archive/refs/heads/gs-gbm_matrix.zip

Then this workaround is needed, Raspberry Pi OS uses a different path for some files. This just creates a symbolic link to the right path.


# drm_fourcc error workaround
sudo mkdir /usr/include/drm/ 
sudo ln -s /usr/include/libdrm/drm_fourcc.h /usr/include/drm/drm_fourcc.h

Extract the downloaded zip:

unzip gs-gbm_matrix.zip

Enter the map

cd xbmc-gs-gbm_matrix

Create build directory:

mkdir kodi-build

Enter build directory

cd kodi-build

Then make:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCORE_PLATFORM_NAME=gbm -DAPP_RENDER_SYSTEM=gles -DX11_RENDER_SYSTEM=gles -DENABLE_INTERNAL_FMT=ON -DENABLE_INTERNAL_FLATBUFFERS=ON -DENABLE_INTERNAL_SPDLOG=ON -DENABLE_VAAPI=OFF -DENABLE_VDPAU=OFF

Then compile

cmake --build . -- VERBOSE=1 -j$(getconf _NPROCESSORS_ONLN)

If done properly, ti should take about 2 hours. Afterwards you can start Kodi with `kodi-build/kodi-gbm`

That’s all. And don’t forget to backup your existing Kodi profile.

Occasionally the script exits with an error. Seems it’s running out of memory. Just restart the building process, executing the cmake –build command, to finish compiling.

No Comments

Serve images in next-gen formats, start using webp

June 11th, 2021

Since Apple added webp support in Safari on both desktop and mobile devices, it’s worth serving images in webp to significantly reduce the size of your images while preserving their quality.  As a guess, you can save 50-66% bandwidth on your images!

Yes, mother earth will like that!

Webp is nowadays supported by 95% of all devices

You can check webp support here, in general you will will be covered for about 95% of all users. A small 5% is using older (out-of-date) software, that probably shouldn’t be used anymore. Now they have a reason to stop using it.

https://caniuse.com/webp

Creating next-gen webp images

Converting jpg to webp isn’t difficult on a modern Linux computer:

convert -quality 50 image.jpg  image.webp

I guess no explanation is needed here.

For a directory of images you could do something like :

mogrify -quality 50 -format webp *.jpg

Creating next-gen webp images the smart way on multi-core machines

On a multi-core machine, start using those cores by running tasks parallel:

parallel "convert -quality 50 -auto-orient {} {.}.webp" ::: *.jpg

This will use all cores and threads and speed up generating next-gen images considerably, 800%  on a modern quad-core machine.

Advantages of webp images

  • webp supports transparency
  • webp supports animation
  • webp supports 24bit RGB color-support
  • smaller size

For PNG images you can save 90% bandwidth, when the main reason to use PNG is transparency.

What about image quality?

Image quality is a subjective matter. I find it acceptable to use a 50% quality by default. Compared to jpg: 60% size reduction, and less artifacts but a bit smoother. That’s OK for me.

No Comments

Raspberry Pi Foundation fixes `Microsoft privacy leak`

March 11th, 2021

The Raspberry Pi Foundation pushed an update to fix the forced addition of the not-so-opensource Visual Studio Code editor from Microsoft to the Raspberry OS repositories.

That means that no longer pings are automatically send to the servers from Microsoft every time a user is checking on his Pi for updates. That is great.

What is exactly done:

Unpacking raspberrypi-sys-mods (20210310) over (20210208) ...
Setting up raspberrypi-sys-mods (20210310) ...
Blocking vscode repo...
Removing obsolete conffile /etc/apt/preferences.d/3rd_parties.pref ...

So this file has been  /etc/apt/sources.list.d/vscode.list has been emptied:

### Disabled by raspberrypi-sys-mods ###

In an earlier post we already advised to edit that file to disable the automatic checking.

We’re glad the Raspberry Pi Foundation followed our advise 😉 .

Furthermore this file has been removed: /etc/apt/preferences.d/3rd_parties.pref

cat /etc/apt/preferences.d/3rd_parties.pref
Package: code code-exploration code-insiders
Pin: release o=code stable
Pin-Priority: 400

Package: *
Pin: release o=code stable
Pin-Priority: -1

Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 400
~

Still the big question, Microsoft is touting about open source and coding for everybody. Why their open source code editor is not released with an open source license is still unanswered. Proprietary telemetry is too important apparently. Disappointing.

Let’s end by citing Jim Bennet, a Microsoft evangelist.

As a young child it was mind-blowing when my Dad brought home a work PC so he could write reports and I could use it to write up my school work – I was using what Dad used at work, making me feel important. I see this with my seven-year-old daughter, seeing her excitement that I use Microsoft Teams for work, the same as she uses for her virtual schooling (she’s even offered to teach me how to use it if I get stuck). To be able to bring that unadulterated joy of using ‘grown-up tools’ to our young learners is priceless.

Arghh, what more to say, a free sample, a marketing trick, priceless for Microsoft. Another reason why schools and kids should use only open source software.

Share knowledge, don’t exploit it.

No Comments

Debugging Audio problems on a Raspberry Pi

February 21st, 2021

A Raspberry Pi is a great small computer that can run 24 hours with no problem, and just consumes a few watts, so it’s a fine candidate for a modern flexible media player.

The default high quality sound output of a Raspberry Pi is HDMI, which is great for video, but not so great for classic stereo systems. The standard analogue out is near CD quality. Fine for system sounds and video calling, but not enough for HiFi. Remember the Pi is designed as a cheap computer for educational purposes.

HiFi audiophiles probably want to add a dedicated USB-DAC (you lose an USB port) or dedicated HAT like HiFiBerry or IQAudio.

ALSA and PulseAudio soundserver

Then we have the software thing. Raspbian always used Advanced Linux Sound Architecture (ALSA) as the driver and skipped the layer of PulseAudio, which is the default sound server that lays on top of ALSA in modern Debian and Ubuntu desktops.

Since the Pi400 was introduced, and marketed as a serious affordable desktop, the now renamed Raspberry Pi OS, started to offer PulseAudio as well in December 2020. The big win of PulseAudio, better support for Bluetooth and more programs can output sound at the same time. With ALSA output would be locked  by one program: you can’t mix.

Well with a caveat. Raspberry Pi OS with desktop is shipped with PulseAudio, but Raspberry Pi OS Lite is not shipped with PulseAudio, because shipping it with PulseAudio would make it a Raspberry Pi OS Medium. ;(

So Raspberry Pi OS Lite uses just ALSA, Raspberry Pi OS with desktop uses also ALSA, but on top of that the PulseAudio layer.

Debug audio on a Raspberry Pi

Check the hardware, it doesn’t matter in this step if you use PulseAudio or not.

Start with listing all audio outputs:

aplay -l

This should output something like:

**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 2: IQaudIODAC [IQaudIODAC], device 0: IQaudIO DAC HiFi pcm512x-hifi-0 [IQaudIO DAC HiFi pcm512x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: DAC [USB AUDIO DAC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Here you see the four outputs: HDMI output (0), analogue out (1),  IQAudio HAT  (2), and an USB-DAC (3)

To test your hardware, upload a test.wav file to your Pi (aplay can’t play mp3 files), and try the different outputs.

aplay -D plughw:0 test.wav # HDMI
aplay -D plughw:1 test.wav #headphones/audio out
aplay -D plughw:2 test.wav # iqaudio
aplay -D plughw:3 test.wav # USB DAC

Of course you need to have the outputs properly connected to an amplifier, monitor or headphone. Now you know your hardware is working OK.

Check for a faulty power supply

If you have hisses, or distortion, also always check your Raspberry Pi for throttling and a possible power or heating problem:

vcgencmd get_throttled
throttled=0x0

If you see a different output, that suggests you have a faulty power supply. Phone chargers typically are not stable PSU’s. Better use the official Raspberry Pi power supply. Also the quality of the cable really does matter.

If that is also OK, it’s just about configuring the right output in your software.

Configuring the Music Player Daemon

To set the IQAudio HAT as the default ALSA output in /etc/mpd.conf

audio_output {
type "alsa"
name "IQAudio"
device "hw:2" # set hw:3 for DAC out
}

To set PulseAudio as the default output:

audio_output { type "pulse" 
name "pulse audio" 
}

Do not edit boot/config.txt by default

In general there is no need to edit /boot/config.txt. Official HATS will configure automatically and the same goes for USB-DACS. Plug and play. You see older tutorials or manuals instructing you to edit /boot/config.txt for configuration. IMHO that is only needed in special cases. If you don’t know what you’re doing, don’t edit boot/config.txt.