My Payphone Runs Linux

For the 20th anniversary of the Movie “Hackers” [Jamie Zawinski], owner of DNA Lounge in San Francisco, threw an epic party – screening the movie, setting up skating ramps and all that jazz. One of the props he put up was an old payphone, but he didn’t have time to bring it alive. The one thing he didn’t want this phone to do was to be able to make calls. A couple of weeks later, he threw another party, this time screening “Tank Girl” instead. For this gathering he had enough time to put a Linux computer inside the old payphone. When the handset is picked up, it “dials” a number which brings up a voice mail system that announces the schedule of events and other interactive stuff. As usual, this project looked simple enough to start with, but turned out way more complicated than he anticipated. Thankfully for us, he broke down his build in to bite sized chunks to make it easy for us to follow what he did.

This build is a thing of beauty, so let’s drill down into what the project involved:

sewing-needles-making-connectionsKeypad

His plan was to connect wires from the payphone keypad to a USB numeric keyboard. These wires were soldered to the through hole via’s on the old payphone keypad PCB. Hooking up these wires to the USB keypad required drilling 0.5mm holes spaced 1mm apart using his Dremel on a piece of acrylic, lots of sewing needles, super glue, Sugru and a couple of days to track down dodgy connections.

Handset

Working late at night, and without a TRRS jack handy, he chopped off an old cable and somehow managed to solder its ultra-thin wires to a pin header. A corresponding socket was soldered to the four wires from the headset for the speaker and the microphone. And lots of epoxy goop to hold it all together.

Computer

The Raspberry Pi 2 B doesn’t have an audio input, so he needed a Cirrus Logic audio hat for the Pi. He had trouble getting ALSA to tango with the Audio hat, so he eventually wrote some of his own code to detect keyboard buttons and play or record messages.

Hook switch

Finally, he needed to detect the hook switch status. Sounds simple, but it took him a few more days to get it to work. Turns out the audio hat was causing all unused GPIO pins to act “floating” no matter which way he tried. Finally, after trial and error, he bent one pin on the Pi so it wouldn’t connect to the audio hat, and wired the hook switch to it directly.

Software

His main code was in Perl. In the version of Raspbian he was using, reading pin states worked in Python, but not in Perl – they would always appear floating. Since the underlying BCM2835 library is written in C, he tried writing his code in C, and that didn’t work either. As usual, python was doing its magic under the hood. So he called the Python script from his Perl code to do that, but not before running everything under “root” since that was the only way he could read the status of the pins. Take a closer look by reading section 3 of his blog post, which includes a link to the code.

He had thoughts on adding more features, but having got this much working, he decided to wrap it all up before things headed south. We think there’s more than enough accomplished here for him to be proud of. If you need some introduction to [jwz] as he is known, he’s the guy who worked on emacs, Netscape and Mozilla and has been hacking away since 1985.

Thanks [dr Memals] for sending in this tip.

27 thoughts on “My Payphone Runs Linux

  1. I bet I know why it only worked as “root”.

    To activate a GPIO pin, you write the GPIO number to /sys/class/gpio/export. When you do so, the kernel will create /sys/class/gpio/gpioN as a directory with a bunch of nodes inside. The kernel will create those as root. You can set up udev rules to set ownership and permissions on those nodes, but the problem is that there’s a race condition there. The nodes will be created and exist, and then you have to yield the CPU for long enough to give udev a chance to run and set the permissions properly.

    I ran into this with the linuxgpio support in avrdude.

  2. If I was doing this project I’d do it with Asterisk and a cheap ATA, Leave the phone unmodified and have the ATA set up to dial when it goes off hook.

    Asterisk runs well on the Raspberry Pi.

    1. I dunno, probably easier just to write a script and have a load of audio files on the Pi itself. Saves any more hardware, which is a plus. You also get much more memory than an answering machine, if that’s what an ATA is.

      1. It’s an old phone, just a speaker and mic. A sound card’s a better method I think, rather than something supporting all those advanced telephone features the phone doesn’t have. Buttons in -> sound out. Even the software’s simpler, if he isn’t experienced with Asterisk. Just sound files and a script.

        That said the USB’s a bit unnecessary, reading buttons with GPIOs isn’t exactly complicated. Maybe Jamie’s more a software guy, but he could’ve done it that way. Would’ve been less hassle, and needed less soldering.

  3. I was thinking the same as John. Here is the whole Asterisk stack ready to go for the Pi. You can have the full world of Asterisk and auto-attendants and announcements and and and and at your fingertips. Just get the phone to dial in as an extension. http://nerdvittles.com/?p=14787 (or google “VoIP at Your Fingertips: Incredible PBX GUI for Raspberry Pi 2 with Asterisk 13” if the link doesn’t work.)

    Very cool and fun project though!

    1. So, I’m just curious here – and maybe this totally isn’t a problem, in which case woohoo! Solved. But how well (if at all) can Asterisk handle a Fortress Phone? I’m not sure what the over-the-wire signalling protocol is and what years they were common, but faint memory suggests some were tone controlled (green box?), the last of the COCOTs were ISDN, and there must have been something in the middle.

      It would be cool if the Pi charged a nickle to call it. :-)

      1. Replying to myself… bad form. But yes, upon actually, I don’t know, reading something, it looks like it will work for this generation of AT&T-owned phones. Older ones and COCOTs would have issues. So, Asterisk wins again.

      2. payphone dot com
        Under “support” click “instruction manuals”, everything you need to know.
        The payphone in the image looks to be a standard recent Elcotel or Protel phone (the two models look nearly identical from the front)

        You can also pick up a payphone of your very own, and even a full phone booth for extra overkill points.

  4. Ah, I know who JWZ is. He had his own “about” screen in early versions of Netscape.

    Another thing that Netscape had, was, I think, ctrl-shift-T, which told you what files were currently being downloaded from the server. It was often useful. Don’t suppose there’s an addon or a way to do that in Firefox?

    1. If you hit F12 in Firefox it’ll bring up the ‘Developer Tools’. If you look in the ‘Network’ tab you’ll get a list of all the files the page has requested, what domain’s they’ve come from and how long each took to download etc.

      1. Where were you 10 years ago, when I needed you!? Thanks a lot! That means there’s probably some extension somewhere to make this easier. Or maybe I need to polish my Javascript. Does it work while files are still downloading? I’ll have a look myself.

    2. Actually on a related issue, I used to enjoy reading alt.folklore.computers. All the old-timers all had three-letter names, and I think back then many of them knew each other by them, over the wired / tape / social networks. A very particular sort of honour. Once had dmr himself reply to something I posted, I swooned!

  5. Hmmm, been debating what to do with my payphone in my game room….hooking it up to the phone system worked fine, but people kept using the phone booth as a storage location and more than once I had no way to reach home (DW and Mother would power down cellular phones when home).

    Perhaps this or the Asterisk model for some fun…..will investigate.

    1. Wire it up to the network, but also have a cheap ordinary phone in the living room? And get really angry when people store stuff in your phone booth. Unless those “people” are you…

  6. This reminds me that I was watching TV and they had Adelle’s Hello song on again and I suddenly realized she’s using a classical land-line type of phone all the time instead of a cellphone.
    And nobody made an issue of it AFAIK, whereas normally people in the US mock land-line type phones.

    Mind you, in europe and other western places such phones are most likely using VOIP rather than old analog systems.

    1. Nah, plenty of British people at least have landlines. Even if we don’t want one. The phone networks insist on fitting one when you get broadband. It’s so they can claim the broadband only costs 15 a month, but then charge another 15 for a landline you didn’t want.

      I dunno why anyone would mock one. You can still have a mobile phone as well.

  7. I think the only thing I used my landline for was dialup.
    D-Dial was a thing back in the 80’s, and you can experience one here:
    https://magviz.ca

    I remember redboxing and all the other fun things you could do with payphones.
    Evan Doorbell has recordings of old telephone network sounds.
    Unlike the digital silence of what’s left of today’s POTS network,
    the analag systems had many local flavors of exchange noises.
    I miss the analog days…

Leave a Reply to DielectricCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.