×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Python IR remote control!

    After days of testing I eventually got some results: I successfully used my nokia 6680 to remote control my Sat decoder!
    The interesting thing is tht 6680 does NOT have IRDA port!

    It was "just" a matter of connecting an IR LED to the headset port, and playing a proper wav file.

    Now I'd like to write a program which plays proper file depending on key pressed.
    I wrote this one:

    Code:
    import keycapture
    from appuifw import *
    from e32 import *
    import appswitch
    import audio
    
    file1 = u"c:\\nokia\\sounds\\1.wav"
    file2 = u"c:\\nokia\\sounds\\2.wav"
    file3 = u"c:\\nokia\\sounds\\3.wav"
    
    def quit():
        app.exit_key_handler = None
        script_lock.signal()
        capturer.stop()
        print "TERMINATO."
        print
    
    def cb_capture(key):
        if key==keycapture.EKeyYes:
            appswitch.switch_to_fg(u"Python")
            note(u'Capture yes key !',u'info',1)
        if key==keycapture.EKeyNo:
            note(u'Capture no key!',u'info',1)
            appswitch.switch_to_fg(u"Python")
        if key==keycapture.EKey1:
            print "UNO"
            sound = audio.Sound.open(u"c:\\nokia\\sounds\\1.wav")
            sound.play()
        if key==keycapture.EKey2:
            print "DUE"
            sound = audio.Sound.open(u"c:\\nokia\\sounds\\2.wav")
            sound.play()
        if key==keycapture.EKey3:
            print "TRE:" + file3
            sound = audio.Sound.open(u"c:\\nokia\\sounds\\3.wav")
            sound.play()
    
    
    script_lock = Ao_lock()
    app.exit_key_handler = quit
    capturer=keycapture.KeyCapturer(cb_capture)
    capturer.forwarding=0
    capturer.keys=(keycapture.EKeyYes,keycapture.EKeyNo,keycapture.EKeySelect,keycapture.EKeyEdit,keycapture.EKey1,keycapture.EKey2,keycapture.EKey3)
    capturer.start()
    script_lock.wait()
    It properly detects keys... but it does not play anything!
    The weird thing is that python itself CAN play those files; at least, I can play them on the phone if I send sound.play() command from PC bluetooth console.

    So why is it not working directly on phone?!?

    Here you find more details about how to use a PC (not a phone, a new article is coming) to sample and replay a remote control just by using a couple of TRANSMITTING infrared diods:

    http://jumpjack.wordpress.com/2008/0...icator-just-1/

    You find attached the schematic I used to replay the sound through the headset port.
    Note that actually only ONE led is enough to have this thing working!

    You also find attached the WAV file I used.
    Attached Images Attached Images

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    the wav file
    Attached Files Attached Files

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: Python IR remote control!

    Hi cassioli,

    Excellent Stuff!

    Try replacing the respective code lines with below,

    Code:
    sound = audio.sound.open("c:\\nokia\\sounds\\1.wav")
    sound = audio.sound.open("c:\\nokia\\sounds\\2.wav")
    sound = audio.sound.open("c:\\nokia\\sounds\\3.wav")
    Could you tell me, where did you get the PIN OUT diagram from?

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Quote Originally Posted by croozeus View Post
    Hi cassioli,

    Excellent Stuff!

    Try replacing the respective code lines with below,

    Code:
    sound = audio.sound.open("c:\\nokia\\sounds\\1.wav")
    sound = audio.sound.open("c:\\nokia\\sounds\\2.wav")
    sound = audio.sound.open("c:\\nokia\\sounds\\3.wav")
    Could you tell me, where did you get the PIN OUT diagram from?

    Best Regards,
    Croozeus
    even replacing "sound" with "Sound" as required, it does not work :-(

    The weird thing is that this simple program works fine, instead:
    Code:
    from e32 import *
    import audio
    
    file1 = u"c:\\nokia\\sounds\\1.wav"
    file2 = u"c:\\nokia\\sounds\\2.wav"
    
    print "UNO"
    sound = audio.Sound.open(u"c:\\nokia\\sounds\\1.wav")
    sound.play()
    But it does not work if I play further files, due to "play status error n.2": I guess it's a "busy error message", but how to prevent it? I tried with ao_sleep and time.sleep with no success.


    For pinouts... just look at pinouts.ru!

    http://pinouts.ru/CellularPhones-Nok...p_pinout.shtml

  5. #5
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: Python IR remote control!

    Quote Originally Posted by cassioli View Post
    even replacing "sound" with "Sound" as required, it does not work :-(
    I had also removed the unicode from those statements

    sound = audio.Sound.open(u"c:\\nokia\\sounds\\3.wav")

    Quote Originally Posted by cassioli View Post
    But it does not work if I play further files, due to "play status error n.2": I guess it's a "busy error message", but how to prevent it? I tried with ao_sleep and time.sleep with no success.
    Could you try this:

    Code:
    sound1= audio.sound.open("c:\\nokia\\sounds\\1.wav")
    sound1.play()
    
    sound2 = audio.sound.open("c:\\nokia\\sounds\\2.wav")
    sound2.play()
    
    sound3 = audio.sound.open("c:\\nokia\\sounds\\3.wav")
    sound3.play()
    Busy status is because you have not stopped playing. So I guess using other variable as above may work for you.

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Quote Originally Posted by croozeus View Post
    I had also removed the unicode from those statements

    sound = audio.Sound.open(u"c:\\nokia\\sounds\\3.wav")
    Yes, I noticed that, but it didn't change anything (indeed no error was raised neither before nor now).
    I guess it's a matter of "thread conflict", as sound playing and key detection are contemporary tasks.



    Could you try this:

    Code:
    sound1= audio.sound.open("c:\\nokia\\sounds\\1.wav")
    sound1.play()
    
    sound2 = audio.sound.open("c:\\nokia\\sounds\\2.wav")
    sound2.play()
    
    sound3 = audio.sound.open("c:\\nokia\\sounds\\3.wav")
    sound3.play()
    Busy status is because you have not stopped playing. So I guess using other variable as above may work for you.

    Best Regards,
    Croozeus
    Thanks, I solved this way:

    Code:
    import audio
    import appuifw
    import time
    
    data = appuifw.query(u"Canale?", "text")
    file_to_play=u"c:\\nokia\\sounds\\"+data+".wav"
    print file_to_play
    sound = audio.Sound.open(file_to_play)
    sound.play()
    time.sleep(1)
    sound.stop()
    print "fatto1"
    sound.play()
    time.sleep(1)
    sound.stop()
    print "fatto2"
    sound.play()
    time.sleep(1)
    sound.stop()
    print "fatto 3."
    The audio file is very short, so I waited just a few ms before stopping, and this resulted (again) in "play overlapping".
    I see my sat decoder tolerates up to 1 sec interval between keypresses, so this works fine.

    ...but being able to just press three number-keys rather than menuOPTIONS->INPUT CHANNEL->123 would be much better, of course...

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Ok, I need some help (again )
    I found this freeware program which apparently allows synthesizing any kind of sound in any file format... but I'm quite confused by the documentation, due to my poor english I guess...

    I'd like to generate, for example, a WAV file made up just of tones and silences this way (durations are in microseconds):
    2800 tone
    888 silence
    444 tone
    444 silence
    444 tone
    444 silence

    How do I accomplish this using SOX? I don't even know if it is possible to have us precision...

    On site documentation is quite poor, you have to look at the program package.
    I paste here what I think is the relevant part of the documentation from soxeffect.txt (but I maybe wrong):

    synth [len] {[type] [combine] [freq[-freq2]] [off] [ph] [p1] [p2] [p3]}
    This effect can be used to generate fixed or linearly swept fre-
    quency audio tones with various wave shapes, or to generate
    wide-band noise of various ‘colours’. Multiple synth effects
    can be cascaded to produce more complex waveforms; at each stage
    it is possible to choose whether the generated waveform will be
    mixed with, or modulated onto the output from the previous
    stage. Audio for each channel in a multi-channel audio file can
    be synthesised independently.

    Though this effect is used to generate audio, an input file must
    still be given, the characteristics of which will be used to set
    the synthesised audio length, the number of channels, and the
    sampling rate; however, since the input file’s audio is not nor-
    mally needed, a ‘null file’ (with the special name -n) is often
    given instead (and the length specified as a parameter to synth
    or by another given effect that can has an associated length).

    For example, the following produces a 3 second, 44.1 kHz, audio
    file containing a sine-wave swept linearly from 300 to 3300 Hz:

    sox -n output.au synth 3 sine 300-3300

    and this produces an 8 kHz version:

    sox -r 8000 -n output.au synth 3 sine 300-3300
    The following example shows how two synth effects can be cas-
    caded to create a more complex waveform:

    sox -n output.au synth 0.5 sine 200-500 \
    synth 0.5 sine fmod 700-100
    A detailed description of each synth parameter follows:

    len is the length of audio to synthesise expressed as a time or
    as a number of samples; 0=inputlength, default=0.

    The format for specifying lengths in time is hh:mm:ss.frac. The
    format for specifying sample counts is the number of samples
    with the letter ‘s’ appended to it.

    type is one of sine, square, triangle, sawtooth, trapezium, exp,
    [white]noise, pinknoise, brownnoise; default=sine

    combine is one of create, mix, amod (amplitude modulation), fmod
    (frequency modulation); default=create

    freq/freq2 are the frequencies at the beginning/end of synthesis
    in Hz or, if preceded with ‘%’, semitones relative to A
    (440 Hz); for both, default=%0. If freq2 is given, then len
    must also have been given. Not used for noise.

    off is the bias (DC-offset) of the signal in percent; default=0.

    ph is the phase shift in percentage of 1 cycle; default=0. Not
    used for noise.

    p1 is the percentage of each cycle that is ‘on’ (square), or
    ‘rising’ (triangle, exp, trapezium); default=50 (square,
    triangle, exp), default=10 (trapezium).

    p2 (trapezium): the percentage through each cycle at which
    ‘falling’ begins; default=50. exp: the amplitude in percent;
    default=100.

    p3 (trapezium): the percentage through each cycle at which
    ‘falling’ ends; default=60.

    tempo [-q] factor [segment [search [overlap]]]
    Change the audio tempo (but not its pitch) using a ‘WSOLA’ algo-
    rithm. The audio is chopped up into segments which are then
    shifted in the time domain and overlapped (cross-faded) at
    points where their waveforms are most similar (as determined by
    measurement of ‘least squares’).

    By default, linear searches are used to find the best overlap-
    ping points; if the optional -q parameter is given, tree
    searches are used instead, giving a quicker, but possibly lower
    quality, result.

    factor gives the ratio of new tempo to the old tempo.

    The optional segment parameter selects the algorithm’s segment
    size in milliseconds. The default value is 82 and is typically
    suited to making small changes to the tempo of music; for larger
    changes (e.g. a factor of 2), 50 ms may give a better result.
    When changing the tempo of speech, a segment size of around
    30 ms often works well.

    The optional search parameter gives the audio length in mil-
    liseconds (default 14) over which the algorithm will search for
    overlapping points. Larger values use more processing time and
    do not necessarily produce better results.

    The optional overlap parameter gives the segment overlap length
    in milliseconds (default 12).

    See also stretch for a similar effect.

    treble gain [frequency [width[s|h|o|q]]]
    Apply a treble tone-control effect. See the description of the
    bass effect for details.

    tremolo speed [depth]
    Apply a tremolo (low frequency amplitude modulation) effect to
    the audio. The tremolo frequency in Hz is given by speed, and
    the depth as a percentage by depth (default 40).

    Note: This effect is a special case of the synth effect.

    trim start [length]
    Trim can trim off unwanted audio from the beginning and end of
    the audio. Audio is not sent to the output stream until the
    start location is reached.

    The optional length parameter tells the number of samples to
    output after the start sample and is used to trim off the back
    side of the audio. Using a value of 0 for the start parameter
    will allow trimming off the back side only.

    Both options can be specified using either an amount of time or
    an exact count of samples. The format for specifying lengths in
    time is hh:mm:ss.frac. A start value of 1:30.5 will not start
    until 1 minute, thirty and ½ seconds into the audio. The format
    for specifying sample counts is the number of samples with the
    letter ‘s’ appended to it. A value of 8000s will wait until
    8000 samples are read before starting to process audio.

    vol gain [type [limitergain]]
    Apply an amplification or an attenuation to the audio signal.
    Unlike the -v option (which is used for balancing multiple input
    files as they enter the SoX effects processing chain), vol is an
    effect like any other so can be applied anywhere, and several
    times if necessary, during the processing chain.

    The amount to change the volume is given by gain which is inter-
    preted, according to the given type, as follows: if type is
    amplitude (or is omitted), then gain is an amplitude (i.e. volt-
    age or linear) ratio, if power, then a power (i.e. wattage or
    voltage-squared) ratio, and if dB, then a power change in dB.

    When type is amplitude or power, a gain of 1 leaves the volume
    unchanged, less than 1 decreases it, and greater than 1
    increases it; a negative gain inverts the audio signal in addi-
    tion to adjusting its volume.

    When type is dB, a gain of 0 leaves the volume unchanged, less
    than 0 decreases it, and greater than 0 increases it.

    See [4] for a detailed discussion on electrical (and hence audio
    signal) voltage and power ratios.

    Beware of Clipping when the increasing the volume.

    The gain and the type parameters can be concatenated if desired,
    e.g. vol 10dB.

    An optional limitergain value can be specified and should be a
    value much less than 1 (e.g. 0.05 or 0.02) and is used only on
    peaks to prevent clipping. Not specifying this parameter will
    cause no limiter to be used. In verbose mode, this effect will
    display the percentage of the audio that needed to be limited.

    See also compand for a dynamic-range compression/expansion/lim-
    iting effect.

  8. #8
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Talking Re: Python IR remote control!

    Quote Originally Posted by cassioli View Post

    How do I accomplish this using SOX? I don't even know if it is possible to have us precision...
    Do you want to accomplish this with PyS60 or something with Python??

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  9. #9
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Quote Originally Posted by croozeus View Post
    Do you want to accomplish this with PyS60 or something with Python??

    Best Regards,
    Croozeus
    I was trying to use SOX to create proper WAV files to be used by my python script.

    I think I obtained something: by combining SOX (to create wave files) and SHNTOOL(to concatenate them) I was eventually able to create the needed WAV file in an easier way than manually silencing a 36000 KHz tone.
    But I think there should be an easier way, using just SOX rather than two separate programs: I see that commands in SOX can be concatenated... but I can't figure out how; I also read around that SOX can also be used to concatenate ready-made WAV files... but again I can't figure out how.

    And I also found this pys60 source:
    http://snippets.dzone.com/posts/show/1656

    Of course it's causing some troubles to get it to work, but I guess it could be used to directly create the needed WAV files on the phone rather than storing them in phone memory (and this would be cool, having some old phones very few free memory available!).

  10. #10
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    I have another problem: I really need my WAV file to be reproduced upon keypress, but it looks like it is impossibile:
    as soon as I press a key, I hear its tone; but once it finishes playing, if I keep the speaker really close to my ear I hear a very low "remaining" beep, which continues for several seconds; only once it finishes I eventually hear MY wav file played!

    So I tried editing my profile not to use keyboard tones.
    Same result: I do not hear main tone, but the low, "background" tone is still present and it prevents my wav file from being played!

    Is this a known bug?
    How can I avoid it?

    I'm using python 1.4.1 on a nokia 6680 v 5.04.07 (15-02-06, RM-36)

  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Re: Python IR remote control!

    Can someone tell me how that 10 ohms resistor looks like? (I'm referring to the colored stripes)...p.s. can i use Flash to create a simple application that plays the necessary wav sounds?...thanks in advance
    Last edited by hellhound2; 2009-01-14 at 10:39.

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Quote Originally Posted by hellhound2 View Post
    Can someone tell me how that 10 ohms resistor looks like? (I'm refering to the colored stripes)...p.s. can i use Flash to create a simple application that plays the necessery wav sounds?...thanks in advance
    brown, black, black; silver/gold on the right.
    http://www.dannyg.com/examples/res2/resistor.htm

  13. #13
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Re: Python IR remote control!

    well...I went to the electronic components store and asked the guy for an 10ohms resistor and he gave me two resistors and told me to tie them in parallel....i don't know from which end to start but...they're stripped something like this or the other way around: red,brown,gold,gray/nothing(it's hard to tell)and red

  14. #14
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: Python IR remote control!

    Quote Originally Posted by hellhound2 View Post
    well...I went to the electronic components store and asked the guy for an 10ohms resistor and he gave me two resistors and told me to tie them in parallel....i don't know from which end to start but...they're stripped something like this or the other way around: red,brown,gold,gray/nothing(it's hard to tell)and red
    as he had no 10 Ohm resistor, he should have given to you two 20 Ohm resistor, which connected in parallel give 10 Ohm resistance. But red/brown/gold does not appear to be 20 Ohm! It should be Red/Black/Black (gold/silver strip is always on the right).
    I also never heard about a gold/silver color for 3rd strip, only for last one.

    But looking at this page, I guess he gave you a "high precision" resistor, which is NOT needed at all! You just need a cheap 1/2 watt resistence, 10% tolerance, like one of these (the bigger it is, the more power it can tolerate):
    http://www.byexamples.com/ee/images/resistor.jpg

    Could you post a picture of the resistor?

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Re: Python IR remote control!

    I couldn't get a good picture so...I hope that these will do...
    http://www.fileden.com/files/2008/2/21/1772390/re1.bmp
    And this is how the guy from the store told me to put them...
    http://www.fileden.com/files/2008/2/.../resistors.bmp

Similar Threads

  1. pys60, irda and remote control
    By cassioli in forum Symbian
    Replies: 5
    Last Post: 2008-06-10, 14:19
  2. Replies: 2
    Last Post: 2008-04-18, 00:19
  3. Replies: 2
    Last Post: 2008-02-16, 16:47
  4. Phone as Universal Remote Control
    By ticktock in forum Symbian
    Replies: 7
    Last Post: 2007-01-16, 14:14
  5. Using a nokia phone as a remote control
    By mholmes in forum Mobile Java General
    Replies: 1
    Last Post: 2003-02-18, 11:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×