brandorf.com The everyday ramblings of one nerd.

20May/13

Annoying people with a Raspberry Pi

The Raspberry Pi is a neat little device. First and foremost, it's a complete little computer, secondly it's very easy to program for, allowing a software guy like myself to have a much lower learning curve to AVR-style programming than you would have on an Arduino or Launchpad. I've had one for a while, but nothing immediately sprung to mind about anything fun to do with it, so it disappeared into the big bucket of projects-that-might-be.

I eventually decided to use it for evil. To sic Navi on the poor victim, like a more annoying version of the Annoy-a-tron
(If that's possible?).

Principal ingredients for this is the Pi itself, and some speakers. I'm using one of those speaker case jobs designed for a MP3 players, runs off of 2 AA batteries for a very long time, unfortunately this won't power the Pi, so the Pi still needs to be plugged in (and the Pi can only provide a wimpy 50ma at 5v on pins, not enough to power a speaker). That's really it on the hardware department, the rest of the magic is software - namely Python. I've never worked with python, but the more languages you learn the easier new ones become (both spoken languages and programming). So let's bang something out and see what we can get it to do.

photo (1) photo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
 
import time
import random
import os
import subprocess
 
random.seed()
command = ["mpg321", "/etc/Navi/Navi-WatchOut.mp3"]
print "Watch Out!"
with open(os.devnull, "w") as fnull:
	result = subprocess.call(command, stdout=fnull, stderr=fnull)
time.sleep(30)
 
while (True):
	command = ["mpg321", "/etc/Navi/Navi-Listen.mp3"]
	with open(os.devnull, "w") as fnull:
		result = subprocess.call(command, stdout=fnull, stderr=fnull)
	sleepTime = random.randrange(-15,15)
	time.sleep((30 + sleepTime) * 60)
	print "Hey! Listen"
	print "Sleeping for " + str(30 + sleepTime) , " minutes."

For those of you who can't decipher this what it does is play the "Hey Listen!" sound clip at random intervals between 15 and 45 minutes between each one. It's using the linux app mpg321 to play the audio files with most of the extra bits there to hide the output from mpg321 from spamming the console. Not really needed as the prank use will not have the Pi connected to a display but hey, why not.

To make sure that this script starts each time the PI is booted, we need to add this script to Init.d I must confess I'm not entirely sure what this is doing except at a high level; registering our python script as a service, and therefore runs even if you don't log-in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /bin/sh
 
case "$1" in
  start)
    echo "Starting NAVI"
    # run application you want to start
    sudo amixer cset numid=1 90%
    python /etc/Navi/Navi.py &
    ;;
  stop)
    echo "Stopping NAVI"
    # kill application you want to stop
    killall python
    ;;
  *)
    echo "Usage: /etc/init.d/example{start|stop}"
    exit 1
    ;;
esac
 
 
exit 0

Save the scripts, chmod them if needed run update-rc.d and restart the Pi, you'll get a warning of "Lookout" and then you've got a minimum of 15 minutes to plant your annoyance bomb. Try not to get caught.

26Apr/13

Making the Retron3 a little better.

Were I live now, I'm fortunate to have what I'm beginning to assume is a shop of a dying breed: the independent video game store. This seems especially true now that GameStop owns pretty much every other game store chain. While poking my head into the one closest to me, I uncovered a little gem from my youth: , the resulting nostalgia bomb was irresistible, but now I needed a console to play on, I haven't owned a Sega Genesis since I regrettably gave mine away to a relative years ago.

While the little shop did have a Genesis in stock (and even a 32x to go with it), this thing caught my eye. The Retron 3 is a clone system that can play NES, SNES, and Genesis games, just the thing for a retrogamer who is running out of A/V inputs on his TV (and it was on sale!). I took the little thing home, with a Sega controller (good, because the "wireless" controllers that came with it were pretty awful) and was shortly afterwards playing a cyborg kick-boxer punching a caveman in the face, awesome.

Eternal Champions for Sega Genesis, at a bargain!

Eternal Champions for Sega Genesis, at a bargain!

The system seemed to work great, for my NES and Sega collections, but things went sour when I tried out one of my few SNES carts; the sound was horribly distorted as can be heard here. It sounds like some serious clipping, like the volume was cranked up too high. Turns out I was right, this was exactly the case: a little more research revealed a flaw with the assembly of the unit's SNES side. For the SNES's audio amp, they used 2.7kOhm resistors, when something like 33kOhm would have been appropriate. Perhaps this was a typo on the data sheet or similar because the resistors in question are SMD, the don't have the traditional color bands a 2.7K Ohm resister is simply marked '272' where as a closer 27k Ohm would be marked '273'. Enough of the electronic lesson, it's clear that the solution is to crack the beast open and give it a transplant.

See the little black rectangles with '272' printed on them?  They are the ones that have to go!

See the little black rectangles with '272' printed on them? They are the ones that have to go!

It's not easy, but you CAN mount standard 1/4" resistors as surface mount.

It's not easy, but you CAN mount standard 1/4" resistors as surface mount.

This seemed like a fantastic opportunity excuse to use my fancy new tool toy : SainSmart DSO203 Nano I'd wanted an oscilloscope for a long time, but being at best a hobbyist, could never justify having a full expensive bench unit. This little beauty is smaller than my cellphone, and let me trace the audio signal to the spot on the board. (In theory anyway, I was pretty new at using an oscilloscope.)

Poking around on the Retron with the scope in analog mode, to try and see where the audio signal is coming from.

Poking around on the Retron with the scope in analog mode, to try and see where the audio signal is coming from.

An example of what the scope was showing while the SNES was running.

An example of what the scope was showing while the SNES was running.

Special thanks to Benheck.com user Ace_1, who seems to be the resident expert on clone systems, for pointing me in the right direction as to which resistors to replace, as I'm still a rookie to using an oscilloscope, it was taking me a while to trace the audio out on the board.

Filed under: Uncategorized No Comments
27Mar/13

Calvin and Hobbes

Tagged as: No Comments
26Mar/13

Winner

Tagged as: No Comments