Android and BLE

Hello All,

I am completely new to Android development but want to port my BLE application working well in PC environment to Android (we have droid Razr). We have CC2540 kit, I saw a demo here http://processors.wiki.ti.com/index.php/Category:MotoRAZRAndroidBLEDemo but that seems to be for CC2541, can I use it with CC2540 as well or do I need CC2541?

Can anyone give me a starting point where I need to start working on it please? A step by step guide to make BLE work with Android for a new person like me would be REALLY appreciated., 

Thanks so much!

-nh

  • Hello All,

    Can any one share any word on this please? 

    Thanks so much,

  • Hi,

    You can use that Android demo software as a base for your development, its not specific to CC2541. The interoperability in a BLE eco system allow you to connect to any BLE enabled device (Bluetooth SMART). What you can after connection is completely dependent on the Phone application. I suggest you go through the Android code and learn a bit of java syntax on the way and you should be able to figure it out. Another hot tip is to check out the Motorola dev forum. 

    I have not worked with either Android or Java myself so I cant give you any further help at this moment.

    Good Luck

    Br

  • In reply to Joakim Lindh:

    Hi Nick,

    My interest is to have a sort of application similar to Btool as a starting point., If I use the demo application in wiki with CC2540 keyfob, can I use any available project directly to check the functionality? I installed the baby monitor in razr and I see that there is a provision to read accelerometer data via activity sensor., Can anyone who has worked with these kindly guide me please?

    Thanks so much.,

    With best regards,

  • In reply to nagaraj hegde:

    Hi!

    To use the Baby Monitor demo with CC2540DK (with the KeyFobDemo app) you need to do the following:

    1. Apply the fix GregS suggests in http://e2e.ti.com/support/low_power_rf/f/538/p/161510/600673.aspx#600673 for the KeyFobDemo app (I'm not sure if it is included in the latest BLE stack, but if it is, it'll work without doing this).

    2. In BLESensorBoard.java: line 157
    - Change m_uuid from
    protected String m_uuid = "0000f0b0-0000-1000-8000-00805f9b34fb";
    to
    protected String m_uuid = "0000ffa0-0000-1000-8000-00805f9b34fb";

    This is to connect to the Accelerometer service on the KeyFob.



    3. Still in BLESensorBoard.java: line 406
    Comment out m_uuid = s[3];
            // m_uuid = s[3];

    The app originally tried to autodetect the UUID on the Sensor Tag. This makes no sense now that we know the UUID.

    4. In BLEAccelerometer.java: line 37
    Change from
            READ_HANDLE_INDEX = 2;
            CONF_HANDLE_INDEX = 3;
    to

            READ_HANDLE_INDEX = 2;
            CONF_HANDLE_INDEX = 0;

    The indices into the handle array is there to let the BLESensor subclasses know what handles to connect to. This is because the SensorTag FW had all the sensors under one primary service, which the KeyFob doesn't. So, the first handle in the accelerometer Primary Service is the enable/disable handle, and the third handle is the X coordinate.


    5. In BLEAccelerometer.java: line 59
    Change
                byte x = data[0];
                byte y = data[1];
                byte z = data[2];
    to             
                byte x = data[0];
                byte y = data[0];
                byte z = data[0];

    The Sensor Tag has the x, y and z values all at one handle, the KeyFob doesn't.. So, as a quick hack, just read the X value three times.

    Then, when you start the app, prior to connecting to the KeyFob, select the "Activity" sensor. When you connect, the Activity graph will be plotting changes in the X axes.

    Obviously, this is a bit of a hack. Due to a bug in the CC2541 SensorTag firmware at the time of writing the Razr demo, all the sensors are accessed from the same Primary Service. This is not the way the KeyFobDemo firmware is operating, so using this demo together with the KeyFobDemo can be a little bit awkward.

    Also note that you will only see values plotted when you actually move the keyfob, as it only gives notifications when it  is moved.

    I hope this helps!

    Best regards,

     - Tord Øygard

  • In reply to Tord Oygard:

    Thanks soooooooooo much Tord,

    I am very happy to get this info., Thanks again.,

    Regards,

    Nagaraj

  • In reply to nagaraj hegde:

    Tord,

    Should I make all the changes as told by Greg (including the ones in Android project) or just the one in Keyfob demo project?

    Thanks and best regards.

    Nagaraj Hegde

  • In reply to nagaraj hegde:

    I made the changes you made but not getting any acceleration plot in the Razr., One thing I am concerned is about the second part modifications as told by Greg in his post.,  I am not able to find those places in BLEDemo project.,

    Thanks and best regards,

    -Nagaraj 

  • In reply to nagaraj hegde:

    Hi Nagaraj,

    The changes proposed for the Android app by Greg is in general, not for the Baby monitor app. The changes I outlined makes sure the Baby Monitor app writes the right things to the right handles, so if you did what I posted, you can ignore the second part of his post.

    To the problem at hand:

    1. Before connecting, did you pair the phone with the keyfob? If you changed the firmware of the Keyfob, you have to re-pair, since the phone stores the GATT table locally.

    2. When starting the app, do this:

        1. Press the menu button, select sensor, activity

        2. Press the menu button again, connect, and pick the Keyfobdemo in the menu (if you just paired it, the name may be displayed as null, but that doesn't matter)

       3. Verify that the Bluetooth icon in the status bar on the top becomes blue. If it doesn't, press the right button on the Keyfob

       4. Wait ~30 seconds (until you see the "Enabling notifications for accelerometer" message), and start moving the Keyfob. You should see the activity graph being plotted now.

    Hope this helps!

    Best Regards

    - Tord Øygard

  • In reply to Tord Oygard:

    Hello Tord,

    Thanks again for the response., 

    1. Before connecting, did you pair the phone with the keyfob? If you changed the firmware of the Keyfob, you have to re-pair, since the phone stores the GATT table locally. 

    I did pair with the keyfob

    2. When starting the app, do this:

        1. Press the menu button, select sensor, activity

    did the same.,

        2. Press the menu button again, connect, and pick the Keyfobdemo in the menu (if you just paired it, the name may be displayed as null, but that doesn't matter)

     did the same.,

       3. Verify that the Bluetooth icon in the status bar on the top becomes blue. If it doesn't, press the right button on the Keyfob

    This never happens somehow!! What may be the reason?

       4. Wait ~30 seconds (until you see the "Enabling notifications for accelerometer" message), and start moving the Keyfob. You should see the activity graph being plotted now.

     I do see the above message but no plots get displayed.,

    Kindly let me know what should I do., 

    Thanks so much,

    Nagaraj

  • In reply to nagaraj hegde:

    Hi nagaraj,

    In my experience, the top reason for not getting connected is a dead battery. Try to replace the coin cell battery. If that doesn't work, please verify that you have the correct firmware on CC2540. Also, I'd advice you to take a look at the LogCat output from the app.

    Last but not least, restarting the bluetooth stack on the phone also helps some times. To do that, go to the phone wireless settings and uncheck/check the Bluetooth checkbox.

    Best regards,

    - Tord