Wednesday, January 5, 2011

Connecting Nokia phone to arduino ( USB Cable)

The moment I started using Arduino, I realized that to expand its capabilities I would need to spent quite a lot of money purchasing wifi shield, gps shield, BT shield and so on. I soon realized that it would be a good idea to connect my arduino to a modern cell phone since the phone already has many of these desired features built-in. One way to accomplish this would be to use a BT shield, but it is a waste of wireless features, and so I decide to use BT or wifi just for remote control.After a lot of googling, I found a USB Host Shield from Circuits@home which gives to arduino the ability to "talk" with almost every usb devices. In their web site they already get the arduino talking with some other usb devices.
When I saw this, I thought that this would be the shield I need to get my mobile phone talking with arduino through cable. And that is what this post is about.



Parts needed:

  1. Nokia phone ( anyone with usb port, i used n95)
  2. cable
  3. Arduino
  4. Usb Host Shield form Circuits@home
Phone side:
  1. Firstly, i installed the "glass term" example program from Symbian SDK, which is an good example of Serial communication.
  2. I tested the communication with HyperTerminal on windows. it worked! The phone side is done!
source files: GlassTerm (included in your nokia sdk)
    Arduino side:

    This side is s little more tricky because you need to have some knowledge of USB protocol. I use this document to get the information i needed:usb-in-a-nutshell

    1. When doing step 2 of phone side i sniff usb communication, using snoopPro to get how information flows back and forth between arduino and pc, and to check from what endpoint the data leaves the phone. This endpoint is controlled by an interface which by turn is controlled by a class interface.
    2. Supposing that the endpoint number was known, i used an example from circuits@home which allow me to get device descriptor to make sure if it exists in arduino configuration speed. The configuration speed in the connection between the phone and the pc is one, and between the phone and the arduino can be another. And the configuration speed can change the struture of interfaces and endpoints.
    3. Luckly, the configuration speed was the same, so the endpoint number also will be the same. I used a Bt dongle code example from circuits@home and modified some instructions, as to configure the class interface.
    4. After all this work, i test it. it worked, but not in the first try :S
    5. My worse problem was to understand usb protocols and configurations. 
    source file:usb_nokia.pde
      My Video:



      Hope you enjoy.

      33 comments:

      1. All I can say is excellent and well done as I am currently trying this as well.

        Would you share your Arduino code?

        David.

        ReplyDelete
      2. hi, i got aswell a n95 and wanted to do the same, like using the n95 cam and gps and that stuff and transmit this data to the arduino.

        so would be nice if you could share your code(s) mobile and arduino that i can go on from there.

        another question, a usb host shield is a must have because the normal arduino usb is just a slave?

        ReplyDelete
      3. I will post the code on next weekend, for now i'm too busy with university.Hope u understand.

        Don't try to send camera pictures to arduino, images has a lot of information and arduino is too slow to process them with acceptable quality.

        And yes, u are right! Arduino is a usb slave as almost every device among us. it's why we need a usb host shield.

        What is the platform u use to program to nokia?

        Regards

        ReplyDelete
      4. Hi, interested in your project as well so shared code would be more than appreciated..

        Btw, have you tried Qt on the Nokia side? Makes Symbian programming so much easier.

        BR

        ReplyDelete
      5. my android phone can pair with the device but it always says "paired but not connected" any idea whats the problem?

        ReplyDelete
      6. Sorry, but i never used an android before!

        Sorry everyone, my source files should be online a long time ago, but my college consumes all my time! I 'll try to post it as soon as possible
        Regards

        ReplyDelete
      7. Hi, interresting project as well so shared code would be more than appreciated. hope that you will do it as sooner as possible

        ReplyDelete
      8. Hi

        Any chance to see the code + some more detail instructions how to get there any time soon?

        Thx

        ReplyDelete
      9. i'll try to post the source files in the end of June...

        ReplyDelete
      10. Hello, Really nice work.
        I'm a Telecomunication engineering student, and i'm working on a project with arduino, where i also need to connect it to a mobile device, here i share my blog where i will be publishing my improvements. http://androino.blogspot.com/

        I think that your work would be a great opportunity to try as an option, so could you please share the code and anything could help me please??

        Thank you very much. I hope to keep in touch to progress with our respective jobs.

        ReplyDelete
      11. Source files have are posted! Hope it will be usefull to you.

        ReplyDelete
      12. hi you're project is nice. please help me with my thesis project. am i allowed to control my cellphone N95 to go on its features? may i see your codes? where can i see it? thanks a lot!

        eric :)

        ReplyDelete
      13. Read the entire post and you will find the source files.

        ReplyDelete
      14. Thanks a lot for your work!

        ReplyDelete
      15. I have read the entire post but could not find the source files.Please help

        ReplyDelete
      16. Last line of each side (phone and arduino), you have a "source file":and a link to megaupload.

        ReplyDelete
      17. hi, Im a beginner with the arduino and i'm wondering if it's possible to connect the nokia in the usb port of the arduino(the converded serial port which is used to program it).
        Thanks

        ReplyDelete
      18. You cant connect nokia to arduino just like that. Your nokia is usb slave as the arduino. you need the shield i used in this project to give the arduino usb host capabilities. Read the entire post and you'll get this connection established. good luck

        ReplyDelete
      19. Please could you send me source code, I am beginner, I need send and receive SMS.
        Thanks
        Cyril
        cyrilja@seznam.cz

        ReplyDelete
      20. Can I use Arduino USB 2 serial converter for
        connection Arduino and Nokia C1 ?

        ReplyDelete
      21. Nop,this wont work because you always need the nokia usb driver to tell which end point to read the data.Im my project i had to write a program to arduino that act like a driver.

        ReplyDelete
      22. Hi! Looks great. Could you repost the source somewhere else? MegaUpload is having a few problems.

        ReplyDelete
      23. mate source file:usb_nokia.rar doesnt exist anymore, pls upload again, thx

        ReplyDelete
      24. Sorry for that. I'll try to repost as soon as possible.

        ReplyDelete
        Replies
        1. GlassTerm.rar and usb_nokia.rar

          thanks

          Delete
      25. Hi there, really interested in the source code but MegaUpload has been taken down - any chance you can upload the code somewhere else?

        ReplyDelete
      26. Hi can you put your file sources on another active server plzz.
        Thanks

        ReplyDelete
      27. Sorry!!!!


        I finally could spend some time configuring github...
        Source files are already online.

        Take a look.

        ReplyDelete
      28. Hi, I try to connect my nokia 3600slide with arduino adk mega but when I connect together I recive:

        Data packet error: 7DRequest error: 7D

        Do anyone know what that mean and how to fix that?

        ReplyDelete
      29. Did u already read usb-in-a-nutshell? i think there are an error list...

        it seems to me that you are trying to request data from a wrong endpoint.
        You need to find what endpoint is dedicated to serial connections

        Good luck

        ReplyDelete
      30. yes I read usb-in-a-nutshell (not realy read more look), and I didn't see error list, now I am reading little slowly, and trying to find the mistake.

        And thank you for fast answer.

        ReplyDelete
      31. Dear Fialhon,

        I'm working on a project which need a WAN connection because of I didn't find here in my country any UART GPRS Module so I thought in USB Modem.
        I'm using Arduino Mega and found that it's a USB Slave Device so I had made some searches and found to interface USB device I'll need a USB Host so I had purchased the USB Host Shield v2.

        I saw example Interfacing Arduino to USB GPRS modem
        www.circuitsathome.com/mcu/interfacing-arduino-to-usb-gprs-modem
        (with PL2303 example) I got infinite loop of Ret: 0D
        like:-
        Ret: 0D
        Ret: 0D
        Ret: 0D
        Ret: 0D
        Ret: 0D

        then I saw the other example Interfacing Arduino to a Cellular Phone
        http://www.circuitsathome.com/mcu/programming/interfacing-arduino-to-a-cellular-phone
        I have run it but unfortunately didn't work I got

        Start
        ACM Init
        Addr:1
        NC:1

        I have searched about the USB and found that the USB Stick, it's a combo USB Device containing many devices like Modem, CD(in which its Driver) and Card Reader.
        So to get it work I should run it in the Modem mode only.
        I found that with Huawei USB Stick, just send the AT Command "AT^U2DIA=0" and for ZTE USB Stick "AT+ZCDRUN=E" this command will force the USB Stick to run in the Modem mode only.

        I think here the USB Stick side is done.

        the other side with Arduino Mega and the USB Host Shield

        I run the USB descriptor example after force the USB to run in the Modem mode only and got:

        Device descriptor:
        Descriptor Length: 12
        Descriptor type: 01
        USB version: 0200
        Device class: 00
        Device Subclass: 00
        Device Protocol: 00
        Max.packet size: 40
        Vendor ID: 19D2
        Product ID: 0016
        Revision ID: 0000
        Mfg.string index: 03
        Prod.string index: 02
        Serial number index: 00
        Number of conf.: 01

        Configuration descriptor:
        Total length: 0055
        Num.intf: 03
        Conf.value: 01
        Conf.string: 01
        Attr.: E0
        Max.pwr: FA

        Interface descriptor:
        Intf.number: 00
        Alt.: 00
        Endpoints: 02
        Intf. Class: FF
        Intf. Subclass: FF
        Intf. Protocol: FF
        Intf.string: 00

        Endpoint descriptor:
        Endpoint address: 81
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20

        Endpoint descriptor:
        Endpoint address: 01
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20

        Interface descriptor:
        Intf.number: 01
        Alt.: 00
        Endpoints: 02
        Intf. Class: FF
        Intf. Subclass: FF
        Intf. Protocol: FF
        Intf.string: 00

        Endpoint descriptor:
        Endpoint address: 82
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20

        Endpoint descriptor:
        Endpoint address: 02
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20

        Interface descriptor:
        Intf.number: 02
        Alt.: 00
        Endpoints: 03
        Intf. Class: FF
        Intf. Subclass: FF
        Intf. Protocol: FF
        Intf.string: 00

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 03
        Max.pkt size: 0040
        Polling interval: 05

        Endpoint descriptor:
        Endpoint address: 84
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 20


        Addr:1(0.0.1)

        ReplyDelete
        Replies
        1. After I have modified the PL_VID & PL_PID in cdcprolific.h
          and run again pl2303_gprs_terminal
          stop getting infinite loop of Ret: 0D
          just got

          Start
          PL Init
          Addr:1
          NC:1
          Conf:1
          PL configured

          but when sending AT Commands I didn't get any back response

          just “^BOOT” and “^RSSI” keep coming back (I don't know what's it)

          I have these USB Modems list:
          ZTE MF180
          Huawei E220
          Huawei E303
          Huawei k3565
          Huawei k3765
          Huawei K3770
          and tried all the about on them but didn't work

          Also I've installed the USBlyzer on my PC to sniff the USB data and know about the endpoints

          URB Select Configuration succeeded
          Device Object USBPDO-8
          Driver Object usbhub

          URB Function URB_FUNCTION_SELECT_CONFIGURATION
          URB Status USBD_STATUS_SUCCESS

          Configuration 1

          Interface 0 / Alt 0 Vendor-Specific, 2 pipes
          Endpoint 81h 1 In, Bulk 512 bytes
          Endpoint 01h 1 Out, Bulk 512 bytes

          Interface 1 / Alt 0 Vendor-Specific, 2 pipes
          Endpoint 82h 2 In, Bulk 512 bytes
          Endpoint 02h 2 Out, Bulk 512 bytes

          Interface 2 / Alt 0 Vendor-Specific, 3 pipes
          Endpoint 83h 3 In, Interrupt 64 bytes
          Endpoint 84h 4 In, Bulk 512 bytes
          Endpoint 03h 3 Out, Bulk 512 bytes

          I know you don’t need to support this but I really hope you just guide me to modify the acm_terminal or write a driver to get my modem work.

          Best Regards,

          Kareem

          Delete