User:Birgit bachler/BBB: Difference between revisions

From XPUB & Lens-Based wiki
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:TheInternetIsCalling.png]]
[[File:TheInternetIsCalling.png]]
[[File:internetphone.jpg]]
[[File:internetphone.jpg]]<br />
For this thematic project I will make use of the telephone as a dying medium for networking, <br />
For this thematic project I will make use of the telephone as a dying medium for networking, <br />
and belhuizen are some last public resorts for these machines.<br />
and belhuizen are some last public resorts for these machines.<br />
Line 105: Line 105:


<source lang ="python">
<source lang ="python">
# 7th december 2010
# A telephone state machine with pygame
# state 1: WAIT, state 2: RING, state 3: PLAY, state 4: OVER, state5: RING2(on/on/off)
# simulate a hook with your hand on the space-key
# 3 testing sound files: ringringring.ogg for ring, offthehook.ogg for "besetzt", test.ogg for speech
# phone rings after random time (here, 15-90 seconds), gives up after 10 seconds
# important: serial crashes, timeout now 5, maybe size=1, timeout=None to test
#!/usr/bin/python


import sys, pygame, time, random, os
import sys, pygame, time, random, os
Line 115: Line 124:
device = glob.glob("/dev/ttyUSB*")[0]
device = glob.glob("/dev/ttyUSB*")[0]
time.sleep(1)
time.sleep(1)
arduino = serial.Serial(device, 115200, timeout=1)
arduino = serial.Serial(device, 115200, timeout=5)




Line 132: Line 141:


offthehook = pygame.mixer.Sound("offthehook.ogg")
offthehook = pygame.mixer.Sound("offthehook.ogg")
#ringringring = pygame.mixer.Sound("ringringring.ogg")


WAIT=1
WAIT=1
Line 141: Line 149:




rtime = random.randint(3,5)
rtime = random.randint(15,90)
state = WAIT
state = WAIT
pickup = False
pickup = False
Line 147: Line 155:
ringing = False
ringing = False
shringing = False
shringing = False


def getPickup():
def getPickup():
   arduino.write('r')
   arduino.write('r')
   resp=arduino.readline().strip()
   resp=arduino.readline().strip()
  print resp
   return resp == 'G'
   return resp == 'G'


#  return not pygame.key.get_pressed()[pygame.K_SPACE]
#  return not pygame.key.get_pressed()[pygame.K_SPACE]
#  return line
#  return line
def newMessage():
  messagelist = glob.glob("messages/*.ogg")
  rmes = random.randint(0, len(messagelist)-1)
  return messagelist[rmes]
themessage = newMessage()


while True:
while True:
Line 180: Line 198:
       arduino.write('k')
       arduino.write('k')
       pygame.mixer.stop()   
       pygame.mixer.stop()   
       message = pygame.mixer.Sound("out.ogg")
       message = pygame.mixer.Sound(themessage)
      time.sleep(1)
       message.play()
       message.play()
      themessage = newMessage()
     if state == PLAY and not pickup:
     if state == PLAY and not pickup:
       state = WAIT
       state = WAIT
Line 189: Line 209:
     state = OVER
     state = OVER
     statetime = time.time()
     statetime = time.time()
    time.sleep(1)
     offthehook.play(loops=-1)
     offthehook.play(loops=-1)


Line 196: Line 217:


   if state == WAIT and timeinstate >= rtime:
   if state == WAIT and timeinstate >= rtime:
     rtime = random.randint(3,5)
     rtime = random.randint(15,90)
     state = RING
     state = RING
     statetime = time.time()
     statetime = time.time()
     pygame.mixer.stop()
     pygame.mixer.stop()
    #ringringring.play(loops=-1)
     arduino.write('K')
     arduino.write('K')
     ringing = True
     ringing = True


   if state == RING:
   elif state == RING:
     # moduloring
     # moduloring
     shringing = int(timeinstate)%3 != 2
     shringing = int(timeinstate)%3 != 2
Line 214: Line 234:
       ringing = shringing
       ringing = shringing


  if state == RING and timeinstate >= 10:
    if timeinstate >= 10:
    state = WAIT
      state = WAIT
    statetime = time.time()
      statetime = time.time()
    arduino.write('k')
      arduino.write('k')
    pygame.mixer.stop()
      pygame.mixer.stop()
    
    


Line 224: Line 244:
   clock.tick(30)
   clock.tick(30)
</source>
</source>
== code dump bash ==
<source lang="bash">
#!/bin/bash
for x in $(ls)
do
cat $x | text2wave -f 44100 -o $x.ogg
done
</source>
[[User:Birgit_bachler/BBB/rescue | all scripts after my computer died go here]]

Latest revision as of 15:41, 17 December 2010

TheInternetIsCalling.png Internetphone.jpg
For this thematic project I will make use of the telephone as a dying medium for networking,
and belhuizen are some last public resorts for these machines.
We are very much used to actively using the Internet by visiting websites rather than them visiting us.
Now the Internet is calling you, in the belhuis.
Scraping all this information you want or do not want to find
(sources yahoo answers, craigslist, facebook, brandmonitor etc etc)
and letting this information find you.

Example1: "Ring ring"... "Its a shame you don't know what your worth! You've let pathetic guys ruin you! \nYour better than that! \nIs your BEAUTY, your curse!?"
Example2: "Ring ring".... "Just to be clear, I'm not really looking for a bodyguard (that's a lyric from the song haha!) just a friend named Betty."

Howto

  • Data-scraping: python with feedparser etc (facebook, craigslist...)
  • Mastercontrolprogram.py (state-machine) + PySerial + Arduino >> Phone
  • Text-to-Speech: festival, text2wave on commandline with the "American female"
  • Phone: Mod-copper-phone with 2 inputs (1 audio, 1 ring) and 1 output (fork)

Pcha.jpg

* http://www.troglodisme.com/?p=42
* http://brohogan.blogspot.com/2009/12/telephone-interface.html


code dump arduino

#include <avr/io.h>
#include <avr/interrupt.h>

#define gabelPin 4
#define klingelEn 7
#define klingelA 5
#define klingelB 6
#define klingelPeriod 2500 //1250

void setup(void){
  pinMode(gabelPin, INPUT);
  digitalWrite(gabelPin, HIGH);
  pinMode(klingelEn, OUTPUT);
  pinMode(klingelA, OUTPUT);
  pinMode(klingelB, OUTPUT);
  sei();

  TCCR1B = (_BV(CS12)); //timer at Fcpu/256  
  Serial.begin(115200);

}

void scheduleTimerInterrupt(void){
  OCR1A = (unsigned int)TCNT1 + (unsigned int)klingelPeriod; 
}

void startKlingel(void){
  scheduleTimerInterrupt();
  TIFR1 |= _BV(OCF1A); 
  TIMSK1 |= _BV(OCIE1A); 
  digitalWrite(klingelEn, HIGH);
  digitalWrite(klingelA, HIGH);
  digitalWrite(klingelB, LOW);
}

void stopKlingel(void){
  TIMSK1 &= ~_BV(OCIE1A); 
  digitalWrite(klingelEn, LOW);
}

ISR(TIMER1_COMPA_vect){
  PORTD ^= (_BV(5) | _BV(6));
  scheduleTimerInterrupt();
}

int gabel = 0;

void loop(void){
  int g;
  if (Serial.available()){
    switch (Serial.read()){
    case 75: //K
      startKlingel();
      break;
    case 107: //k
      stopKlingel();
      break;
    case 114:  //r
      g = digitalRead(gabelPin);
      if(g){
        Serial.write("g\n");
      }
      else {
        Serial.write("G\n");
      }
      break;
    }
  }
}

code dump python

# 7th december 2010
# A telephone state machine with pygame
# state 1: WAIT, state 2: RING, state 3: PLAY, state 4: OVER, state5: RING2(on/on/off)
# simulate a hook with your hand on the space-key
# 3 testing sound files: ringringring.ogg for ring, offthehook.ogg for "besetzt", test.ogg for speech
# phone rings after random time (here, 15-90 seconds), gives up after 10 seconds
# important: serial crashes, timeout now 5, maybe size=1, timeout=None to test

#!/usr/bin/python

import sys, pygame, time, random, os
import serial

import glob


  
device = glob.glob("/dev/ttyUSB*")[0]
time.sleep(1)
arduino = serial.Serial(device, 115200, timeout=5)


time.sleep(2)

pygame.mixer.init(frequency = 44100)
pygame.init()



width, height = (640, 480)
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()



offthehook = pygame.mixer.Sound("offthehook.ogg")

WAIT=1
RING=2
RING2=5
PLAY=3
OVER=4


rtime = random.randint(15,90)
state = WAIT
pickup = False
statetime = time.time()
ringing = False
shringing = False


def getPickup():
  arduino.write('r')
  resp=arduino.readline().strip()
  print resp
  return resp == 'G'


#  return not pygame.key.get_pressed()[pygame.K_SPACE]
#  return line

def newMessage():
  messagelist = glob.glob("messages/*.ogg")
  rmes = random.randint(0, len(messagelist)-1)
  return messagelist[rmes]

themessage = newMessage()

while True:
  for event in pygame.event.get():
    if event.type == pygame.QUIT or \
      (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
        sys.exit()

  pygame.draw.rect(screen, (0, 0, 0), (0,0,width,height), 0)
  p = getPickup()
  if p != pickup:
    pickup = p
    # pickup event
    if state == WAIT and pickup:
      state = OVER
      statetime = time.time()
      offthehook.play(loops=-1)
    if state == OVER and not pickup:
      state = WAIT
      statetime = time.time()
      pygame.mixer.stop()
    if state == RING and pickup:
      state = PLAY
      statetime = time.time()
      arduino.write('k')
      pygame.mixer.stop()  
      message = pygame.mixer.Sound(themessage)
      time.sleep(1)
      message.play()
      themessage = newMessage()
    if state == PLAY and not pickup:
      state = WAIT
      statetime = time.time()
      pygame.mixer.stop() 
  if state == PLAY and not pygame.mixer.get_busy():
    state = OVER
    statetime = time.time()
    time.sleep(1)
    offthehook.play(loops=-1)

  timeinstate = time.time() - statetime

  print state, timeinstate

  if state == WAIT and timeinstate >= rtime:
    rtime = random.randint(15,90)
    state = RING
    statetime = time.time()
    pygame.mixer.stop()
    arduino.write('K')
    ringing = True

  elif state == RING:
    # moduloring
    shringing = int(timeinstate)%3 != 2
    if ringing != shringing:
      if shringing:
        arduino.write('K')
      else:
        arduino.write('k')
      ringing = shringing

    if timeinstate >= 10:
      state = WAIT
      statetime = time.time()
      arduino.write('k')
      pygame.mixer.stop()
  

  pygame.display.flip()
  clock.tick(30)

code dump bash

#!/bin/bash
for x in $(ls)
do
cat $x | text2wave -f 44100 -o $x.ogg
done

all scripts after my computer died go here