Shop OBEX P1 Docs P2 Docs Learn Events
Getting a SP03 to Speak the distance measured by Ping))))) — Parallax Forums

Getting a SP03 to Speak the distance measured by Ping)))))

ndillanendillane Posts: 10
edited 2009-05-22 00:51 in BASIC Stamp
You'll see from a previous post http://forums.parallax.com/forums/default.aspx?f=5&m=337750
that I managed to get the SP03 working using I2C protocol.

I am now trying to get it to speak the distance measured by the Ping))) sensor.

Simple PING Code
DO

PULSOUT 0, 5 '12
PULSIN 0, 1, time '3
DEBUG HOME, "time = ", DEC5 time
time = time ** 1500 '2251
DEBUG CR, "Distance = ", DEC4 time, " cm"
PAUSE 100

' Now need to take the time variable and concatenate "centimeters " to it and then somehow feed it to the SP03 I2COUT Command

' SP03 Code snippet here

GOSUB Wait4Shutup ' Wait until finished speaking
I2COUT SDA, SP03, CmdReg, [noparse][[/noparse] LDBUF, 0, 5, 3, <insert time & Centimeters here> , 0] ' Load Phrase
I2COUT SDA, SP03, CmdReg, [noparse][[/noparse]SPKBUF]
LOOP

Not sure how to store and manipulate text variables using Pbasic

DATA "HELLO" puts load into memory location

Is there a way to assign that to a variable when you read it back (and convert back to Ascii at the same time) ?

Wonder if I can insert a variable name into I2COUT ?

Loads of questions ?????

Anybody got an idea ?

tks
Noel

Comments

  • ZootZoot Posts: 2,227
    edited 2009-03-27 23:29
    You need to convert binary "numbers" to ASCII characters for TTS (text-to-speech).

    Say that "distCm" is the calculated distance in centimeters and txtOut is an array of 3 bytes (3 digits 0-999):

    
    txtOut(2) = distCm/100 + "0"   ' 100s
    txtOut(1) = distCm//100/10 + "0" ' 10s
    txtOut(0) = distCm//10 + "0" ' 1s
    
    
    I2COUT SDA, SP03, CmdReg, [noparse][[/noparse] LDBUF, 0, 5, 3, "distance is ", txtOut(2), txtOut(1), txtOut(0), " centimeters." , 0] ' Load Phrase
    
    
    




    There are more efficient ways, but this should be clear enough, I hope.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • JDJD Posts: 570
    edited 2009-03-27 23:34
    ndillane,

    In regards to inserting a variable in the I2COUT command. The I2COUT command can be used with variables, constants, expressions to format outgoing data.

    Are you trying to get the ASCII value for the text in your DATA statements? If so you can use the DEC formatter. Here is a small example, is this what you are referring to?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • ndillanendillane Posts: 10
    edited 2009-03-29 20:04
    Zoot
    Thank you very much - your approach worked perfectly

    My final snippet of code below

    tks
    Noel


    '
    [noparse][[/noparse]Program Description]
    ' TalkingPing.bs2
    ' You need to convert binary "numbers" to ASCII characters for TTS (text-to-speech).
    ' Say that "distCm" is the calculated distance in centimeters AND txtOut is an array of 3 bytes (3 digits 0-999):

    '
    [noparse][[/noparse]I/O Definitions]
    SDA PIN 8 ' Serial data line - Remember to pull high with 4.7K resistor
    SCL PIN 9 ' Serial clock line - Remember to pull high with 4.7K resistor
    Ping_pin_1 CON 0 'I/O pin that is connected to PING))))

    '
    [noparse][[/noparse]Constants]

    SP03 CON $C4 ' SP03 I2C Address
    CmdReg CON 0 ' SP03 Command register
    VerReg CON 1 ' SP03 Version register - Not used in this program
    LDBUF CON $00 ' NOP command is Load buffer
    SPKBUF CON $40 ' Speak buffer Command
    SPKPRE CON $08 ' Speak Predefined Text $01 to$30 Command - just change the number for what ever phrase you need

    '
    [noparse][[/noparse]Variables]
    time VAR Word
    Stat VAR Byte ' Status byte from SP03
    txtOut VAR Byte(3) ' Make a 3-byte array
    distCm VAR Word

    '
    [noparse][[/noparse]Program Code]
    DO

    PULSOUT 0, 5
    PULSIN 0, 1, time
    DEBUG HOME, "time = ", DEC5 time
    distCm = time ** 1500
    DEBUG CR, "Distance = ", DEC4 distCm, " cm"
    PAUSE 100

    txtOut(2) = distCm/100 + "0" ' 100s
    txtOut(1) = distCm//100/10 + "0" ' 10s
    txtOut(0) = distCm//10 + "0" ' 1s

    GOSUB Wait4Shutup
    I2COUT SDA, SP03, CmdReg, [noparse][[/noparse] LDBUF, 0, 5, 3, "distance is ", txtOut(2), txtOut(1), txtOut(0), " centimeters." , 0] ' Load Phrase
    I2COUT SDA, SP03, CmdReg, [noparse][[/noparse]SPKBUF]

    LOOP

    END
    '
    [noparse][[/noparse]Subroutines]
    Wait4Shutup:
    ' Check to see that SP03 is finished speaking
    I2CIN SDA, SP03, CmdReg, [noparse][[/noparse]Stat]
    IF stat>0 THEN wait4shutup
    RETURN
  • KatyBriKatyBri Posts: 171
    edited 2009-05-04 03:25
    Where is the best place to buy the SP03 module?
  • modemmanmodemman Posts: 41
    edited 2009-05-21 23:57
    KatyBri,

    Not sure about 'best', I got mine from www.junun.org/MarkIII/Store.jsp a few weeks ago, when it was 90 bucks. Now I see it's $105. I tried to get it straight from Devantech, but their website at www.robot-electronics.co.uk/acatalog/Speech_Synthesiser.html states "This product is now obsolete". Their US resellers, at www.acroname.com/robotics/parts/R184-SP03.html also say "this product no longer available". I think I read somewhere that the Winbond WTS701 chip that's the brain of the board is no longer being made. So, hurry and try to find one, looks like they're rare. Also, after reading about how only female voice boards are being produced and available now, mine came with a male voice - I'm quite happy with that, my bot Diddly is a guy.

    Oh, if you can't find one of these, take a look at Parallax's own offering - a very nice board indeed (and cheaper too):

    www.parallax.com/Store/Accessories/Sound/tabid/164/CategoryID/38/List/0/Level/a/ProductID/108/Default.aspx?SortField=ProductName%2cProductName

    Question for the group:

    How does one use special formatters with the SP03. I know that the WTS701 accepts "control" characters, such as "^P" for switching to phonemes, "^U" for pauses between words, etc... There's a thread about it for the Emic board here: http://forums.parallax.com/showthread.php?p=758127, but I couldn't make the SP03 do it. Should work pretty much the same, no?

    Thanks for guidance.

    modemman
  • KatyBriKatyBri Posts: 171
    edited 2009-05-22 00:51
    Thanks for the information, modemman!
Sign In or Register to comment.