Shop OBEX P1 Docs P2 Docs Learn Events
Motorola c168i Cell Phone and Propeller — Parallax Forums

Motorola c168i Cell Phone and Propeller

Jay KickliterJay Kickliter Posts: 446
edited 2010-12-31 10:24 in Propeller 1
I've been trying to get the propeller to interface with a Motorola c168i phone, but just can't get it to work. Using an Arduino, and this code, I can get it to send text messages. Here's my Spin code, does anyone see any glaring problems? I'd really like this to work so I can use it as a backup telemetry transmitter for my balloon project.



[b]CON[/b]
  [b]_CLKMODE[/b]                  = [b]xtal[/b]1 + [b]pll[/b]4x
  [b]_XINFREQ[/b]                  = 5_000_000
  PHONE_TX_PROP_RCV_PIN     = 14                                  ' Connect to ring on 2.5 mm phone connector         
  PHONE_RCV_PROP_TX_PIN     = 15                                  ' Connect to tip on 2.5 mm phone connector
  DELAY                     = 0.5
  CONTROL_Z                 = 26
  QUOTATION_MARK            = 34
  PLUS_SYMBOL               = 43 
 
[b]OBJ[/b]
  serial : "Simple_Serial"

[b]VAR[/b]
  [b]long[/b] stack[noparse][[/noparse]10]

[b]DAT[/b]
  phone_set_text_mode_command   [b]byte[/b]  "AT+CMGF=1", 0    ' Puts the phone in text mode
  phone_send_sms_command        [b]byte[/b]  "AT+CMGS=", 0     ' First part of command, the rest is phone number in quotes
  phone_shutdown_command        [b]byte[/b]  "AT+CFUN=0", 0    ' Turn off transmitter or phone, not quite sure
  phone_reset_command           [b]byte[/b]  "AT*SWRESET", 0   ' Resets phone and/or turns the transmitter back on
  at_command                    [b]byte[/b]  "AT", 0           ' Phone should return "OK"
  att_internet_gateway          [b]byte[/b]  "121", 0          ' The phone number to send emails through
  cr_nl                         [b]byte[/b]  13, 10, 0         ' Carrige return + newline
  phone_number                  [b]byte[/b]  "17576306194", 0
  message                       [b]byte[/b]  "[b]Test[/b] [b]Test[/b] 1 2 1 2", 0
  
[b]PUB[/b] Main
  Init
  SendSMS(@phone_number, @message)

[b]PUB[/b] Init
  serial.init(PHONE_TX_PROP_RCV_PIN, PHONE_RCV_PROP_TX_PIN, 4800)       ' Init simple_serial object
  serial.[b]str[/b](@at_command)                               ' Send an AT so phone knows what baud rate we're operating at
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return, newline control characters
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Wait for phone to process command
  serial.[b]str[/b](@at_command)                               ' Send an AT again so phone knows what baud rate we're operating at
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return, newline control characters
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Wait for phone to process command

[b]PUB[/b] SendSMS(recipient_phone_number, message_text)
  serial.[b]str[/b](@phone_set_text_mode_command)              ' Make sure phone is in text mode, not PDU mode
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return and newline
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Pause for phone to process command 
  serial.[b]str[/b](@phone_send_sms_command)                   ' Send sms preamble, AT+CMGS=
  serial.tx(QUOTATION_MARK)                             ' Send a "
  serial.tx(PLUS_SYMBOL)                                ' Send a +
  serial.[b]str[/b](recipient_phone_number)                    ' Send phone number string, eg. 15551236789
  serial.tx(QUOTATION_MARK)                             ' Send a "
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return and newline control characters
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Wait for phone to process command
  serial.[b]str[/b](message_text)                              ' Send message string
  serial.tx(CONTROL_Z)                                  ' Send Control-Z character
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return and newline control characters
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Make sure phone has enough time to process command before next
  serial.[b]str[/b](@at_command)                               ' Send another AT for good measure
  serial.[b]str[/b](@cr_nl)                                    ' Send carrige return, and newline control characters
  [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                              ' Wait for phone to process command               




[url=http://][/url][url=http://][/url]

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-22 22:09
    I would add a "repeat" after the call SendSMS, this will stop the cog shutting down. In case there are anytime timing issues.
    The other question I have is hardware related, do you have a pull-up on the tx pin, and is the c168i 5V (inline resistor). Its not obvious from the phone library code what the pinmode sets pull-ups to, etc. simple-serial floats the tx line at the end of every char, which probably goes low, the c168i probably sees that as a start bit which may confuse it.
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-22 22:30
    Tim, that's a good suggestion. I haven't tried using any sort of resistor. What is the difference between pull-up and inline, I thought they were the same? Also, what do you mean by "floats the tx line? As far as voltage, I don't know. I don't have an oscilloscope handy. And I've yet to find any publications from Motorola that mention the serial port. It works with the Arduino, and it is 5V, that may say something.

    Thanks for the advice. If I can get this to work predictably it could be of use to a number of propeller projects. The c168i only costs $15 and you can use pre-paid cards. The OpenGPS Tracker folks use it with a PIC, and they don't appear to have any problems at all.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-22 22:43
    I would connect the tx to a resistor, 1st a 4.7K resistor to 3.3V.
    The rx pin, I would use 2 resistors, 1st a 4.7K resistor to 3.3V and 2nd a 1K resistor to the c168i tx
    A pullup pulls the pin to +ve voltage - 3.3V for the prop, pulldown pulls to GND, both are normally 4.7K-10K range. An inline is used with the prop as a quick way to interface to 5V, often 1K is used. An inline is used when the prop is an input, in this case for the c186i tx to prop rx.

    If you have a meter you could measure the voltage on the c168i rx input, just in case it has a pullup to 5v. If it is at 5v you could try a 1K inline from the prop tx to the c168i rx but I haven't had much success doing that.
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-22 23:36
    Here's the OpenGPS Tracker schematic, they are running at 3.3V. Does that rule out the need for pull-up resistors? Should I try FullDuplexSerial?

    microcontroller1.jpg
  • william chanwilliam chan Posts: 1,326
    edited 2008-08-22 23:37
    Does the serial cable come standard with the phone?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-22 23:49
    No, I had to make the cable. They don't even mention that the headphone jack doubles as a serial port.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-23 00:45
    The attiny84 can have internal pullup so it doesn't negate them unless they haven't been enabled in the software. It isn't 5V tolerent so you shouldnt need the inline resistors and the opengpstracker website uses max3232 for 3.3 operation so I would try just the pullups

    I just took a quick look at the opengpstracker software, the way I read it says you will need the pullups.

    Post Edited (Timmoore) : 8/23/2008 12:51:37 AM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-08-23 05:24
    Jay,
    Being a newbie, I didn't know that such a thing was even possible. This is totally interesting. Where did you learn about this? When you get it to work, please give us an update on how you did it. I'm blown away.

    Mark

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It might be the Information Age but the Eon of Ignorance has yet to end.
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-23 13:43
    Mark,

    I'm new myself, and just learned about this by accident. I'll post something when I get it to work with the Propeller. Right now I'm just trying to get it to send text messages, but it could also be used for receiving them. I'm just going to use it as a backup to my balloons primary location transmitter.
  • Paul RowntreePaul Rowntree Posts: 49
    edited 2008-08-24 07:17
    Hi again;
    This looks very good! It is odd that the phone's web site does not mention the interfacing aspects.

    Do you have any idea of the maximum altitude for which the cell phone will maintain a connection? The 9-11 conspiracy theory folks made quite a bit of fuss over this at one point ...
    Cheers!
  • BradCBradC Posts: 2,601
    edited 2008-08-24 09:30
    Hrm.. I can seriously see implications for this for cheap remote monitoring and server monitoring..
    .. off to the shops to see if I can get one locally!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pull my finger!
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-24 11:34
    Hi Paul, I don't know the maximum altitude. With its internal antenna, I don't imagine it's very high. I'm only going to use the phone as a backup locator.

    Brad, please get one and try it. I know it will work, I'm just stuck. Maybe you can figure it out.

    It just occurred to me that I was one able to get the phone to send a text message by hooking it up to the prop plug directly, and manually entering the command strings. Does anyone know the electrical characteristics of the signal leaving the prop plug?
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-24 19:04
    Mike from the OpenGPS Traacker posted this:

    Mike said...
    Sat Jun 21, 2008 10:11 am

    The phone will work; I have never seen one not work. You need a three-lead jack: base, sleeve, and tip. Base is common, sleeve is phone transmit out, microcontroller receive in. Tip is phone receive in, microcontroller transmit out. The polarity is inverted compared to RS232 from a PC and is about 3.3 volts. A MAX3232 chip works great to interface with a PC. A microcontroller on 3.3 volts works directly. Start bit low, data true (0 volts = 0) and stop bit/idle high. Yes 4800 baud works. Expect to send AT<cr> twice before getting a reply.

    What does " Start bit low, data true (0 volts = 0) and stop bit/idle high" mean? I'm away from my setup right now to test it but does this confirm Tim's suggestion that I need to putt a pull up resistor between the Propeller's transmit and the phone's receive pin? Can this be mimicked with software?
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-24 19:21
    Jay, some comments
    1 Add a cog that receives from the phone and outputs to debug serial port (pin30/31) and see if you are getting any response from the phone.
    i.e. a cog that just does
    repeat
    debug.tx(serial.tx)
    2. Simple serial doesn't take the tx line high until it sends the first character. I would expect the phone to get confused with the first character because of this. Either a pullup between the prop tx and +3.3V or try sending AT<cr> a third time in case the first AT is getting lost. In fact I would just send AT several more times in your init routine to see what happens and reduce the number once you have it working.
    3. Getting the debug serial port going is going to help if it is working to the phone but the sms commands are not working - I noticed in the opengpstracker website you have to put the phone in a special mode for this to work - did you do that?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-24 20:18
    Jay,

    I tried the attached code on my 168i, and I got the "AT" echoed, plus an "OK" from the phone. I think one problem is that you didn't terminate your AT commands with a carriage return. Another issue is the phone going to sleep after a few seconds of no communication (as evidenced on my scope). When this happens, you need to get its attention again before sending anything. I use the "+++" preceded and followed by a one-second delay. This is the standard attention signal for the AT command set to put the device into command mode and seems to work here as well. The phone will not echo the "+++", but if it is already awake when it receives the attention signal, it will reply "OK".

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-25 10:46
    Thanks guys. I've tried everything and have come to the concludion that I may have fried the serial port. I can't even get it to echo AT using the Prop Plug. I'll get a new one today and try again.

    Jay
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-29 02:02
    This thread had dropped to page four already.

    Jay, any success yet? Even without the balloon aspect, it's an interesting project. Fill us in!

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-30 00:14
    Hey Phil,

    Thanks for asking. No, I still think I killed the phone somehow. I started my fall semester on Tuesday, so haven't had time to buy a new one, but I'm actually out the door to head to Radio Shack to get a new one. I'll let you know.

    Jay
  • Mike CookMike Cook Posts: 829
    edited 2008-11-27 23:13
    Just an FYI.......
    If you want 'play' with this phone via a terminal program it's pretty simple to connect this phone to a USB2SER adapter that Parallax sells, could possibly also use a PropPlug or just build a MAX3232 interface. Connections below for USB2SER:
    2.5mm Audio Jack     USB2SER - REV A
    ------------------------------------
    Sleeve - Ground      VSS
    Ring - Phone TX      RX
    Tip - Phone RX       TX
    
    


    Looks like the phone will 'auto baud' I've used 19200 in ProComm. AT+CLAC will list off all AT-Commands that this phone will respond to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike
  • john_sjohn_s Posts: 369
    edited 2008-11-27 23:32
    FYI... so I guess·a·picture below shows signal names from the point-of-view of·c168i·audio jack·:-)

    I still wonder if anybody was ever able to interface any other cellphone from the same manufacturers named·C257, C261, V175, V176, V177, W375, C168, and W220.

    attachment.php?attachmentid=56523

    Post Edited (john_s) : 11/27/2008 11:48:50 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-12-01 00:02
    Hi All,

    Finally got a tracphone that will work in my area, but I ma having trouble finding much hack type information on it. It is a Kyocera K126C. Any pointers on finding out some info on this one? All I want to do is send text using a Prop with it, as part of a remote alarm system. I suppose if nothing else I can pull it apart and tap into the buttons, but something a little more elegant would be prefered.

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Mike HuseltonMike Huselton Posts: 746
    edited 2008-12-01 01:16
    This link looks promising:

    www.smart-clip.com/news.php

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH - Electronics: Engineer - Programming: Professional
  • JonathanJonathan Posts: 1,023
    edited 2008-12-01 15:15
    Quantum,

    Took a look, but didn't see any info about this phone. I'm not looking for hack info, just want to send text messages as above in this thread. The battery is charged, so I'm going to start but just seeing if it will respond as above.

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-12-01 22:09
    Phil, Jay, I don't know if you are still following this thread or not...

    Been playing with the Kyocera K126C today. Using Phil's code, both pins show the AT commands etc, at exactly the same time, regardless of which pin is RX or TX. The start routine returns a -1. If I unplug the phone, the Prop endlessly restarts. With Jay's code (which I had downloaded previously and can't see in this thread now) it returns a -1, again regardless of which pins I us as TX/RX.

    Does this provide any clues? I don't even know if this phone has a comm port connected to the headphone jack.

    The dang thing has weird screws, so I am having a tough time taking it apart to hack into the keypad. Might have to drill them out...

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • gonzobrainsgonzobrains Posts: 27
    edited 2009-12-30 20:28
    I had no idea you could interface to a Motorola c168i like this. Where can I get more technical details about it? AT commands, etc.? I thought that jack was just for headphones! Can you use it to make a GPRS data connection? wow. Who would have thought....

    Can you connect a HYDRA board directly to it for wireless data connections?

    Thanks,
    gonzobrains
  • eblanckeeblancke Posts: 26
    edited 2010-01-05 15:00
    Jay,
    Have you made any progress with the motorola c168i interface?
    This seems like to very promising project.
    Regards
  • gonzobrainsgonzobrains Posts: 27
    edited 2010-01-05 22:50
    I am speaking with some guys who are using an Arduino with the c168i to make a car security project. They are connecting the Ardunio to the c168i with a MAX3232 chip. Would you need this chip for signal conversion if you used the HydraNet port? Maybe you could just make take an RJ-45 cable and splice it to a headphone/mic plug directly?

    If that was the case I would make one right away and start tinkering.
  • pgbpsupgbpsu Posts: 460
    edited 2010-12-29 21:04
    Jay,

    I tried the attached code on my 168i, and I got the "AT" echoed, plus an "OK" from the phone.

    -Phil

    Phil-

    I tried modifying the code you provided to work with the pins 30/31 on the proto board since I don't have a TV out (or TV for that matter). I've included it below. I'm not sure my version does the same thing. I AM sure that my phone doesn't respond, but I can't figure out if it's because the code isn't modified correctly, or because the phone isn't wired correctly.

    Looks to me like "+++" needs to get passed to the phone then wait the correct amount of time and then send AT. Phone should respond with "OK". It does not. Does the display on your phone do anything when your code is executed? My does not turn on the backlight up when "asleep" even if I run this code and if my phone is "awake" and I run the code, the backlight goes out when the 10 sec timer expires. It really acts like my proto board isn't speaking to the phone. Is there any other way to force the phone to spit out anything over this port?

    I've checked continuity in my cable (between proto board and tip of 2.5mm plug) and that's fine. I've spent most of the day working this problem and I'm not sure I'd see a glaring error right in front of me at this hour. Can anyone provide a sanity check?

    In desperation, I tried flipping the PHONE_TX and PHONE_RX lines. Same (nil) response from phone. Did I fry the phone's serial port by doing that?

    Thanks,
    Peter

    PHIL'S VERSION
    CON
    
      _CLKMODE                  = xtal1 + pll16x
      _XINFREQ                  = 5_000_000
      RCV_PIN                   = 5                                  ' Connect to ring on 2.5 mm phone connector         
      XMT_PIN                   = 6                                  ' Connect to tip on 2.5 mm phone connector
      CR                        = 13 
    
    OBJ
    
      sio   : "basic_sio"
      tv    : "tv_wtext"
    
    PUB start
    
      tv.start(12)
      sio.start(RCV_PIN,  XMT_PIN, 4800)
      tv.str(string("RESET"))
      waitcnt(cnt + clkfreq * 2)
      tv.out(0)  attention
      sio.str(@at_command)
    
      repeat
        tv.out(sio.in)
    
    PUB attention
    
      waitcnt(cnt + clkfreq)
      sio.str(string("+++"))
      waitcnt(cnt + clkfreq)
      return
    
    DAT
    
      at_command                    byte  "AT", CR, 0           ' Phone should return "OK"
      
    

    MY VERSION
    CON
    
      _CLKMODE                  = xtal1 + pll16x
      _XINFREQ                  = 5_000_000
    '  RCV_PIN                   = 5                                  ' Connect to ring on 2.5 mm phone connector         
    '  XMT_PIN                   = 6                                  ' Connect to tip on 2.5 mm phone connector
    
    '***************************************
    ' UART Constants
    '***************************************
      CR                =     13 
      DEBUG             =      0
      DEBUG_TX          =     30
      DEBUG_RX          =     31
      DEBUG_BAUD        = 38_400
    
      PHONE             =      1
      TX_TO_PHONE       =      0       '  red wire on my phone cable is the tip = Phone RX from Prop
      RX_FROM_PHONE     =      2       '  black wire on my phone cable is the ring = Phone TX to Prop
      PHONE_BAUD        =  4_800
    
    OBJ
    
      uarts    : "pcFullDuplexSerial4FC"               '1 COG for 3 serial ports
    
    VAR
      byte passThroughCogId
      byte serialCogId
    
    PUB start   | RxByte
      uarts.Init
    
      uarts.AddPort(DEBUG,DEBUG_RX,DEBUG_TX,-1,-1,0,0,DEBUG_BAUD) 'Add DEBUG port
      uarts.AddPort(PHONE,RX_FROM_PHONE,TX_TO_PHONE,-1,-1,0,%000000,PHONE_BAUD) 'Add GPS NMEA port
    
      serialCogId := uarts.Start - 1                                           'Start the ports
      waitcnt(cnt + clkfreq * 2)
    
    '  passThroughCogId      := cognew(PASS_THROUGH(NMEA),@stack1)      'Start the Process_GPS Cog
        
      uarts.str(DEBUG,string(13,"Serial ports running in cog:          "))
      uarts.dec(DEBUG,serialCogId)
    
    
      uarts.str(DEBUG,string(13,"RESET",13))
      waitcnt(cnt + clkfreq * 2)
      attention
    
      uarts.str(PHONE,@at_command)
    
      repeat
        RxByte := uarts.rxcheck(PHONE)       ' collect byte from PHONE port
        if RxByte <> -1                     ' -1 means no data; don't do anything
    '      uarts.putc(DEBUG,RxByte)
          uarts.hex(DEBUG,RxByte,2)
    
    PUB attention
    
      waitcnt(cnt + clkfreq)
      uarts.str(PHONE,string("+++"))
      waitcnt(cnt + clkfreq)
      return
    
    
    DAT
    
      at_command                    byte  "AT", CR, 0           ' Phone should return "OK"
      
    
  • pgbpsupgbpsu Posts: 460
    edited 2010-12-31 10:24
    I know I resurrected a really old thread the other day but I wanted to update it for completeness. Turns out the audio cable I purchased from Digikey didn't seat all the way into the phone. I got a $3 connector at RadioShack and soldered it up. I was then able to get a modified version of Phil's code to work.

    I'm up and texting! Thankfully no blown serial port. I simply followed the setup instructions Jay posted from opentracker. They had to do with backlight and going to sleep so I don't think it had anything to do with the serial port. It's a bit disconcerting that the phone doesn't give any indication that it's sending a message. The display remains dark, but it is in fact sending messages.

    Thanks again Jay for bringing this to our attention.

    Happy New Year.
    Peter
Sign In or Register to comment.