Adding wildcards to Google AIY actions on Raspberry Pi.

I’ve been playing with Google AIY on raspberry pi for nearly an hour now and I love it. If you are lucky you can get your kit from issue 57 of The MagPi Magazine.

Google provided a python based example app that recognises the command you spoke to the box and runs your action. The problem with it is that the command needs to match literally without and option to add variable part (a parameter). In real world I want to give parameters to the commands, for example “Add note my note“. So I’ve hacked the app to do just that. Here are the steps:
1. Modify the to recognize patterns. In class class KeywordHandler(object): change the handle method:

class KeywordHandler(object):

    """Perform the action when the given keyword is in the command."""

    def __init__(self, keyword, action):
        self.keyword = keyword.lower()
        self.action = action

    def get_phrases(self):
        return [self.keyword]

    def handle(self, command):
        if("*" in self.keyword):
            match = re.match(self.keyword.lower(), command.lower())
            if match:
                return True
            if self.keyword in command.lower():
                return True
                return False

2. Make sure the action you are running understands that the param given to it is the variable part. I’ve modified the SpeakAction to do just that:

class SpeakAction(object):

    """Says the given text via TTS."""

    def __init__(self, say, words):
        self.say = say
        self.words = words

    def run(self, voice_command):

3. Add new action in make_actor method:

    actor.add_keyword(_('add note (.*)'),SpeakAction(say,"adding $1"))

Have fun!


Speed tests of SD cards on Raspberry Pi

Here are some speed results of speed of two sd cards on two different Raspberry Pis (old 256MB and new 512MB one). I followed methodology listed on

Write speed
sync; time dd if=/dev/zero of=~/test.tmp bs=500K count=1024; time sync
Read speed
dd if=~/test.tmp of=/dev/null bs=500K count=1024

And here are the results:

SanDisk Extreme class 10 UHS-1 45MB/s
New Raspberry Pi:
 write: 524288000 bytes (524 MB) copied, 27.2083 s, 19.3 MB/s
 read: 524288000 bytes (524 MB) copied, 22.5482 s, 23.3 MB/s
Old Raspberry Pi:
 write: 524288000 bytes (524 MB) copied, 28.5079 s, 18.4 MB/s
 read: 524288000 bytes (524 MB) copied, 22.6449 s, 23.2 MB/s
Centon class 4 (cheap card from Walmart)
New Raspberry Pi:
 write: 524288000 bytes (524 MB) copied, 112.908 s, 4.6 MB/s
 read: 524288000 bytes (524 MB) copied, 30.2082 s, 17.4 MB/s
Old Raspberry Pi:
 write: 524288000 bytes (524 MB) copied, 106.991 s, 4.9 MB/s
 read: 524288000 bytes (524 MB) copied, 27.7869 s, 18.9 MB/s

Result: spend five dollars/pounds more and buy a proper card.


Playing DVD on Raspberry Pi

I’m using Raspberry Pi as a media center using raspmbc, which is amazing for streaming (bbc iplayer, 4od) and playing files from NAS and USB. For DVDs I still needed to connect my laptop to TV, which is just an unnecessary effort. Being geek I knew I have to enable RPi to play my DVDs.

First thing I discovered about RPi as DVD is that it let’s you skip all anti-piracy warnings!:

People say it will also ignore region protection (quite useful for my collection of dvds I bought in US)!

So what did I need?
* External DVD (I have actually bought a blu-ray external drive from ebay for 15.89GBP + 2.99P&P, which will work with my macbook air as well).
* Powered USB hub. Raspberry Pi won’t provide the drive with enough power. I’m actually connecting the DVD directly to RPi and using the hub to supply power only. It seems RPi can be powered from the same hub via normal USB connection, which eliminates a need for second power supply.
* A bit of the software:
** MPEG2 Licence – 2.4GBP from
** DVD plugin for XMBC (OOTB support doesn’t work good enough yet):

Et voila!

ps. when you buy stuff from ebay please check if the seller is paying taxes in your country (eg. is company registered in your country). If not, find another one even if you cost you a pound more. Thanks!


Raspberry Pi, servo motor, gpio, i2c and soldering weekend

This weekend I decided to work on my soldering skills and finally assemble the PWM driver PCA9685 I bought from Adafruit couple weeks back. Not all solder points looks perfect, but I’ve manage not to burn the PCB which I consider a major success. I thank all the
guys how put soldering tutorials on the youtube!


Then I played with software.
* I2C: I used python to steer servo controller via I2C interface. For some reason the Raspbian image has I2C kernel module disabled, so I had to comment blacklist i2c-bcm2708 in /etc/modprobe.d/raspi-blacklist.conf and the add i2c-dev and i2c-bcm2708 to /etc/modprobe to enable them to start.
* GPIO: Raspbian has all libraries loaded by default for GPIO development in python. I had encountered hardware problem instead – there’re many sources on the web describing pin layout of GPIO port, but non of them says which pin is the physical pin 1! I have some gaps in basic knowledge, so I have missed a small rectangle marking P1 – it’s the one nearest to the side of the board in bottom row. See a picture with pins P3, P5, P9, P10 and P11 connected:

And here it is – Raspberry Pi waving The Flag of the United States of America


MGPlayer on Raspberry PI (javafx!)

I’ve just “successfully” run my MG Podcast Player on Raspberry Pi using just released JDK8 for ARM Preview.

Performance isn’t great compared to desktop system and it doesn’t actually play mp3 files (Media are not supported yet), but having ability to run a java 8 application on $35 is amazing by itself!

If you want to try follow the steps on oracle site to install the image and then run:
$ /opt/jdk1.8.0/bin/java -Djavafx.platform=eglfb -jar MGPlayer.jar

* -Djavafx.platform is crucial as it let javafx work on OpenGL ES 2.0 embedded device
* I’ve installed java on my raspbmc image