PiPhone-Setup

Preliminary notes are kept on this page for now... we'll probably turn this into a more official guide before long.

//**See also:**//

 * Wiki pages
 * our PiPhone software
 * prior Raspberry Pi hacking/experiments.
 * Connecting wirelessly to the Pi
 * public [|project overview] page for the PiPhone project
 * blog post on [|history of the PiPhone kit]

=**//What you will need://**=
 * 1) Our custom circuitry board for the PiPhone by Andrew, and a cable for connecting to Raspberry Pi (the cable might need to be a special one [|like this] if you have a version 2 or B+, since you'll need to downgrade the 40 pin from your Pi to work with the 26 pins on the Piphone board)
 * 2) Raspberry Pi, with monitor+keyboard etc., probably running Raspbian for most uses
 * 3) Payphone with a DB25 connector for the keypad unit (most North American models will work) and cable for connecting to our PiPhone board
 * 4) One stereo audio cable for audio to payphone handset speaker (mono appears not to work for some reason)
 * 5) If recording audio: One stereo audio cable for audio to the payphone microphone (yes, stereo), USB audio card (see description below), and make sure your USB hub has its own power adapter

=**//Diagram for basic wiring://**=

=//Wiring the handset://= =//**Playing Audio:**//=
 * 1) If you have a new handset, or want to plug it in right (or just confirm the wiring for an existing phone): unplug all power, then connect just the piphone board to the payphone. Then plug a stereo audio cable into one of the two jacks on the raspberry pi. Now you're ready to test and figure out where the wiring is going, and make sure it's going to the right place. We used the "conductance buzzer" on a voltmeter, which makes a sound when the connection goes through. Just keep testing until you've identified where the piphone audio jacks end up inside the payphone. For mine, the handset mic wires were black and red with an impedance of 21 k ohm; while the speaker wires were yellow and green with an impedance of 150 ohms. It doesn't matter which of the two piphone jacks is the mic and which is the speaker, but write down whichever one you choose!
 * 1) Connect 1/8" audio input from board to 1/8" audio out from Raspberry Pi using the stereo audio cable.

=//**Recording Audio:**//=
 * This is a little trickier because you'll need extra hardware! If you want to record audio, you'll need to buy a USB **sound card** for the Raspberry Pi... note that these often are reportedly more stable if powered separately from the Raspberry Pi (i.e., get a USB hub that has its own power, and still plugs into the Raspberry Pi). We have successfully used a Syba Audio Adapter ([|SD-CM-UAUD USB]) with a Terminus [|usb hub].
 * Configure the RPI to treat the USB sound card as the default -- as described [|here].
 * The simplest test of audio recording I found was to use "arecord -vv -fdat foo.wav" or see alsa project's page on [|soundcard testing]
 * For python implementation:
 * Beware: It's tempting to use the Jack Audio Connection Kit (jackd / jack server)... but this didn't work for me, and the more I looked around, the more it seemed like this would be pretty hard to do on the RPI. e.g., see [|here].
 * Instead, I just kept using **//arecord//**.
 * To get started, I stole code from this RPI page on karaoke and related [|design challenges]... basically piping the arecord commands though //os.system// (e.g., "//os.system('arecord -D plughw:1 -r 16000 test.wav &')// ")
 * ...and good news: this works with our current payphone key system, i.e., you can press a key to start recording, and if you press another key it can interrupt recording -- leaving behind the WAV file you want!
 * //__Still to investigate__//:
 * smaller file sizes with mono and lower sampling (i.e., parameters for arecord);
 * stopping recording more smoothly -- perhaps sufficient to use //os.system('killall arecord')//

=//Triggering Code with Button Presses://=
 * 1) TBD [thinking link here to github, give basic examples of how to use libraries - ARS 5/19/15]

=//**Strange tips:**//=
 * mono audio plugs might not work with the PiPhone board //[more specifically the male mono plugs, which seem logical for the PiPhone board since the wiring is for mono audio but in fact reportedly do not always work with our female jacks for some reason... so beware! (per Benjamin, May2015)]//

Misc debugging notes
These may help others learn to diagnose things too... :)
 * keypad misread diagnosis. (2016-06)
 * 3 is being misread as 1, 6 as 4 9 as 7.
 * according to the binary in our PY file, that means: 3=0100 while 1=0000 (not detecting second digit); 6=0110 while 4=0010 (not detecting second digit); and 9=0101 while 7=0001 (not detecting second digit)...
 * hurrah a pattern: the second digit is not being read. that's GPIO #23. For the Raspberry Pi+, that = pin 16. ground is pin 39. see [|diagram].
 * so we should NOT detect 16-to-39 when pushing these buttons... but for instance, we should detect on the 4 key that the third number (GPIO24=pin18) does work.
 * ...but i can't figure out how to test this.... YET
 * precursor: see if new keypad works... should be easier to test. if not, get right cables!