TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me

A talking Arnie book

I asked my Raspberry Pi club what they wanted to create and they said a book that talks to you.  Not in the conventional way of reading to you, but in a way to get your attention, to call you over and shout at you.  Even better if the book was Arnold Schwarzenegger's autobiography and he tells you to get you to 'get to the chopper now!'

I'll be back

Distance Sensor


Picture
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 LED


Arnie 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.
Picture

Get to the Choppa!

Spark Design Tilt Switch


The 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.
Picture
Picture

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 Speaker


Using 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 &")

Download the code and files from Github

Picture


Copyright 2020 TeCoEd @dan_aldred