User:Wordfa/oldphonehack: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
<img src="https://pzwiki.wdka.nl/mw-mediadesign/images/a/ab/Oldphonehack.png" style="transform: rotate(90deg); align:center; width:500px;margin:0;padding:0;">
<img src="https://pzwiki.wdka.nl/mw-mediadesign/images/a/ab/Oldphonehack.png" style="transform: rotate(90deg); align:center; width:500px;margin:0;padding:0;">
[[File:Old phonebitmap.png|thumb]]
= Press #1 For: =
= Press #1 For: =



Revision as of 19:17, 12 November 2024

Press #1 For:

Description

From getting your BSN to installing internet in your new home to renting a car, rigid mazes of bureaucratic systems hold us all hostage. In the spirit of collective catharsis 'Press One For' invites you to share and listen to stories of how these systems frustrated you, or how you frustrated them.

T65 Rotary Phone bought by Sevgi n' Fred

Cookbook

Parts Required

USB interface to 3.5mm

https://www.adafruit.com/product/1475

3.5mm Cables

Old phone (T65)

https://www.marktplaats.nl/v/telecommunicatie/vaste-telefoons-niet-draadloos/m2158407457-ptt-t65-goed-werkende-nostalgische-telefoon

Raspberry Pi

TRS 3.5 Jack x2

Loads of wires

old headphones with a mic (apple earpod works best)

Things we done

- We got one phone from ScrapXL Rotterdam and one from Marktplaats. The first one was a T65

[11 (Neg), 12(Pos) speaker output]
We tried batteries for the carbon mic, didn't work

- We took the phone apart and got the speaker to work by connecting the blue and red cables from the phone out to the audio jack to the soundcard to the computer. played show me the body, was good.

- Then we tried the microphone but its a carbon mic and it didnt work. so we atttached a battery and hoped. didnt work.

- We took apart wired headphones that had mic in them to see if we could use the mic from it rather than the carbon mic in the telephone.-> didnt work, headphone cable is TRRS not TRS:

spent a day trying to wire up TRRS to an audio cable, turns out the audio jack was the wrong kind.

then wired it directly to a TRS jack, worked!!!!!!!!!!!!!

then cable managed, looks beautiful now. now we have working speakers and working mic.

This is how you could make it work too (Schema 1)

From the headphones you need to...

Connect th Blue (Ground) to the Sleeve of the TRS jack

Connect the Red (mic) to Pin (Ring) 1 or 2 of the TRS jack

MAKE SURE THE HEADPHONES CONNECTION IS CLOSED!

The wiring used
sketch of the wiring of the handset connection (Schema 1)

Next Steps:

We need to work out how to read the keypad input on the raspberrypi. Mark Powers has a snippet of code that supposedly works with this: https://marks.kitchen/blog/rotary_phone_running_linux/

To test our phone we used this GitHub project: https://github.com/ralphcrutzen/PTT-Tafeltjes-Telefoon?tab=readme-ov-file. > This project turns the phone into a math game where a child asks you a times table question and you are supposed to give the correct answer using the rotary keypad. When you dial the answer the py code reads it as 2 separate entires and gives you a Goed zo! if you gave the correct answer.

Fred is translating the code to eng. He also thinks I can't do times tables.

Set up the raspberrypi, named it telephone.(tut here:https://nematicslab.com/how-to-enable-ssh-without-using-a-monitor/)

Fred made me a user(Sevgi) as well and we tested the connections first, adjusted the code accordingly. Fred tested the connections like this (this is the final working version):

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(25, GPIO.IN, pull_up_down = GPIO.PUD_UP)

while True:
        
        print('-')
        if GPIO.input(23):
                print('23')
        if GPIO.input(25):
                print('25')
        if GPIO.input(24):
                print('24')

Here is how we set up the wires and the raspberry pi:

Wire Sketch rbpi.png

This wiring worked for us at first, but then we had to put the ground cables in different Rbpi GND's for it to work again.

Here is the eng version of the dutch code: https://pzwiki.wdka.nl/mediadesign/User:Wordfa/oldphonehack/PTT_Tafeltjes_Telefoon

We now reverted back to writing the code Ralph Crutzen's way, using pygame. We pulled this code from: https://github.com/pygame/pygame/blob/main/examples/audiocapture.py

""" pygame.examples.audiocapture

A pygame 2 experiment.

* record sound from a microphone
* play back the recorded sound
"""
import pygame as pg
import time
import wave

from pygame._sdl2 import (
    get_audio_device_names,
    AudioDevice,
    AUDIO_F32,
    AUDIO_ALLOW_FORMAT_CHANGE,
)
from pygame._sdl2.mixer import set_post_mix

# sound length (seconds, a float)
SOUNDLEN = 2.0
# sound frequency (in Herz: the number of vibrations per second)
SOUNDFREQ = 1000

# maximal amplitude
MAXAMP = 32767 / 2
# sampling frequency (in Herz: the number of samples per second)
SAMPLINGFREQ = 44100
# the number of channels (1=mono, 2=stereo)
NCHANNELS = 2

pg.mixer.pre_init(44100, 32, 2, 512)
pg.init()

# init_subsystem(INIT_AUDIO)
names = get_audio_device_names(True)
print(names)
sounds = []
sound_chunks = []


def callback(audiodevice, audiomemoryview):
    """This is called in the sound thread.

    Note, that the frequency and such you request may not be what you get.
    """
    # print(type(audiomemoryview), len(audiomemoryview))
    # print(audiodevice)
    sound_chunks.append(bytes(audiomemoryview))


def postmix_callback(postmix, audiomemoryview):
    """This is called in the sound thread.

    At the end of mixing we get this data.
    """
    print(type(audiomemoryview), len(audiomemoryview))
    print(postmix)


set_post_mix(postmix_callback)

audio = AudioDevice(
    devicename=names[0],
    iscapture=True,
    frequency=44100,
    audioformat=AUDIO_F32,
    numchannels=2,
    chunksize=512,
    allowed_changes=AUDIO_ALLOW_FORMAT_CHANGE,
    callback=callback,
)
# start recording.
audio.pause(0)
print(audio)

print(f"recording with '{names[0]}'")
time.sleep(2)


print("Turning data into a pg.mixer.Sound")

sound = pg.mixer.Sound(buffer=b"".join(sound_chunks))
snd = pg.mixer.Sound(sound)

# open new wave file
sfile = wave.open('pure_tone.wav', 'w')

# set the parameters
sfile.setnchannels(NCHANNELS)

# write raw PyGame sound buffer to wave file
sfile.writeframesraw(snd.get_raw())

# close file
sfile.close()

print("playing back recorded sound")
sound.play()
time.sleep(2)
pg.quit()


This didn't really work, just worked for us to record the sound and play it back on the handset.

We gave up on pygame and used pyaudio. Fred found this snippet of code which we will try to translate into our test.py:

import RPi.GPIO as gpio 
from recorder import Recorder 
gpio.setmode(gpio.BCM)  

class ButtonRecorder(object): 
    def __init__(self, filename): 
        self.filename = filename 
        gpio.setup(23, gpio.IN, pull_up_down=gpio.PUD_UP) 
        self.rec = Recorder(channels=2) 

    def start(self): 
        gpio.add_event_detect(23, gpio.FALLING, callback=self.falling, bouncetime=10) 

    def rising(self, channel): 
        gpio.remove_event_detect(23) 
        print 'Button up' 
        gpio.add_event_detect(23, gpio.FALLING, callback=self.falling, bouncetime=10) 
        self.recfile.stop_recording() 
        self.recfile.close() 

    def falling(self, channel): 
        gpio.remove_event_detect(23) 
        print 'Button down' 
        gpio.add_event_detect(23, gpio.RISING, callback=self.rising, bouncetime=10) 
        self.recfile = self.rec.open(self.filename, 'wb')    
        self.recfile.start_recording() 

rec = ButtonRecorder('nonblocking.wav')
rec.start() 

try: 
    raw_input() 

except KeyboardInterrupt: 
    pass 

gpio.cleanup()

We managed to get a recording with this code:




We made a first recording with this. (We were discussing if having a limited time to record is okay instead of hanging the phone to stop recording and its a second of that convo)

We combined these 2 snippets together but had errors, we had to install a bunch of audio related python scripts and Joseph told us to download sox (in his words: Swiss army knife Audio python scripts) :

sudo apt install sox


To do list from 13/11/2024 on:

- discuss the intro in detail : maybe a connecting sound(?) at first, then hold music, then intro, then press 1 for: etc, beep sound before the recording, etc. , before the recording: disclaimer,

- decide whether we have different audios for each pickup

- what is the detailed version of the 'annoying' bureaucratic protocol? make it a detailed question.

- discuss decor after the giveaway shop visit

- collect forms / print forms

- (eventually) make the pi go into the phone and fix the wiring (take everything out, solder the wires, )

File:Output-11.11.2024.mp3

Refs and resources

Microphone from handset

https://www.youtube.com/watch?v=rIkIkbOw3OQ&t

Rotary Pi

Lofi Mic

https://www.youtube.com/watch?v=7gorBkdk8zY

Schematic (v scary)

https://easyeda.com/editor#id=7d0350ec43844219912695cec1a0e156

Rotary MP3 Player

https://www.whizzbizz.com/en/gpo746-t65-rotary-dial-phone-mp3-wav-player

Info on the T65

https://www.cryptomuseum.com/phone/t65/index.htm(there is a wire list here as well)

possible way to wire up carbon microphone

Carbon Mic

https://www.youtube.com/watch?v=cwPPoVvljOw

https://www.youtube.com/watch?v=pb-Lu2kzKYc&t=221s

Dutch guide on rotary dail

https://github.com/ralphcrutzen/PTT-Tafeltjes-Telefoon?tab=readme-ov-file

Guide on getting Keypad Working (Matrix should be tried)

https://web.archive.org/web/20130919160654/http://www.keesvanweert.nl/blog/?p=1

Weird Stuff

how does a carbon mic work

https://wonderfoon.jimdosite.com/

https://www.youtube.com/@ruudshangout/search?query=t65

Event Rider:

Items Needs
  • Table [ ] - from XPUb studio
  • Chair [ ] - WORM
  • Phone [x]
  • Lamp [ ] - Fred has a lamp
  • Calendar [ ]
  • Forms on table? [ ]
  • Assorted Desk Items [ ] - from giveaway shop - bring the cups from studio

Space Needs

  • 2m x 2m (UBIK)
  • Power (UBIK)
  • Low light preferred

Time Needs

  • Async/ All day