Code Blog

Displaying 1-2 of 2 results.
2016/07/31 Raspberry-Pi

Had been thinking about how to stream music at home in a convenient way, the Sonos products look quite nice, but also quite expensive. Started to look for alternatives and found out this can be done on a Raspberry Pi board. This also has the advantage I can keep using my old speaker. Seemed like a fun project so I went ahead and bought the following:

  • HIFI DAC+ sound card I2S interface (for Raspberry Pi B+/2B )
  • Raspberry Pi 2 model B (900 MHz quad-core ARM CPU, 1GB RAM) (it replaced Raspberry Pi 1 Model B+ in February 2015)
  • Power adapter (Mitsumi, 5.0V 1.8A) with USB cable
  • Black plastic box for fitting the HIFI DAC board
  • Heat sinks for the Raspberry board (for CPU and GPU)

I put the Volumio OS ( on the microSD card. Volumio is built on Linux and is open-source/free software. Another alternative is using RuneAudio. At the time I installed it I choose Volumio for better support of the hardware (I2S DAC support). Volumio is developed from RaspyFi but is supporting more embedded platforms than RaspFi did (UDOO, CuBox and Beaglebone Black and Raspberry PI).

Raspberry Pi also can do audio output via USB, but for good reliable sound output using a DAC connected to the internal I2S bus (a specialized chip-to-chip audio bus available on the board) is much better.

Volumio supports AirPlay and it can also be remotely controlled via MPoD iOS app to play locally stored music (I connect a USB-stick with music to the Raspberry Pi).

I have been running it 24/7 from Nov 2015 to July 2016, and it has been working without any problems all this time, but it just died at the end of July. Wonder if it got overheated in the Shanghai summer heat ..

Debugging steps:

  • Check incoming voltage on micro-usb
  • Change SD card (seems SD card can easily become damaged during power breaks etc)

So I will probably upgrade to Raspberry 3 now. The I2S DAC board is compatible with Raspberry Pi 3. One good thing is that Raspberry 3 looks the same as Raspbery 2 so the same case can still be used. Raspberry 3 comes with Wifi and bluetooth builtin which Raspberry 2 lacked.

Below is a script to monitor CPU and GPU temperatures on the Raspberry Pi Linux OS. Might be good to improve this and send an email or other warning if the temperature gets too high. I think I should also fit a small fan for active cooling the next time.

cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) 
cpuTempM=$(($cpuTemp2 % $cpuTemp1)) 
gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp) 
echo CPU Temp: $cpuTemp1"."$cpuTempM"ºC" 
echo GPU Temp: $gpuTemp0

The output comes out as following:

$ ./temp 
CPU Temp: 56.2ºC 
GPU Temp: 56.2ºC 

(Script from

2016/07/01 MacOSX

I've been trying to find a solution to stop my cat from turning off my Macbook Air. I normally leave the computer in the screen saver / login screen mode so that the cat can't mess up any open documents etc (this happened before). However, sometimes when I get back the computer has been completely powered off!

So obviously just running the screen saver won't be enough, instead I need a way to disable the power button on the keyboard. Unfortunately Apple hasn't designed their system with this in mind.

I found some tips at for protecting the keyboard from one's cat but that doesn't really work for me. It is more about locking down the keyboard from unintentional input, but if I turn on the screensaver (I use a hot corner with my mouse to start the screensaver btw) before leaving the computer I already don't have that problem. The power button is still active though.


Next I downloaded and installed Karabiner ( which is a free tool for remapping the Mac keyboard.


I discovered that Karabiner doesn't remap the power button any longer! (I'm running 10.11 El Capitan).

Before 10.9 pressing the power button for 1.5 would display this dialog window:

It turns out the way Karabiner remapped the power button was to detect this popup dialog. After Apple changed the behaviour in 10.9 (no popup window) it wasn't any longer possible to intercept it (it is possible to detect the key event but not stopping it from going to sleep).

Turns out this behaviour was disabled in OS X 10.9 but was later added back on as an option in 10.9.2. The following command can restore the old behaviour:

defaults write PowerButtonSleepsSystem -bool NO

Power button old behaviour (from the Apple documentation)

Power button • Tap to turn on your Mac or wake your Mac from sleep.  
• Hold for 1.5 seconds while your Mac is awake to display a dialog asking if you want to restart, sleep, or shut down. If you don't want to wait 1.5 seconds, press Control–Power button or Control–Media Eject  .
• Hold for 5 seconds to force your Mac to turn off.


There is another free tool called PowerKey ( that got broken off from Karabiner to only deal with the power button. I downloaded the code and built it in XCode.


This worked after I changed the deployment target to my current system.

Turns out Karabiner and PowerKey never were able to to what I wanted. It's useful for typing as you can re-map the powerkey to for example a forward delete. But it was never able to totally disable the power button. Maybe I should have realized this earlier, because the power button is the only way to reset / turn off the computer, so it shouldn't really be possible to easily change in software (virus/malware could really mess up the computer).

I found some good information at
Running the following command can unload (totally disable) the internal keyboard kernel extension:

sudo kextunload /System/Library/Extensions/AppleACPIPlatform.kext/Contents/PlugIns/AppleACPIButtons.kext

But even running the command above (you will preferably also need an external keyboard to reload the internal keyboard kernel extension later) will not disable the power button! The power button is the only way to reset the computer so it's actually not part of the internal keyboard. It's a very special key indeed.

In the end it might actually be better to prevent the Mac from sleeping when folding it (so it will keep downloading files or playing a movie etc). Folding the computer will for sure prevent my cat from sitting on the power button. There are some free tools available that does just that (I installed InsomniaX) but I also read some warnings that this may restrict the air flow and overheat the macbook, so this solution is also not without it's own problems. But it is still the best option I could find, as its the only way to actually protecting the power key button (physically protecting it with the screen cover).

Karabiner, PowerKey and InsomniaX are all quite useful pieces of software, so it's worth checking them out.

The new Macbook Pro (still no release date, maybe end of 2016?) is rumoured to have a TouchID function integrated with the power button, which would be great, as that will hopefully prevent my cat from powering off the computer in the future!