Google AIY Thoughts

Like many people I was very excited to see the Google AIY Raspberry Pi addon. Before my copy of the MagPi magazine arrived with the kit I had already installed the software on a linux laptop. One of the things I liked about the project is that, whilst it is to some extent targetted at the Raspberry Pi, it is actually a very good example of using standard modules and frameworks to produce something that is very cross platform and should work very easily on a variety of systems with very little work.

One of the aspects I would like to talk about today is the method used for the LED status indicator. Unlike the speech processing the LED is rather Raspberry Pi specific, as it depends on GPIO locationsupport which is not likely present on other platforms. However the way that this has been implemented allows you to ignore or reimplement it quite trivially in some other way.

How did they do this? Simply put they used a system called mknod to create a FIFO that can be accessed as a file. This file is then used as the input source to the python script. Anyone that wants to change the led state simply writes to that file.

I have produced a simple example that illustrates how this can be done quite easily.

First the python file which will receive messages.

This simply loops until it sees user input that is equal to “Hello 9” printing what if not a:
ever is input in reverse (note this is for python 2.7, if you are using python 3 you would replace raw_input with input).

Next the producer

This writes to a file called myfifo.txt , flushes the write after each line and then sleeps.

If you just run this as it is you will end up with a file containing lines from Hello 0 to Hello 9
The secret sauce is in the next bit.

This will compile the C code for the producer
use mknod to create the fifo
Launch the python script in the background redirecting myfifo.txt as user input
and then launch the producer which will write to the fifo.

There you now have a nice simply way of sending a message from one process to another.

Leave a Reply

Your email address will not be published.