Shopping Cart

Posts

Bluetooth code for Arduino USB Host

Arduino to Bluetooth connection

Arduino to Bluetooth connection

[EDIT]The standard RFCOMM/SPP implementation is available in rev.2.0 of the library.[/EDIT]

I am pleased to announce addition of Bluetooth dongles to the family of USB devices supported by USB Host Shield. Bluetooth dongles are affordable, interface is well documented, and USB transport layer is very simple. Even though full Bluetooth protocol is heavy and takes a lot of program space, it can be stripped down quite a bit for a particular application. One good example of such approach is Richard Ibbotson’s HID over Bluetooth implementation – see Wiimote Game Controller Interfacing article for details. I wanted to have simple communication transport over Bluetooth which would fit into Arduino and the code I’m presenting in this article is doing just that – it’s lightweight terminal program allowing two Arduinos talk to each other over Bluetooth. The code has been developed by George Lgotkin.

The source is hosted in GitHub repository. Standard Arduino library format of the code has not been tested yet, for now it’s easier to just copy all the files in a directory and open btclass_h.pde in Arduino IDE. To use the program, you need two Arduinos, two USB Host Shields, and two Bluetooth dongles. You need to compile and load the sketch into both Arduinos and then open two terminal windows, one to a serial port of each Arduino – this can be done from a single computer. Don’t use Arduino IDE built-in terminal. Also, SPI library shipped with recent versions of Arduino IDE is not compatible with USB Host library, if you have compiler errors related to SPI, replace your library with one from Arduino-0018 or the Playground. Serial port speed is set to 115200 in the sketch, it can be changed in setup(), if necessary.

Sketch starts by printing short help (see screenshot below) and then waits for the command. In order for two Bluetooth devices to talk to each other, one has to be the server and another one client. In one terminal, type ‘S’ and press Enter. This starts the server. If you are curious, type ‘M’, Enter – the address of the module will be printed. Note that if you send address request before starting the server, address containing all zeroes will be returned.

To establish connection, type ‘C’, Enter in other terminal. The sketch will print “Connecting…”. After some time ( 30 seconds or less ) both terminals will print “Connected”. Now type something in one terminal and press Enter – the string you just typed will appear in other terminal window. Easy.

This code is just a small example, error handling is minimal. It works better if no other Bluetooth radios are transmitting nearby. If client Arduino reports “Connected” but server doesn’t, it means that client has connected to some other server, most likely your laptop or phone. This can also be used to your advantage for testing – start Bluetooth on a PC and then see if both Arduinos are able to connect to it in client mode.

It is possible to instruct client Arduino to connect to a particular host. Look into Serial.cpp file. InbufAnalyse function contains addrA.bytes array initialization. You can initialize it with address of the Bluetooth dongle connected to other Arduino (note that address bytes are loaded backwards), recompile, load, and then use ‘A’ instead of ‘C’ for client connection.

Bluetooth sketch screenshot

Bluetooth sketch screenshot

The code has been tested with different Bluetooth dongles from different manufacturers and they all seem to work fine. Sometimes one dongle refuses to work as a client so alternating server and client roles on Arduino may help. If you see any other errors, leave a comment here and I’ll try to help.

In this sketch, communication occurs over plain HCI so it can’t be used to talk to a PC or a phone. On the other hand, the code takes less than 11K of program space and can be used on Atmega168-based Arduinos. The code which implements SDP, L2CAPS and RFCOMM is in the works and will be released soon along with the documentation. For the time being, play with this code and tell me what you think.

Enjoy,
Oleg.

No related posts.

128 comments to Bluetooth code for Arduino USB Host

  • elias.alberto

    Damn, I had written a long, long, LONG post, but all I would really like to do is to THANK YOU!
    I’ve been looking for years for a simple and cost-effective way to put cheap $2 BT dongles to uCs, so I could put BT in every project I make. You have obviously realized how cool it would be if our projects could talk to our cellphones and computers wirelessly and you’re probably trying to make it work so I won’t bother you asking why it doesn’t work, but you might have not though it would also be cool if there was a way to make the uC (not necessarily an Arduino; I like atmega48 because of their price and availability) talk directly to the ICs in our BT dongles. Many of these ICs already have I2C, SPI or UART, so it seems feasible. I’ll (hopefully) spend my next vacation working on your code to try to make it work without USB on my regular atmega48s. If you could also provide some documentation or maybe point out what needs to be modified to make this idea feasible, I would be very thankful!
    Once again, congratulations for the excellent job you did there!

    • I also spent some time exploring this topic for similar reasons – USB BT dongles on eBay are $1 shipped. I don’t think you can use SPI or I2C of BT chips to transfer data – they seem to be there for firmware programming only. USART may be used if it’s a)supported in the firmware as HCI transport and b)pins are routed out. I’m yet to find such a dongle but if you have one, changing George’s code to USART is simple – only HCI layer needs to be modified, and transport is documented in BT spec.

      The BT code will be expanded to support RFCOMM so talking to laptops, phones and such will be possible. At present, tt’s not the most cost-effective BT solution for Arduino. However, I’m working on a version of USB Host library which will not be dependent on Arduino definitions and support multiple devices via a hub. When this is done, BT radio can be used concurrently with whatever USB peripherals you have in a project.

  • Richard

    The USB chips used in the dongles are not well documented on their interface except the CSR devices. The CSR devices do have USART and SPI interfaces as well as USB and I2C to access the EEPROM. However the cheap dongles do not seem to bring these signals out from under the BGA chip.
    Low cost USB dongles which use the CSR tend to use the ROM version which is more limted than the flash based devices. Many chips which say they are CSR in the descriptors are not true CSR.
    The pricing of CSR based boards (often flash based too) which expose the other interfaces has dropped significantly, so you might meet your goal, but maybe not with the USB dongle.
    http://cgi.ebay.co.uk/2-pcs-Serial-Bluetooth-RF-Transceiver-Module-rs232-/330452405153?pt=LH_DefaultDomain_0&hash=item4cf07f8ba1

  • Alcatraz80

    I’ve connected my dongle but the address is My BDADDR:0:0:0:0:0:0! Why? Thanks!

    • Have you started server first, as described in the article?

      • Billy

        I’ve another one returning all zeros also. It looks like a CSR modem. This is what USB desc reports:

        01

        Device descriptor:
        Descriptor Length: 12
        Descriptor type: 01
        USB version: 0200
        Device class: E0
        Device Subclass: 01
        Device Protocol: 01
        Max.packet size: 40
        Vendor ID: 0A12
        Product ID: 0001
        Revision ID: 3164
        Mfg.string index: 00
        Prod.string index: 02
        Serial number index: 00
        Number of conf.: 01

        Configuration descriptor:
        Total length: 00B1
        Num.intf: 02
        Conf.value: 01
        Conf.string: 00
        Attr.: C0
        Max.pwr: 00

        Interface descriptor:
        Intf.number: 00
        Alt.: 00
        Endpoints: 03
        Intf. Class: E0
        Intf. Subclass: 01
        Intf. Protocol: 01
        Intf.string: 00

        Endpoint descriptor:
        Endpoint address: 81
        Attr.: 03
        Max.pkt size: 0010
        Polling interval: 01

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

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

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0000
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0000
        Polling interval: 01

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0009
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0009
        Polling interval: 01

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0011
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0011
        Polling interval: 01

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0019
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0019
        Polling interval: 01

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0021
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0021
        Polling interval: 01

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

        Endpoint descriptor:
        Endpoint address: 03
        Attr.: 01
        Max.pkt size: 0031
        Polling interval: 01

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 01
        Max.pkt size: 0031
        Polling interval: 01

        Addr:1(0.0.1)

        • Billy

          Here is the output from PS3BT

          PS3 Bluetooth Library Started
          Bluetooth Dongle Initialized
          No response to HCI Reset
          HCI Reset complete
          Local Bluetooth Address: 00:00:00:00:00:00
          Wait For Incoming Connection Request

          • Billy

            This is what my MacBook reports in system info

            BT2.0:

            Product ID: 0×0001
            Vendor ID: 0x0a12 (Cambridge Silicon Radio Ltd.)
            Version: 31.64
            Speed: Up to 12 Mb/sec
            Location ID: 0xfa130000 / 7
            Current Available (mA): 500
            Current Required (mA): 0

  • Alcatraz80

    Yes, i do. I shall want connect my android phone to arduino with USB Host Shield and bluetooth dongle then i used this code source for my arduino board.
    Please, have you some suggest? Thanks :-)

  • Alcatraz80

    Ok, i shall try it this evening. Thanks.

  • Alcatraz80

    Ok, i tried your suggest but it didn’t work. Please, can you help me??? Are you sure that is possible to connect my phone to arduino via bluetooth? Thanks

    • The code posted here won’t work with the phone or any other standard serial over RFCOMM implementation. I have code for standard serial, will post soon.

      • Dmitry

        Hi Oleg!

        Could you post a link to the source code?
        I’am building an arduino based quadrotor using detais I could find at home and I’d like to use my android as rc control :)
        I’ll put arduino with usb host shield and attached bluetooth dongle on it and will use bluetooth as radio link.

        Thanks!

        • The link to the code is in the article, first line of the second paragraph.

          • Dmitry

            Is that standard serial over RFCOMM implementation? I tryed to connect from android to the arduino with bluetooth dongle.
            Unfortunatelly, every time I keep getting “Connection refused” exception from the android.
            At the same time, arduino output says its connected and some unreadable symbols. Here is a screenshot.

            Do you have any ideas what it could be?

            Thanks!

  • Anders

    Great work! Nice to see that this project is still alive. With RFCOMM support this opens up a whole lot of possibilities like using the amarino toolkit (http://www.amarino-toolkit.net/) to communicate and read sensors from an android phone.

  • alcatraz80

    Infact, i’m interested to amarino :-)

  • thelodge

    Hi Oleg

    Great work too! When you mention standard serial, could this be used to connect to a mobile phone using the serial port profile? Is it possible to post the code? Thanks

  • RedGuy

    Hello Oleg,

    Just wondering about supporting multiple devices using your Host Shield design. Aside from an extra USB port, what other modifications would be required to both read an HID device such as a mouse, and also connect to an Android device using a Bluetooth Dongle? Is this a reasonable goal?

    Thank you,

    • Next revision of the library will support USB hubs so you would be able to communicate to multiple devices. However, it is unlikely that a code for two devices, hub and full Bluetooth (not the type described in this article) would fit into Atmega328P; it will be more on a scale of 1280 or 2560.

  • Hi Oleg,

    Any progress with RFCOMM implementation? Thank you!

    • I put it on a back burner for now

      • Hi Oleg,

        How much work do you think it is? Is there any other way to communicate with something like Android or iPhone over bluetooth? Thanks.

        • With embedded development you never know how much is left until you finish. I have an RFCOMM code which works with Linux and some phones. It doesn’t work with windows stacks, I don’t yet know why. I got android phone yesterday, when I have time I’ll check it and post the code as-is, leaving windows support for later.

          You won’t be able to connect to iphone via RFCOMM.

  • hello,
    from where i can get this usb host
    thank you

  • Hi,

    Do you have News about Bluetooth dongle and Android phones?

  • Jason Mitnick

    Oleg,

    It’s Jason again! I’ve tried to run your sample code but to no avail. I have the same exact bluetooth dongle as in the picture, and yet when I compile and run everything I am unable to input. Is it a setting on PuTTY or something simple like that?

    Thank you for the quick replies and help!

    • Don’t forget to press Enter after typing ‘S’, ‘C’, etc. To get the actual connection, you’d need two Arduinos running this code, it is not compatible with standard Bluetooth serial protocol.

  • Jason Mitnick

    Nevermind. I figured out that my VDIP1 is interfering with the serial signals. Any ideas on what I can do to make both work simultaneously.

  • Jason Mitnick

    Does the bluetooth code for the host use all serial pins? Or can I assign it to use specific pin numbers?

    • USB Host Shield doesn’t use serial pins.

      • Jason Mitnick

        That is what I thought initially, but everytime I try to run the code while the VDIP1 is connected…it doesn’t work. It’s not the power, because I can power the VDIP1 while running the code just fine. But the second I plug in the two serial pins for the VDIP, the bluetooth program will not let me input.

        • That’s terminal. Serial pins go to USB to serial converter on Arduino and then to a PC. The USB host is working fine, you just can’t communicate with it.

  • Jason Mitnick

    Ah, I see. So there wouldn’t be any way to connect the pins to the VDIP1 while maintaining communication with the USB host?

  • Jason Mitnick

    Yes! After tinkering with the NewSoftSerial library, I was able to get both your bluetooth dongle program and a VDIP1 readtest program without any interference. It’s now using pins 5 and 6 instead of 3 and 4. Not sure why, but everything works now.

    Thanks a bunch!

  • Manindra

    Fantastic work there Oleg! Really innovative of you to come up with such a great shield! I’m planning to buy it for my next arduino project. I want to communicate through Bluetooth to symbian/android device as well as to my pc using a Bluetooth dongle. Is there a way for serial rfcomm over bluetooth using the current setup yet?

  • jaz

    Is there any way to read sensor values in arduino to android/symbian phone or to pc running xp or win 7.?

  • Is this sketch compatible with v2.0 of USB Host Shield library?

    I am able to run it in v1.0 of USB Host shield library though.

  • Titus

    hi….oleg and everyone

    can we communicate Arduino with Bluetooth USB dongle to Android Tablet Bluetooth???
    Is it possible???
    plz reply ASAP…..
    thanx in advance

  • Florent

    Hi,
    Will this code works with a Sparkfun USB Host shield or just with the Circuitsathome’s one? because this one cost twice the one from Sparkfun (sorry for the rivalry :P )!
    And do you know if the SPP implementation in order to communicate with an Android device trough Amarino toolkit will be possible soon?
    Thanks in advance and i apologize for my poor English: I’m french

  • taipscode

    Hello Mr Oleg.
    Do you have a code.pde about Arduino host shield connect with android phone by Usb bluetooth ?

    If yes,can you reply to my email.
    Thankyou very much.
    I’m from VietNam

  • taipscode

    Hello Mr Oleg.

    Why don’t ?
    -I think ,it’s easy for the best engineer as you.
    -Because i see at:
    http://iteadstudio.com/product/iteaduino-adk-mega2560/
    - The final sentence is :On board USB host makes it easy to interact with USB devices like pen drivers, keyboard, mouse, Bluetooth dongles.
    -So that ,i think Arduino mega ADK can connect usb bluetooth with android phone.

    Thankyou very much.
    Best Regards.

  • taipscode

    Hello Mr Oleg.
    Why don’t you help me!.
    I don’t know what ‘s purpose this web ?

  • Richard

    Taipscode,
    I think you are being very unfair to Oleg on this topic.

    Oleg has gone to great lengths to develop his own products:
    http://www.circuitsathome.com/products-page/arduino-shields/

    Also he has published his hardware designs for other to build and modify.

    Oleg has dilligently developed and published arduino libraries for these products and made them available to others under the GPL2 license. Though this circuits@home site is mainly geared towards the more experianced hobbyists and experimenters, Oleg has provided massive support for users of his own products and often dervived products too.

    You need to understand that the ADK Mega 2560 you have is a product derived from those of Oleg. The responsibility for the performance and the claims of that product belong with the supplier. If you feel the supplier has misrepresented their product, then contact them directly. I did note the suppliers does say:
    “Iteaduino ADK Main Board works like Arduino Mega 2560 with inbuilt USB Host Shield. Hence, this Main Board can be connected to any USB devices. Users have to write their own drivers for using this feature.”

    It is not clear to me how the ADK Mega 2560 board forks software from the developments of Oleg. This should have been considered and published by the ADK board developers, since it was clear Oleg was building new enhancements to the USB libraries for his own boards. Maybe you should ask this on Google ADK or Arduino forums.

  • taipscode

    Thankyou Richard.
    I know ,Mr Oleg is the best engineer ,so i need his help ,it’s little document about Arduino mega ADK host shield connect with usb bluetooth,usb mouse.
    On the forum of Arduino isn’t a good engineer like Mr Oleg.General is newbie like me.

  • AP

    It is possible to connect a BT dongle through a usb hub? I would connect my android to my nikon using both your projects (cameracontrol + bt code)

  • taipscodr

    Oh,i see ,Arduino mega Adk don’t support usb 2.0 ,so it’s can not connect with usb bluetooth.
    I also used Hc05 bluetooth connect with Arduino successfully.
    Thankyou Mr Oleg very much.
    Best Regards.

  • vish33

    Hi everone ,
    I am trying to communicate between my wt 32 bluegiga and arduino. I was looking for some code which can help in connecting the wt 32 with other bluetooth device automatically. ex headsets.

    i need a routine code for these commands.
    can any one help ?

    INQUIRY 5 // command given

    INQUIRY_PARTIAL 00:18:6b:af:d1:15 200404 // response from the WT 32 /Bluetooth add.(00:18:6b:af:d1:15)
    INQUIRY_PARTIAL 00:22:5f:f7:92:8b 000000
    INQUIRY 2 // no of decives found
    INQUIRY 00:18:6b:af:d1:15 200404
    INQUIRY 00:22:5f:f7:92:8b 000000

    2) pair 00:18:6b:af:d1:15 // command given
    PAIR 00:18:6b:af:d1:15 OK // response

    3) call 00:18:6b:af:d1:15 1108 hsp-ag // commande given
    CALL 0 // response
    CONNECT 0 HSP 5

  • taipscode

    Nobody help you ,you should make yourself.
    Mr Oleg never help anybody.
    He only like performance .
    After he died ,nobody can use knowledge of him.

  • taipscode

    Hello Mr Oleg.
    I want to buy code usb bluetooth with arduino mega adk communicate with android phone.
    Can you give me the price and account to send money ?
    I am not joke,i really want to buy this code .
    Thanks.

  • Mat

    Hey Oleg,

    Just an FYI really. This guy http://ytai-mer.blogspot.com/2011/10/ioio-over-bluetooth-or-who-needs-cables.html has managed to add on Bluetooth support to talk to Android phones.

    Mat

  • taipscode

    Oh,really?
    So sad!!! ,thanks.

  • Grant

    Hi Oleg – thanks a bunch for this great code. I’m wondering if you can answer a question – I have this shield (http://www.freetronics.com/products/usbdroid) and a generic USB Bluetooth dongle. I’m trying to be able to send/recieve small bits of data via the Bluetooth (eventually to an Android phone for DC motor control), but I’m not sure how to load a sketch or library in my Arduino IDE to get things going. I basically want to achieve what’s discussed in this tutorial (http://arduino.cc/playground/Learning/Tutorial01) but via the USB-Bluetooth since it’s a dongle, not a modem. Can your code be modified for this purpose, or can hyou suggest another approach? Thanks.

    • This code doesn’t support standard RFCOMM which is necessary to talk to Android via BT. Another approach would be to develop HCI serial code for Android or RFCOMM for USB Host.

  • Grant

    Ok, thanks for the input Oleg. Is any of the HCI code on this page useful as a starting point? http://www.circuitsathome.com/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part-3

      • Jim

        I’ve just taken a quick shot at integrating the HCI code from this page and the BTStack. I didn’t realize that this topic had been raised on this page and would hate to duplicate the work of others. Is anyone else working on it? The phone will pair but not connect, so I suspect that I’ve made almost no progress (I think pairing is an HCI level operation) and, given that I know almost nothing about BT I may not make any further progress.

  • Phil

    I’m testing this Bluetooth library on Arduino v1.0 IDE
    with USB Host Shield library version felis-USB_Host_Shield_2.0-4dcef5e
    but I can’t go through it.
    Does this BT library support Arduino v1.0 ?

    • This code works with legacy library only -> https://github.com/felis/USB_Host_Shield . Legacy library is not compatible with 1.0 and probably never will, you may want to get older revision of Arduino IDE (0022-0023).

    • Phil

      I can compile successfully on arduino 0023 using the version of USB Host Shield you provide.
      Thanks for the reply !

      • Jim

        Phil,

        I have the code for RFComm based on the BTStack implementation. I’m stuck in some other projects so haven’t had a chance find some testers and get it out to the world. If you’re interested in working with it, maybe Oleg can give you my e-mail and we can communicate directly.

        Jim

        • I’m also half-way done on porting your code to 2.0. I have BT dongle init/transfers written, the only thing left is to interface it to your layer. If you’re interested, I can send you what I’ve done so far and share my thoughts on interfacing to BTStack.

          • Jim

            Oleg,

            2.0 support would be great. If you send me what you have I may have some time to look at it shortly (have to get rid of one other project first).

            I think that ALL that is needed for BTStack is modification of bt_h.cpp, specifically an implementation of these methods:
            void TBT::HCI_Poll(void)
            uint8_t TBT::ACL_Poll(void)
            uint8_t TBT::HCI_Send(uint8_t Abytes_count, int8_t * Abytes)
            uint8_t TBT::ACL_Send(uint8_t Abytes_count, int8_t * Abytes)

            With that, BTStack will take care of the rest.

            Jim

  • Peter

    I have got a doubt. I am the beginner, working with arduino. Is it possible to connect usb dongle to arduino board?

  • Mike

    Any update on the RFCOMM functionality? I have been looking for a way to connect an Android phone to the Arduino via a bluetooth dongle but I am not having any luck…

  • Manasa

    is it possible for you to upload codes of l2cap and sdp for arduino megaadk… via usb dongle..our project is near its deadline. Thank you

  • Hello Oleg,

    quite an impressive work in such a short time given that you had to dig into so many areas.

    For an imminent private project of mine with a tight deadline I need the ability to control an Arduino application remotely via Android Smartphone. I’m therefore interested to develop this RFCOMM functionality and have started yesterday to take PS3PT apart. First step was to support the HCI inquiry process. I’m now working on the masterslave switching and its effect on the HCI state machine and the message exchange. Next I’ll have to see what to still add to the L2CAP handling code of PS3BT, and then I would do the RFCOMM itself.

    Is there any source code in your cupboard that I could profit from?

    Or should I better stop the fun and joy of programming and buy a BTM-222 …

    Many thanks in advance.

    Kind regards,
    Sebastian

  • allanonmage

    Hey guys, me again :D I was able to get the USB -> PS3 interface working, so now I’m trying for Bluetooth.

    Sam Arduino MEGA ADK Rev 3. I’m using an actiontec USB->Bluetooth adapter BM200B. I think it’s a Cambridge chip, but not sure. I’ve ordered some Bluetooth dongles that I am much more willing to think will work, but I wanted to try this one in case it did, while I wait.

    I load the sketch PS3BT and I ge what looks like success:
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:20:E0:CC:2A:92
    Wait For Incoming Connection Request

    But I’m not sure what to do next. I skimmed the 3 part series and it seems the OP is talking about development, not usage.

    Somehow I need to get the BT adapter’s hardware/MAC address into the the PS3 controller, right? This is where I am stuck…

    On a related note, if I need to connect a hub to get them both plugged in, will that be automatic software magic-ness, or do I need to load a library and set up some code?

  • allanonmage

    I figured it out! haha!

    You have to go through an iterative process to get things going. First off the 2.0 library does work with Bluetooth now. That was unclear in the OP and comments due to their age. I managed to get this working with an Arduino MEGA ADK Rev 3 and a Cirago BTA-3210.

    Step 1.
    You need to run the PS3BT code with the BT dongle plugged in if you don’t have the MAC address already. If you do have the MAC, you can skip this part. Some dongles have the address on a sticker; some are too small for that.

    Step 2.
    Hard code the MAC into the program in the commented out line:
    // PS3BT PS3(&Btd,0×00,0×15,0×83,0x3D,0x0A,0×57); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch
    This will send this address to the PS3 controller when connected. All you need to do is replace the hex digits after the “0x”. Make sure not to fat-finger it.

    Step 3.
    Remove the BT adapter and plug USB in the PS3 controller to the USB host port or your arduino setup. USB is hot swappable but you can remove power first if you like.

    Step 4.
    Reboot (or boot) your arduino. The modified code will send that address to the PS3 controller so that the controller can initiate the connection to the adapter. This is a similar process to how you pair a controller to a PS3.

    Step 5.
    Remove the USB cable from the PS3 controller to the arduino and plug your BT adapter back in.

    Step 6.
    Reboot/boot your arduino.

    Step 7.
    If it’s going to work, it should work. I think the PlayStation button initiates the pairing. You might see all the LEDs flash at once for a bit while it gets started.

    So I fat fingered the Actiontec’s address and then switched to a different adapter. Since this works, I will use it. Maybe later I’ll try out the Actiontec again. or maybe on another project. This adapter is also much smaller and more convenient to use.

    I did send an email to Cirago, the manufacturer, since their site/page/manual didn’t include spec’s for the radio and I was ignored.

  • jonscibelli

    What should I change the MAC address to to connect the controller? After going through the process, the controller’s LED’s don’t even blink, as if it never even found the MAC address to the Bluetooth dongle.

    Also, should I comment out the “PS3BT PS3(&Btd); // This will just create the instance” and use “//PS3BT PS3(&Btd,0×00,0×15,0×83,0x3D,0x0A,0×56); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch”? I tried it, and it still never worked. Just wanted to know if I was doing something wrong.

  • Andrei

    Is it possible to connect two PS3 controllers to the same dongle on a android board?
    Should the code be modified to achieve that?

  • Vasilya

    I have ardurino mega ADK and ı have a bluetooth dongle, I pulged it in usb port of mega adk.
    I am using bluetoothhostshield 2.0. When ı open ardurino peers with computer. Computer opens a port for it. When ı search bluetooth devices ı can see ardurinos bluetooth signal. Here is the problem: when ı connectted pc and ardurino ver bluetooth ı cant send or recive anything over port. My port data sender sowftware freeses when ı try to send data, how can ı solve this problem? everything works fine but ı cannot cominicate :/ pls hellllllppp :( (

    • What OS are you using? Windows, Mac, Linux etc.

      • Vasilya

        windows 7 home premium..

          • Vasilya

            ı did all them many time, when ı try to connect to out port its succesfull but when ıtry to send signal vith it it freezes. program works fine with ardurino on usb cable means program has no problem.

          • Vasilya

            I fıgure out something:

            When I pair my pc and ardurino it is freezing but after one minute, ı get the “hello from ardurio” message. (spp example of the libary sends this message when connection sucsecfull).

            Every time I try to connect it taked exactly 1 minute. (time is between :entering paskey time – message time)

            Now tell me why cant I still send anything :S

          • That sounds strange. Is it exactly one minute?
            Could you try it on a different Windows machine and tell me if it works?

          • Vasilya

            ı tried it on xp and 7 and it always took 60 seconds to be get normal :) but still cant send message.

          • @Vasilya
            Try to remove these lines: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L314-L315 og https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L318
            Maybe your dongle doesn’t return the poll time correctly, but remember to add a delay in your main loop – for instance delay(1).

            @Caner
            Try to uncomment these lines and post the output again: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L20 and https://github.com/felis/USB_Host_Shield_2.0/blob/master/SPP.cpp#L20. Are you using the example provided or your own code?

          • Caner

            vasilya is me too :) we are same people :) so you know my codes :) ı will try your suggestions and feedback :) thanx for your help :)

          • Caner

            all report :

            SPP Bluetooth Library Started
            BTD Init
            Addr: 01
            Endpoint descriptor:
            Length: 07
            Type: 05
            Address: 81
            Attributes: 03
            MaxPktSize: 0010
            Poll Intrv: 01
            Endpoint descriptor:
            Length: 07
            Type: 05
            Address: 82
            Attributes: 02
            MaxPktSize: 0040
            Poll Intrv: 00
            Endpoint descriptor:
            Length: 07
            Type: 05
            Address: 02
            Attributes: 02
            MaxPktSize: 0040
            Poll Intrv: 00
            Bluetooth Dongle Initialized
            HCI Reset complete
            Local Bluetooth Address: 00:1F:81:00:08:30
            The name is set to: Arduino
            Wait For Incoming Connection Request
            Incoming Connection Request
            Remote Name: CANER
            HCI event error: 06
            HCI event error: 06
            Connected to Device: 0C:60:76:E7:E3:00
            L2CAP Connection Request – PSM: 00 01 SCID: 00 40 Identifier: 01
            SDP Incoming Connection Request
            SDP Configuration Request
            SDP Successfully Configured
            Disconnected SDP Channel
            L2CAP Connection Request – PSM: 00 03 SCID: 00 41 Identifier: 04
            RFCOMM Incoming Connection Request
            RFCOMM Configuration Request
            RFCOMM Successfully Configured
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: 2F PF_BIT: 10
            Received SABM Command – RFCOMM Data: 3 73 1 D7
            Received Key Request
            Wait For Incoming Connection Request
            Bluetooth pin is set too: 1234
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Received UIH Parameter Negotiation Command – RFCOMM Data: 1 EF 15 81 11 2 E0 0 0 40 0 0 0 AA
            RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: 2F PF_BIT: 10
            Received SABM Command – RFCOMM Data: B 73 1 92
            L2CAP Connection Request – PSM: 00 01 SCID: 00 42 Identifier: 06
            SDP Incoming Connection Request
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Send UIH Modem Status Response – RFCOMM Data: 1 EF 9 E1 5 B 8C AA
            Send UIH Modem Status Command – RFCOMM Data: 1 EF 9 E3 5 B 8D AA
            SDP Configuration Request
            SDP Successfully Configured
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Send UIH Modem Status Response – RFCOMM Data: 1 EF 9 E1 5 B 8D AA
            Send UIH Modem Status Command – RFCOMM Data: 1 EF 9 E3 5 B 8D AA
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Send UIH Command with credit – RFCOMM Credit Data: 9 FF 1 64 5C
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Send UIH Modem Status Response – RFCOMM Data: 1 EF 9 E1 5 B 5 AA
            Send UIH Modem Status Command – RFCOMM Data: 1 EF 9 E3 5 B 8D AA
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            Received UIH Remote Port Negotiation Command – RFCOMM Data: 1 EF 15 91 11 B 7 0 0 0 0 1 0 AA
            RFCOMM Connection is now established

            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            RFCOMM Channel: 0 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
            RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 10
            RFCOMM Data Available: 0 – Credit: 0x1A
            Disconnected SDP Channel
            Disconnected RFCOMM Channel
            HCI Disconnected from Device
            Wait For Incoming Connection Request

          • Everything seems alright, but for some reason you computer disconnect both channels just after they are established!
            Could you a different computer?

  • Vasiya

    windows 7 home premium

  • Alvidroid

    Hi,

    I followed all the steps but I cant connect the PS3 controller… both the dongle and the PS3 blink blink blink but they never pair…

    I also followed the instructions to uncomment those lines to get more detailed debug data and uploaded again to Arduino but the result is the same… no more debug…

    When I connect arduino I get:
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request

    As soon as I press the button in PS3 controller I get:
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request
    Incoming Connection Request

    but nothing happens and after a while the PS3 controller disconnects

    Help would be highly appreciated!

    Thank you!

    P.S. I tried already 2 PS3 COntrollers but the result is the same… if I connect the BT dongle directly on the PC the PS3 controller is detected but cant pair (i think this is expected in windows). If i try to connect my phone it works just fine. My PS3 controllers are original.

    • Try to change this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L852 to 0×01 instead. If that doesn’t work then your dongle isn’t working correctly. You will have to try a different one :)

    • I got the same symptoms for the hanging on “Incoming Connection Request”. Here is my verbose output:

      PS3 Bluetooth Library Started
      BTD Init
      Addr: 01
      Endpoint descriptor:
      Length: 07
      Type: 05
      Address: 81
      Attributes: 03
      MaxPktSize: 0010
      Poll Intrv: 01
      Endpoint descriptor:
      Length: 07
      Type: 05
      Address: 82
      Attributes: 02
      MaxPktSize: 0040
      Poll Intrv: 00
      Endpoint descriptor:
      Length: 07
      Type: 05
      Address: 02
      Attributes: 02
      MaxPktSize: 0040
      Poll Intrv: 00
      Bluetooth Dongle Initialized
      HCI Reset complete
      Write class of device
      Local Bluetooth Address: 00:1F:81:00:02:50
      Wait For Incoming Connection Request
      Class of device: 00 05 08
      Incoming Connection Request
      HCI event error: 06
      HCI event error: 06
      HCI event error: 06
      HCI event error: 06
      Connection Failed
      Wait For Incoming Connection Request

Leave a Reply

  

  

  



You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">