Distance Sensor
The first part of the hack is to wire up a Distance Sensor to measure how far away a potential reader is. As they move nearer, Arnie says various phrases to attract their attention.
GPIO Zero
This is a smart Python library that makes interaction with the GPIO pins really simple, you can find out more here
Control the eye LED with the simple code: from gpiozero import LED from time import sleep led = LED(17) while True: led.on() sleep(1) led.off() sleep(1) |
Playing MP3s
To enable Arnie to talk, record some classic phrases and convert them to MP3 files. (Although I was told I sound like Kermit the frog! which is not a good sound)
Install the python mp3 player type sudo apt-get install mpg321 To play an mp3 use the code os.system('mpg321 foo.mp3 &') time.sleep(5) os.system(‘sudo killall mpg321’) A Red LEDArnie was the Terminator and therefore he does not like being ignored. If you do not follow his instructions his eye will glow red, he is angry, better leave the building fast.
|
Get to the Choppa!Spark Design Tilt SwitchThe book is on the shelf and Arnie asks you to pick it up, if you do then he responds with a new set of instructions. To identify when book has been lifted off the shelf use a tilt switch. This component enables you to measure a turn, for example the book position turning from upright, on the shelf to off the shelf and flat in your hand.
It consist of two simple contacts and a small ball bearing. As you tilt the switch the ball bearing moves and connects with the contacts. This gives you four 'states', (1 and 1, 1 and 0, 0 and 1 and finally 0 and 0. ) which can be coded to respond. |
Hacking the Book
One of my students gave me a 'spare' book which her Dad no longer wanted, it was Arnie's autobiography and set the tone for the hack. Several holes were drilled into the side of the book for the Distance Sensor and one hole on the front for the LED to poke through as an eye. A rectangle was cut into around 300 pages to make space to hide the RaspPi and battery.
|
Bluetooth SpeakerUsing a Pi3 means that the required Bluetooth hardware is already available. The latest OS image Jessie also contains the required drivers and a software interface. Set is easy, just pair with the device however, I found that mpg321 would not play through the speakers. I tried PyGame and at this point June 2016 that does not stream music either. The good news is that VLC player works!
Install it with: sudo apt-get install vlc and then in Python use os.system ("cvlc name_of_file.mp3 &") |