Shopping Cart

Posts

Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!

Compatible Bluetooth Dongles

Compatible Bluetooth Dongles

[EDIT] Here is Kristian’s post with more detailed explanation of the example sketch.[/EDIT]

Kristian Lauszus from TKJ Electronics, a man behind PS3 and Xbox360 code in USB Host Shield 2.0 library did it again! I’m pleased to announce that the library now supports standard RFCOMM/SPP implementation, thanks to Kristian’s work.

RFCOMM is basic Bluetooth service and SPP is serial port emulator on top of this. The code allows interfacing standard USB Bluetooth dongles to Arduino boards using USB Host Shield v.2.0. Bluetooth dongles (the ones I’ve tested can be seen on a title picture ) are widely available, cost much less than specialized serial Bluetooth modules (I have a couple of powerful class 1 dongles bought on eBay for $1 shipped) and won’t occupy precious serial port on Arduino board. Even though most dongles are compatible with the code, there are also some that don’t work. The code has been tested for compatibility with all major OSes – Linux, MacOS and Windows 7, as well as Android devices. It will likely work with any RFCOMM client, however, more testing is necessary.

The example code is a simple SPP server. It needs to be started before attempting to connect to it from a PC/phone. Once started, the state of the server is printed on a terminal. After that, the device can be discovered/paired/connected to; it is then possible to send characters from one device to the other by means of a keyboard. In the coming days I will write a series of posts with details of connecting different Bluetooth devices to Arduino. In the mean time, enjoy the code! Please give it a try and let me know what you think.

Oleg.

Related posts:

  1. Mass Storage Support for USB Host Library 2.0 released!
  2. Bluetooth code for Arduino USB Host
  3. USB Host Shield library Version 2.0 released.
  4. Sony PS3 Controller support added to USB Host library
  5. Wireless Xbox360 controller support for USB Host 2.0 library
  6. Arduino 1.0-compatible USB Host Library released
  7. Using USB Bluetooth dongle on Arduino to connect to Windows PC
  8. Google Open Accessory Interface for USB Host Shield Library 2.0 released
  9. Using USB Bluetooth dongle on Arduino to connect to Android phone
  10. USGlobalsat ND-100S GPS receiver works with USB Host library

88 comments to Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!

  • Oleg, Kristian, marvellous. This is exactly what I was waiting for.

    I’m having some issues to get it to work over here, though. I understand you are still working on the PC matters, so I’ll focus on Android. I’m on Gingerbread with a Galaxy S, and when trying to communicate using Blueterm I’m getting:

    Wait For Incoming Connection Request
    Incoming Request
    Remote Name: GalaxyS
    Connected to Device: 00:07:AB:04:AC:50
    Information request
    Scan Disabled
    L2CAP Connection Request – PSM: 00 01 SCID: 00 48 Identifier: 03
    SDP Incoming Connection Request
    SDP Configuration Request
    SDP Successfully Configured
    Disconnected SDP Channel
    L2CAP Connection Request – PSM: 00 03 SCID: 00 49 Identifier: 06
    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
    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
    Received Key Request
    Bluetooth pin is set too: 1234
    RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: 2F PF_BIT: 10
    Received SABM Command – RFCOMM Data: B 73 1 92
    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 FF 5C
    RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 10
    Unsupported RFCOMM Data – ChannelType: EF Command: 03
    RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
    Unsupported RFCOMM Data – ChannelType: EF Command: 67
    RFCOMM Channel: 1 Direction: 0 CommandResponse: 1 ChannelType: EF PF_BIT: 0
    Unsupported RFCOMM Data – ChannelType: EF Command: 68

    This is after entering the PIN in Blueterm and then typing the three characters fgh.

    So it seems that with my setup Android is not sending the UIH Remote Port Negotiation Command that you are expecting before completing the connection setup and starting the data exchange?

    I’m eager to resolve this (or at least to help resolving it). Would you mind contacting me on oleg at s dot wangnick dot de so as not to spoil this blog?

    Kind regards,
    Sebastian

  • Try to move these two lines: https://github.com/felis/USB_Host_Shield_2.0/blob/master/RFCOMM.cpp#L852-853 after this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/RFCOMM.cpp#L846. That should solve your problem.
    I will try to do the same thing with my setup tonight and then maybe push the changes to github.
    The problem is that your device never sends the “UIH Command with credit”.
    I actually don’t wait for the UIH Remote Port Negotiation Command as I also discovered that some devices does not send it. See this line for more information: https://github.com/felis/USB_Host_Shield_2.0/blob/master/RFCOMM.cpp#L902-909

    Regards
    Lauszus

  • Ron tay

    hi ,i want to control my servo motor using bluetooth dongle. but im bery new to arduino code.

  • Ron tay

    hi lauszus,
    thank for ur help i already able to control my servo motor via using usb .now the problem im having is i required to use bluetooth.i already tested using ur rfcomm module and the bluetooth is working fine.but i need combine the code with ur rfcomm code but it can’t compile.can u help me please.

  • Ron tay

    hi lauszus,
    it can be compile alr but is not working. maybe i send u my code and hope u can give me a way to combine my code and ur code .

    i really appreciate alot for ur help.
    thanks.

    char val[4];
    int pin1 = 22;
    int pin2 = 24;
    int pin3 = 26;
    int pin4 = 28;
    int pin5 = 30;
    int pin6 = 32;
    int index = 0;

    void setup()
    {
    pinMode(pin1, OUTPUT);
    pinMode(pin2, OUTPUT);
    pinMode(pin3, OUTPUT);
    pinMode(pin4, OUTPUT);
    pinMode(pin5, OUTPUT);
    pinMode(pin6, OUTPUT);
    Serial.begin(9600);
    }

    void loop()
    {
    if(Serial.available()){
    if(index < 3){
    val[index] = Serial.read();
    Serial.print(val[index]);
    index++;
    }

    val[index] = '';

    Serial.println("");

    if(index == 3){
    if(strcmp("p11", val) == 0){
    digitalWrite(pin1, HIGH);
    }
    else if(strcmp("p10", val) == 0){
    digitalWrite(pin1, LOW);
    }
    else if(strcmp("p21", val) == 0){
    digitalWrite(pin2, HIGH);
    }
    else if(strcmp("p20", val) == 0){
    digitalWrite(pin2, LOW);
    }
    else if(strcmp("p31", val) == 0){
    digitalWrite(pin3, HIGH);
    }
    else if(strcmp("p30", val) == 0){
    digitalWrite(pin3, LOW);
    }
    else if(strcmp("p41", val) == 0){
    digitalWrite(pin4, HIGH);
    }
    else if(strcmp("p40", val) == 0){
    digitalWrite(pin4, LOW);
    }
    else if(strcmp("p51", val) == 0){
    digitalWrite(pin5, HIGH);
    }
    else if(strcmp("p50", val) == 0){
    digitalWrite(pin5, LOW);
    }
    else if(strcmp("p61", val) == 0){
    digitalWrite(pin6, HIGH);
    }
    else if(strcmp("p60", val) == 0){
    digitalWrite(pin6, LOW);
    }
    else if(strcmp("ar1", val) == 0){
    digitalWrite(pin1, HIGH);
    digitalWrite(pin2, HIGH);
    digitalWrite(pin3, HIGH);

    }
    else if(strcmp("ar0", val) == 0){
    digitalWrite(pin1, LOW);
    digitalWrite(pin2, LOW);
    digitalWrite(pin3, LOW);

    }
    else if(strcmp("ag1", val) == 0){
    digitalWrite(pin4, HIGH);
    digitalWrite(pin5, HIGH);
    digitalWrite(pin6, HIGH);

    }
    else if(strcmp("ag0", val) == 0){
    digitalWrite(pin4, LOW);
    digitalWrite(pin5, LOW);
    digitalWrite(pin6, LOW);

    }

    index = 0;
    }
    }
    }

  • Behzad

    Hi,
    The example code link isn’t correct. I need it.

  • Vince

    Hi,
    Great work! This would be the first thing that I would try after getting hands on the USB host shield. :)
    One question though, is it possible that HID profile for BT dongles would be added in the future?

  • Ron tay

    hi lauszus,
    thanks alot alot for ue help.
    i had try the code but it can’t detect the dongle with the code u do for me.but if i try using spp example code it can detect the dongle! may i know why does it happen?

    thanks alot anyway.

  • Ron tay

    hi lauszus,
    there is no error just that the debug msg show osc did not start.but when i just upload the bluetooth spp example it is able to load the bluetooth etc. is working .
    my project is just to light up a led using an android phone using bluetooth that all is there any other solution?

    thank lauszus for ur effort and help.

  • Ron tay

    hi lauszus,
    sorry to trouble you.im using a uno board with a usb host shield (sparkfun) .

    • Have you remembered to connect a wire between pin 7 and the reset pin. If it’s still not working try to connect a external power supply. You are not using any of the pins from 7-13 right?
      Maybe the issue could be that you define pins above 13 as output ports! Try to change the pins to something like 2,3,4,5, and 6 and see if that works.

  • Ron tay

    hi lauszus,
    thank you for ur help. the code u send me i had try compile . however it is not working,i cannnot enable the bluetooth dongle. may i know where did i do wrong?

    • Please describe your problem in more detail. Try to connect a external power supply to your Arduino. The Sparkfun shield has a power issue when it’s running from USB, since it’s need more than 5V at the VIN for it’s onboard regulator.

  • Kabir

    Hi Lauszus,

    I tried to interface a Mega ADK(reqd. changes made in avrpins.h) to a cheap bluetooth dongle and it seems to initialize it fine with this message in the terminal :

    SPP Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Local Bluetooth Address: 00:19:86:00:29:1A
    The name is set to: Arduino
    Wait For Incoming Connection Request

    But, no devices can find it – tried it with a HTC Flyer p510e, Nokia 6300, Motorola RaZr v3m.
    A point to note here is that whenever one of the devices finish their search (but fail to find it)the LED on the dongle blinks once.

    Dongle details(not much):
    HCI version : 3.12288
    LMP version : 3.16907
    chipset : BCM 2045

    Other features of the USB Host library work.

    Thanks for the help,
    Kabir

  • rgm

    Can the USB host library be used to make a Bluetooth dongle act as a Bluetooth HID device?

    • What do you mean. For instance to make the Arduino show up as a Bluetooth joystick? Then the answer is no. Right now it only supports the PS3, Wiimote, Nunchuck, Motion Plus via Bluetooth and also the SPP protocol.

  • Great and huge effort indeed.
    I just get my new Arduino De, and I want to know the feasibility to use this code on it, making use of the two USB ports.

  • Chuck

    Wow – the shield and usb bluetooth sketch work great! I took a ps3 controller and a demo using a broken printer carriage controller to work and everyone enjoyed making it move it back and forth by remote control. ;)

  • Kapil Saraswat

    Hi! this is very informative. I have Arduino Mega2560 ADK. How can I use usb bluetooth and pendrive interface with it. Is this library can be used for the same? may you send me the example that is implemented on MEGA 2560 ADK.

    Thaks.

  • Kapil Saraswat

    Thanks, The solution is here!! I forget to comment the line. Now, may I know how can I communicate arduino (with bluetooth) with computer or mobile phone? Thanks for this library.

  • Frederik Juul

    Hello! Would it be possible to make this SPP Class inherit from the Stream library? It would make sense, I think, and make the problem I’m working with currently much, much easier :)

      • Frederik Juul

        I’ve implemented an XML-parser, which is currently able to take any stream, parse the received data and react accordingly. By using stream it is possible for me to code without considering wether the input is ethernet or serial or anything else. I’d like to be able to use the Bluetooth communication in the same way, so it can just check if it receives any XML-commands on any of the communication lines, and run the same code for all of it, regardless of source.

        • Frederik Juul

          I’ve modified the library a bit, and it seems I’ve got it running with the Stream class implemented :) I’m working on some of the kinks I’m currently experiencing, but that seems to be more related to the way that I handle the connection afterwards, than the connection itself.

          • Nice. Can I have a look at the code? :) Btw are you danish as well?

          • Frederik Juul

            I’m danish as well, yes :)

            It’s pretty much just implementing the virtual functions from the Stream class (which included changing some of the functions from uint8 to int and returning -1 instead of 0 for empty):

            class SPP : public BluetoothService, public Stream {

            int available();

            int read();

            int peek();

            void flush();

            size_t write(uint8_t);
            }

            The “tricky” part was recognizing that the Stream class is implementing the Print class, which required the write method to be present. I implemented that as simply:
            write(uint8_t c){
            print(c);
            }

            I’ll see about uploading it at some point, when I’ve made sure that it’s not gonna fuck something up :)

            Sorry if my language is a little bit off – It’s been a while since i dabbled with inheritance and polymorphism and all those object-oriented things :)

          • Okay super, but does it send the characters as one large string or send them individually?

          • Frederik Juul

            It would seem that it sends them individually – Is this a problem? It could probably be implemented to start a timer when “the first” char is received and then wait a given time before sending, to allow for sending a larger string.

          • Yes it’s problem if you just keep sending data through the output endpoint. You will have to call Usb.Task() once and a while to read the input endpoint too. That’s why I implemented my own functions in the first place.
            I have also thought about putting it all into a buffer and then when Usb.Task() is called it will both read the input endpoint and also send the buffer through the output endpoint.

          • Frederik Juul

            I’m not completely sure I understand the problem or the solution. Is it correctly understood that the problem is, that if you keep spamming the output-endpoint with data, you will block the code and potentially never reach the Usb.Task() – Atleast not before a problem with buffersize or timing or something could arise.

            I also have a small problem with some sort of internal buffer. When ever I try sending a longer command, the buffer caps out at 63 characters, and then either replaces or appends “PB” at the end of the buffer. When I run the Usb.Task() again, shortly after, the rest of the message is still received and appended to the buffer. I can recreate this bug running just the basics of the Bluetooth communication.

          • Yes exactly. What will happen is that the dongle will stop responding and you will just get this error message over and over again: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L1029-L1039 and you will have to reset the dongle for it to work again.

  • Frederik Juul

    I’ve done a little bit of digging regarding my problem with the buffer size of 63. It is actually the last 10 or so bytes that are a problem. I get the following byte sequence when I try to read a long message from the buffer:
    0×7 0xXX 0×4 0×0 0×50 0×0 0×42 0×0 0×0 0×0 0×1

    Where XX is a number increasing by 9(DEC) every time i disconnected and reconnect my bluetooth connection. The 0×50 and 0×42 are the P and B i was talking about. And as I said, this is what I get when I try to read a message from the buffer.

    I’m thinking that some pointer somewhere is clashing with something, since theres a variable thats obviously changing whenever I reconnect. This is weird :)
    Can you reproduce the problem? The code is here: http://pastebin.com/Re7aCdrP
    I usually send 01234567890123456789012345678901234567890123456789012345678901234567890123456789 to test the communication.

    • Frederik Juul

      Okay, I’m a little bit sorry that I’m using this as kinda my personal development log, but I think I’ve found the problem. Or if nothing else, a solution to the problem. I found that the LSB of the max-buffer size was set to 64, which kinda matches with the problem I had. I tried setting it larger, but that just gave me a larger error. Instead, i tried setting it smaller, to 53 to be exact, so that my actual, uncorrupted data could fit in. That worked. I can now receive and process data as i want it, without issue.

      What i specifically changed was line 287 in SPP.cpp. I changed it to:

      rfcommbuf[6] = 0×35; // Max Fram Size LSB – we will just set this to 64

      So from 0×40 to 0×35. Now it works :)

  • Sab

    Hey there,

    You mentioned some of the dongles are incompatible with the board. How do I find out if a particular dongle will work or not without plugging it into the shield.

  • Sab

    Well , currently I am on windows 7 . Which software do you recommend for that?

  • xenonforlife

    Hi,

    I am a beginner at developing with Arduino. Infact this is my first time. So please don’t mind if this is a noob question. I have an Arduino Mega ADK rev3 which has an inbuilt usb port with which I can connect my Android phone. This is means I do not need a USB Host Shield to do the same. However what I want to know is, can/should I still need to use the USB HOST Shield 2.0 library if I want to establish a communication between my board and my android device? I am a bit confused here. Could you please help me with this basic understanding?

    Thanks

  • xenonforlife

    My mistake I asked an already answered query, I will try uncommenting the line in your code and work with my board. Thanks

  • xenonforlife

    Hi Lauszus,

    This is what I want to achieve. I have a separate circuit where I blink an Led with a particular sequence. This sequence represents encoded data. I want to be able to sense this pattern with a photo detector and decode the data from the led blink, and then I want to send this decoded data via bluetooth to my android device. I am a newbie to programming on a board, however I have programmed on Android. Do you think it is possible to achieve what I want with an Arduino. I have ordered the board, but they have still not delivered it. So I am still in the learning phase of my project, contemplating the problems I might run into. Do you think it is a better idea to collate and decode the entire data on the board itself and send it to the android in one go is a better idea? or should I send the information on the fly from the sensor to the android device and decode it in my Android code..please help!

  • xenonforlife

    Hi,
    I am using a dongle and it shows up the following messages in the serial monitor when i burn the SPP sketch on the board :

    SPP Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:15:83:0C:BF:EB
    The name is set to: Arduino
    Wait For Incoming Connection Request

    I can see the device on my Nexus7 and am trying to use Blueterm and when I tryin to connect the following line appears on the Serial Monitor :

    Incoming Connection Request
    Remote Name: Nexus 7

    But still the connection is not made possible. I cannot pair with the device. Could you tell me if I doing something wrong?

    Thanks

  • xenonforlife

    Hi Thanks Lauszus..for your help…however I did figure out the issue in the other forum…its because of the Android version. I tried on Gingerbread and it worked like a charm! I would like to contribute another very cheap working dongles in the list of “working dongles”. It is helpful for enthusiasts in Europe as this one ships to Europe as well, the others in the list don’t(or are expensive). I would be really glad if you include this one in the list as well. Here is the link http://www.ebay.de/itm/261173305309?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
    Hope it helps someone.

  • xenonforlife

    Hi Lauszus,

    I have completed my project but the only problem is that it works only on gingerbread or earlier. It does not show up on my 4.2(Nexus 7) and also not on the recent 4.3(Galaxy Nexus). The device does not show up on the Available devices screen. Do I need to do something special with it? This could not be a dongle issue right?

    Thanks

  • xenonforlife

    Hi,
    I tried the newest libraries and it the dongle started to show up (previously it wasn’t visible to my Android device) on new Android versions. But now I cannot connect to it due to some reason. It shows ‘connecting…’ but after a while I see a message ‘Unable to connect’. Do you know what might be the reason? Also, with the previous library I could see a lot of information on the Serial port but now I just see SPP bluetooth library started. What do I need to do to see the information that

  • xenonforlife

    Ahh thanks for your reply Lauszus, I was really looking forward to hearing from you, this is a great library and has made my project so so much better.
    I have modified the bluetooth chat app a bit and made it to work with the board and I can confirm that yes it works pretty well with all versions of Android now. Thanks for the support however.
    But now I have a very interesting observation
    I just posted a problem at this page http://www.circuitsathome.com/mcu/using-usb-bluetooth-dongle-on-arduino-to-connect-to-android-phone/comment-page-1#comment-22540. I am losing the connection to the bluetooth dongle somehow after a while, and I do not understand why. It seems like my Arduino is just sending a fixed number of bytes and then it just gives up and device connection is lost. Have you faced a similar issue sometime or have an idea when can this happen. Could this be a dongle issue as well?

    • xenonforlife

      I have tested it with Blueterm as well and gives me the same result everytime. after a while device connection is lost.

      • No I haven’t experienced anything like that. Could you please try my app: https://play.google.com/store/apps/details?id=com.tkjelectronics.balanduino and see if that works? If it’s not working, then you will have to try another dongle.

        • xenonforlife

          I tried your Baladuino app and I do not see any disconnections with my Android device, the sketch on the Arduino on both cases remains the same however when I use Blueterm I see the same problem. The thing here is I am receiving data from Serial1 of my MegaADK board and am transmitting the same via bluetooth to my Android and something is going wrong there and I can’t understand what because the dongle is somehow restarting. You can see the Arduino sketch here:
          http://pastebin.com/w5k7HNZq

          and I am also placing the debug output for your reference in case you understand what is going on, its not the program resets but the bluetooth dongle is getting initialized again and again:

          SPP Bluetooth Library Started
          Bluetooth Dongle Initialized
          No response to HCI Reset
          HCI Reset complete
          Write class of device
          Local Bluetooth Address: 00:15:83:4A:2E:6B
          The name is set to: Arduino
          Wait For Incoming Connection Request
          Incoming Connection Request
          Remote Name: Galaxy Nexus
          Connected to Device: B0:EC:71:7E:21:8D
          Wait For Incoming Connection Request
          SDP Incoming Connection Request
          SDP Configuration Request
          SDP Successfully Configured
          Disconnected SDP Channel
          RFCOMM Incoming Connection Request
          RFCOMM Configuration Request
          RFCOMM Successfully Configured
          Received SABM Command
          Received UIH Parameter Negotiation Command
          Received Key Request
          Bluetooth pin is set too: 1234
          SDP Incoming Connection Request
          Received SABM Command
          SDP Configuration Request
          SDP Successfully Configured
          Send UIH Modem Status Response
          Send UIH Modem Status Command
          Send UIH Command with credit
          Disconnected SDP Channel
          SDP Incoming Connection Request
          RFCOMM Connection is now established – Automatic

          SDP Configuration Request
          SDP Successfully Configured
          Disconnected SDP Channel
          Bluetooth Dongle Initialized
          No response to HCI Reset
          No response to HCI Reset
          No response to HCI Reset
          HCI Reset complete
          Write class of device
          Local Bluetooth Address: 00:15:83:4A:2E:6B
          The name is set to: Arduino
          Wait For Incoming Connection Request

  • Giorgio

    Bluetooth RFCOMM/SPP:
    Hello Kristian, I too would like to control a servo motor with a dongleBT and my PC. You can send me a link with some sample code?

  • Giorgio

    But, how can I send a signal from my PC (with windows8) via Bluetooth? I can use PUTTY??Or I can use processing?

  • Jae

    Hi~

    I used USB Host Shield 2.0 to my Arduino MEGA ADK with a USB bluetooth dongle and a sensor(ADS1298). And the code usually works fine.
    But if the bluetooth using SPP sends data quickly, the board is die.

    the following code is simplified my loop function. It works though, I don’t want to use a delay(10) function because of sampling rate of a sensor. When the delay function is removed, the SPP is die after sending little data or nothing.

    May you help me?

    ——-
    void loop() {
    Usb.Task();

    if (SerialBT.connected) {
    if (firstMessage) {
    firstMessage = false;
    SerialBT.println(F(“Hello from ECG SB”)); // Send welcome message
    }

    SerialBT.write(getSensor(),31);

    delay(10);
    }
    else
    firstMessage = true;
    }
    ———-

    • Could you try to post your getSensor() function as well.
      Please also enable serial debbugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging, so I can see the error message. Please also uncomment the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L20.

      • Jae

        I’m sorry for the late reply.

        A following is debug message when I enable on debug option.

        —————————————————————–

        SPP Bluetooth Library Started
        BTD ConfigureDevice
        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: 02
        Attributes: 02
        MaxPktSize: 0040
        Poll Intrv: 01
        Endpoint descriptor:
        Length: 07
        Type: 05
        Address: 82
        Attributes: 02
        MaxPktSize: 0040
        Poll Intrv: 01
        Bluetooth Dongle Initialized
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        Connection established
        HCI Reset complete
        Unmanaged HCI Event: 24
        Write class of device
        Local Bluetooth Address: 00:09:DD:50:8D:D4
        The name is set to: ECG SB
        Wait For Incoming Connection Request
        Class of device: 5A 02 0C
        Incoming Connection Request
        Remote Name: LG-F180K
        Connection established
        Connected to Device: 10:68:3F:30:AF:61
        Wait For Incoming Connection Request
        SDP Incoming Connection Request
        SDP Configuration Request
        SDP Successfully Configured
        Received Key Request
        Bluetooth pin is set too: 0000
        Disconnected SDP Channel
        RFCOMM Incoming Connection Request
        RFCOMM Configuration Request
        RFCOMM Successfully Configured
        Received SABM Command
        Received UIH Parameter Negotiation Command
        Received SABM Command
        Send UIH Modem Status Response
        Send UIH Modem Status Command
        Send UIH Command with credit
        Received UIH Command with credit
        RFCOMM Connection is now established – Automatic
        [go]C00000800000800000800000800000800000800000800000800000[on]
        [go]C00000800000800000800000800000800000800000800000800000[on]
        [go]C00000800000800000800000800000800000800000800000800000[on]

        [go]C00000800000800000800000800000800000800000800000800000[on]
        [go]C00000800000800000800000800000800000800000800000800000[on]
        [go]C00000800000800000800000800000800000800000800000800000[on]

        HCI event error: 0E
        ACL data in error: 0E
        Error sending L2CAP message: 0x0E – Channel ID: 00 41

  • andwicf

    Hello Lauszus

    sorry for my bad english

    i have usb bluetooth dongle. i will use for in Beaglebone Black (Archlinux). i have installed Bluez and i can use pair into my smartphone (but i dont know passkey, i try 0000 and 1234, it is wrong).i have many question for you

    1.is every usb bluetooth dongle can use rfcomm protocol??
    2.when i see my pc (ubuntu 13.04),in /etc/bluetooth there are have rfcomm.conf. but in my Beaglebone black (archlinux) there are not have rfcomm.conf, can i copy rfcomm.conf file to Beaglebone black??
    3.how to set passkey for my bluetooth dongle??
    4.how to check usb bluetooth support rfcomm??

  • Timbo

    Hi Oleg and Lauszus,

    I was hoping you can offer some advise as I try to understand my best option and approach for my situation. Oleg, you might have heard some of this in some personal correspondence.

    My challenge is: I have a laser that provides a USB device interface, i.e. through a Type A USB plug. I need to adapt a wireless interface for the laser, which has <3Mbps throughput. A wifi adapter is my best option but I need to establish sufficiently high enough bandwidth path between USB device plug and wifi module to support my operation.

    The wireless adapter supports SPI, which is my best option to interface. I have both a full-size and mini USB Host shield from circuits@home. I have numerous options for cpu control of the host shield and wifi adapter, e.g. teensy 3.1, several *duinos, etc. or I'll get what I need.

    I've spent a lot of time working on a solution using an FTDI VNC1l (USB Host) but unfortunately the firmware is flaky, but no source available, and then their VNC2 has source but no CDC support–a big waste of time. And so, I'm looking for another chip to help. I'm new to MAX3421E and there's no embedded firmware like the FTDI product. I would appreciate some help understanding, in the case of this chip, what it does vs the code in the library, and the various ways to use it.

    I saw bits and pieces of what I might need as I read this blog, I think. The laser presents a CDC profile. I think I read that the USB BT dongle was a CDC device. This suggests the library used in the examples above leverage existing code required to handle the CDC profile. Am I right?

    If this library suits my need, can I expect to achieve the <3Mbps BW? If yes, Can it be done with a single SPI bus? Your thoughts would be appreciated.

    Thanks

  • Hitesh singh

    hey Lauszus,
    i am trying to create an app which will be connectd with spp barcode scanner over bluetooth . but in this i am not able to connect with spp device . so could you please help me .??

  • Sebastian

    Hi!

    Im using Arduino Mega ADK and i already enabled it in settings.h.
    I loaded the arduino code SPP.ino and it is running fine, but i cannot “see” the arduino as a visible device using a common Bluetooth client.
    In the main loop

    Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well

    if (SerialBT.connected) {
    if (firstMessage) {
    firstMessage = false;
    SerialBT.println(F(“Hello from Arduino”)); // Send welcome message
    }
    if (Serial.available())
    SerialBT.write(Serial.read());
    if (SerialBT.available())
    Serial.write(SerialBT.read());
    }else{
    delay(100);
    Serial.println(“No serial device connected! “);
    firstMessage = true;
    }

    this SerialBT.connected is always false and that makes sense because i had not connected any other device via bluetooth…I should do some extra work to connect with the arduino?

    I need to receive data from the Arduino from Processing as i already do with a common Serial port, so i think that SPP is what i need, isn’t is?

    Thanks you!

    • What devices have you tried. I have both used it with Windows, Linux, Mac and Android and all works fine.
      It could also be related to your dongle – please try a different one.

  • Doug

    I’m using the Arduino ADK with a Bluetooth dongle and connecting to it with an Android device running KitKat. I use a modified SPP example with the USB Host 2 library on the arduino and I am using a modified android Bluetooth chat example on the tablet. I am using it as a datalogger system (voltage, current, etc). Everything works great up until 65 minutes into the test when the Bluetooth stops transmitting data, but the connection is not lost, and I see hci_status=36 on the logcat. From what I gather, this is a Bluetooth sleep mode on android. I don’t need any power saving features as the tablet is always plugged in as part of this fixture. I have tried using a partial wake lock to prevent the tablet from sleeping, but to no avail. This fixture will run unattended for days at a time so I can’t reset the connection every 65 mins. Are you aware of a way to prevent this “sleep mode” or whatever it is. As a back up, I do have the direct usb version using the adk library, but Bluetooth is preferred.

    • Doug

      I suppose I should add that I send a data packet from android every 100ms and the arduino sends a response packet back. I read about a keep alive thread, but I would assume this constitutes an inherent keep alive.

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="">