TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: dbenwoods on March 08, 2015, 09:10:37 AM

Title: TinyScreen Smartwatch
Post by: dbenwoods on March 08, 2015, 09:10:37 AM
The answer to this is probably obvious - but I've never worked with Bluetooth or BLE - do I need to write an app for my smartphone to communicate with the TinyDuino (using the smartwatch kit)? Or is there a smartwatch app out there already>
Title: Re: TinyScreen Smartwatch
Post by: Ben Rose on March 09, 2015, 07:21:29 PM
We have an example Android app that just went up. It's currently available for testing at https://github.com/TinyCircuits/TinyCircuits-TinyScreen-Android-App

It shows how to connect and pass simple notification data- texts and incoming calls at the moment.

Our example watch code is available at https://codebender.cc/sketch:91833
Title: Re: TinyScreen Smartwatch
Post by: ainfield on March 14, 2015, 01:40:57 PM
I've just got the smart-watch kit for a school class, and I am having trouble pairing it with my i-phone. Does anyone know what i can do to help pair them, or should i just wait until there's another update on the website?
Title: Re: TinyScreen Smartwatch
Post by: jpencausse on March 16, 2015, 11:53:21 AM
@Ben can you provides a little bit more explanation ? (sorry i'm n00b)

Android:

I got the Android app running on Android Studio in Debug mode on my Nexus 5
The ScanActivity is running and see BLE devices but do not see the TinyDuino

- How the app should work (where to look/debug in the code) ?
- Where is performed the time update ?


Tinyduino:

The code is installde from codevender but not from Arduino IDE (it look for Time.h and TinyScreen.h)

The time is displayed, buttons works, but it is not sync with the phone
- I assume ble_rx_buffer is filled by BLEsetup() ?
- Where the TinyDuino id is sent to the phone ?

Thanks !
Title: Re: TinyScreen Smartwatch
Post by: Ben Rose on March 16, 2015, 05:58:20 PM
ainfield, we do not yet have an iPhone app, it's something we'll have but I don't know exactly when.

jpencausse, note that the name in the BLE advertisements which will show up in the app is URT, due to the Nordic virtual UART setup. The date/time update should happen automatically after a connection is made.

ble_rx_buffer is filled in aci_loop() when there is new data.

The name/ID is set through the Nordic setup code which needs to be generated with their software.

Hope this helps you get the demo working.
Title: Re: TinyScreen Smartwatch
Post by: jpencausse on March 16, 2015, 08:08:55 PM
Ok thanks understand

I didn't see URT in the scan I'll dig (other BLE device crash the app)

Whats shoud I do to make it work in Arduino IDE ? (It look for TinyScreen.h and Time.h may be I missed something)

Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 16, 2015, 10:28:34 PM
ainfield, we do not yet have an iPhone app, it's something we'll have but I don't know exactly when.
There's no TinyDuino app, but Nordic has one. https://itunes.apple.com/us/app/nrf-uart/id614594903?mt=8
That app will let you communicate directly over UART to the TinyDuino. If you look at the Android app you can find the commands you'd need to send so you can test and build your own iPhone app around it.

The name/ID is set through the Nordic setup code which needs to be generated with their software.
Do you have a link to the software we'd need to rename it? I'm not a personal fan of the URT name. ;)
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 16, 2015, 11:03:52 PM
If anyone would like the already compiled Android app to test without downloading the code and compiling it, the unmodified app is right here.

https://drive.google.com/file/d/0Bwvr66JlAk_7N21yQmNYbzJvZEk/view?usp=sharing
Title: Re: TinyScreen Smartwatch
Post by: Ben Rose on March 17, 2015, 07:02:50 PM
jpencausse, you need to download the Time library http://playground.arduino.cc/code/time and our TinyScreen library at https://github.com/TinyCircuits/TinyCircuits-TinyScreen_Lib and put them in your libraries folder.

WakeArray, thanks, and the software is at https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRFgo-Studio

You'll also need the Nordic's library at https://github.com/NordicSemiconductor/ble-sdk-arduino/releases

Open nRFgo Studio, click on nRF8001 Configuration, then open the xml file under the ble_uart_project_template in the library. You can change the advertising name under GAP settings. Then generate services.h and replace the old file in your sketch folder.

Overkill procedure for changing the name, but that's that. It looks like it's possible to change it during run time, but I can't find the function that sets the name. For now, I've just changed the CodeBender example to advertise as BLEWatch instead of URT, at least.
Title: Re: TinyScreen Smartwatch
Post by: amd599 on March 18, 2015, 09:52:44 AM
I'm not sure if I am missing something or not but I was able to load the TinyWatch code up just fine from the sample code on Codebender but I only see it showing the time which doesn't refresh until the screen shuts off and then when you turn it back on it shows the new time.

Is this the only feature?

ALso, I wasn't able to get it to show the time properly. It had January 1st and 00:00:00 - I saw something about sync'ing it with the android app to do it properly but the android app just keeps crashing on me. I tried the uART program on the iPhone and I was able to successfully connect but didn't know the hex codes or whatever was necessary to set the time properly.

It's a bummer it doesn't count the time in real time and the screen needs to go off and on again before showing the updated time.

Again, maybe I am missing something and there are a lot more features in the sample smart watch code so any help would be greatly appreciated.

Thanks.
Title: Re: TinyScreen Smartwatch
Post by: Ben Rose on March 18, 2015, 12:32:28 PM
The time doesn't tick over without a sync because of the "&& timeStatus()==timeSet" condition that is checked before updating the screen when it's on. Once it has been connected to the Android app or you remove that condition, it will update every second when the display is on until it shuts off after five seconds- you can change displayUpdateInterval and sleepTimeout if you don't like that.

If you can post more details about your Android phone and why the app is crashing, I can try to fix it. Once the app is connected, it will set the date/time and send basic text/phone call notifications to the watch. That's all the example does for now.
Title: Re: TinyScreen Smartwatch
Post by: amd599 on March 18, 2015, 05:59:30 PM
The time doesn't tick over without a sync because of the "&& timeStatus()==timeSet" condition that is checked before updating the screen when it's on. Once it has been connected to the Android app or you remove that condition, it will update every second when the display is on until it shuts off after five seconds- you can change displayUpdateInterval and sleepTimeout if you don't like that.

If you can post more details about your Android phone and why the app is crashing, I can try to fix it. Once the app is connected, it will set the date/time and send basic text/phone call notifications to the watch. That's all the example does for now.


Ah, OK. Gotcha. I'd like to get the Android app working. The phone is an Galaxy S II (SGH-T989).
Android version 4.1.2
Baseband Version: T989UVMC6
Kernel Version: 3.0.31-1003885
Build Number: Jz054k.t989uvmc6
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 18, 2015, 11:02:16 PM
Ah, OK. Gotcha. I'd like to get the Android app working. The phone is an Galaxy S II (SGH-T989).

Sadly even though the S2 shipped with a Broadcom chipset capable of bluetooth 4.0, it was never enabled in software. Part of this is because Android had no default support for Bluetooth 4.0 till nearly 2 years later and by that time the chipset was so outdated writing software to make it work was not a priority.

The S3 was the first Android phone with software support for 4.0 and it wasn't even widely used because Samsung had to make their own support for it, a support that was entirely different from Google's own implimention nearly a year later.

Edit: Turns out Broadcom wrote their own drivers for it and it can be used in Android 4.3(The version of Android that first supported bluetooth 4.0). Only downside is that you have to root and install a newer rom for it to work. From the sounds of it CM11 should support this.

TL;DR: To the best of my knowledge there's simply no easy way to make this work with the S2 without rooting.

Source: I worked for Best Buy selling phones for 4 years.
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 18, 2015, 11:14:56 PM
WakeArray, thanks, and the software is at https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRFgo-Studio

You'll also need the Nordic's library at https://github.com/NordicSemiconductor/ble-sdk-arduino/releases

Open nRFgo Studio, click on nRF8001 Configuration, then open the xml file under the ble_uart_project_template in the library. You can change the advertising name under GAP settings. Then generate services.h and replace the old file in your sketch folder.

Overkill procedure for changing the name, but that's that. It looks like it's possible to change it during run time, but I can't find the function that sets the name. For now, I've just changed the CodeBender example to advertise as BLEWatch instead of URT, at least.

Overkill or not, your help is appreciated. I'll have a look into it in the morning. :)
Title: Re: TinyScreen Smartwatch
Post by: amd599 on March 19, 2015, 10:27:09 AM
Ah, OK. Gotcha. I'd like to get the Android app working. The phone is an Galaxy S II (SGH-T989).

Sadly even though the S2 shipped with a Broadcom chipset capable of bluetooth 4.0, it was never enabled in software. Part of this is because Android had no default support for Bluetooth 4.0 till nearly 2 years later and by that time the chipset was so outdated writing software to make it work was not a priority.

The S3 was the first Android phone with software support for 4.0 and it wasn't even widely used because Samsung had to make their own support for it, a support that was entirely different from Google's own implimention nearly a year later.

Edit: Turns out Broadcom wrote their own drivers for it and it can be used in Android 4.3(The version of Android that first supported bluetooth 4.0). Only downside is that you have to root and install a newer rom for it to work. From the sounds of it CM11 should support this.

TL;DR: To the best of my knowledge there's simply no easy way to make this work with the S2 without rooting.

Source: I worked for Best Buy selling phones for 4 years.


OK. Thanks for this. I was able to get a brand new phone and the app launched. I saw BLEWatch but whenever I tried to connect it kept crashing. At the watch time is still incorrect but when I press a button on the side it now says "No Notifications" which it didn't say before.

I tried to send a text to the phone and see if it showed a notification but it still says no notifications even thought I got the text.
Title: Re: TinyScreen Smartwatch
Post by: amd599 on March 19, 2015, 10:44:00 AM
Ah, OK. Gotcha. I'd like to get the Android app working. The phone is an Galaxy S II (SGH-T989).

Sadly even though the S2 shipped with a Broadcom chipset capable of bluetooth 4.0, it was never enabled in software. Part of this is because Android had no default support for Bluetooth 4.0 till nearly 2 years later and by that time the chipset was so outdated writing software to make it work was not a priority.

The S3 was the first Android phone with software support for 4.0 and it wasn't even widely used because Samsung had to make their own support for it, a support that was entirely different from Google's own implimention nearly a year later.

Edit: Turns out Broadcom wrote their own drivers for it and it can be used in Android 4.3(The version of Android that first supported bluetooth 4.0). Only downside is that you have to root and install a newer rom for it to work. From the sounds of it CM11 should support this.

TL;DR: To the best of my knowledge there's simply no easy way to make this work with the S2 without rooting.

Source: I worked for Best Buy selling phones for 4 years.


OK. Thanks for this. I was able to get a brand new phone and the app launched. I saw BLEWatch but whenever I tried to connect it kept crashing. At the watch time is still incorrect but when I press a button on the side it now says "No Notifications" which it didn't say before.

I tried to send a text to the phone and see if it showed a notification but it still says no notifications even thought I got the text.

The phone is a Nexus 5 running 5.1
Title: Re: TinyScreen Smartwatch
Post by: jpencausse on March 19, 2015, 11:16:19 AM
I install the app from codebench
https://codebender.cc/sketch:91833#TinyScreen_Smartwatch.ino

And use the copiled APK on a Nexus 5 too. The app do not see the URT advertiser and crash when clicking on an other (Shine, StickNFind, ...).
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 19, 2015, 02:04:49 PM
OK. Thanks for this. I was able to get a brand new phone and the app launched. I saw BLEWatch but whenever I tried to connect it kept crashing. At the watch time is still incorrect but when I press a button on the side it now says "No Notifications" which it didn't say before.

I tried to send a text to the phone and see if it showed a notification but it still says no notifications even thought I got the text.

Couple of questions: Did you compile the TinyCircuits BLE app yourself in Android Studio or use the precompiled one I provided earlier in this thread? Are you using the stock texting app on the phone or did you change it to something like Hangouts?

If you compiled it yourself, try to precompiled one I posted earlier, I've confirmed that it works on my Note 4 to send notifications from the default texting app and will notify you of phone calls from the default phone app. If you'd like I have a heavily modified version of the app that will send all notifications(for better or for worse) so you can at least know it's working for some notifications.
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 19, 2015, 02:14:27 PM
I install the app from codebench
https://codebender.cc/sketch:91833#TinyScreen_Smartwatch.ino

And use the copiled APK on a Nexus 5 too. The app do not see the URT advertiser and crash when clicking on an other (Shine, StickNFind, ...).

If you added the TinyScreen Smartwatch code recently, it should be advertising the name BLEWatch instead of URT, Ben Rose was kind enough to change the name to something more appropriate to its code. The Shine and StickNFind aren't compatible with the TinyCircuits app and the app doesn't currently have a graceful way of failing.

Make sure you're using the most recent version of the Smartwatch files from CodeBender and when it starts up look for BLEWatch. It should be there.
Title: Re: TinyScreen Smartwatch
Post by: amd599 on March 19, 2015, 05:48:14 PM
I install the app from codebench
https://codebender.cc/sketch:91833#TinyScreen_Smartwatch.ino

And use the copiled APK on a Nexus 5 too. The app do not see the URT advertiser and crash when clicking on an other (Shine, StickNFind, ...).

If you added the TinyScreen Smartwatch code recently, it should be advertising the name BLEWatch instead of URT, Ben Rose was kind enough to change the name to something more appropriate to its code. The Shine and StickNFind aren't compatible with the TinyCircuits app and the app doesn't currently have a graceful way of failing.

Make sure you're using the most recent version of the Smartwatch files from CodeBender and when it starts up look for BLEWatch. It should be there.

I'm using your compiled one. Again, it launches fine but when I click on the BLEWatch the app just crashes.
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 20, 2015, 12:23:29 AM
I'm using your compiled one. Again, it launches fine but when I click on the BLEWatch the app just crashes.

I think I've realised the problem. When both you and jpencausse had the same issues on your Nexus 5's I guessed that it might be an issue with Android 5.0. I've tested this on my Nexus 4 also running Android 5. It experiences the same issue. I believe there may be some out of date APIs to blame here, I'll look into it and do some testing and get back on here when I have an answer. I'm not a SUPER experienced Android programmer though, so any help I can get on this is much appreciated.

That being said I will state what I know to anyone who might be able to help. Both the Nexus 4 I've just used for testing and the Nexus 5's are running stock Android 5. A manufacturer customized version like the one provided for the S5 and Note 4's may fair differently, if someone can test this, that'll be great. I'd test it myself, but I don't work for the next two days.
Title: Re: TinyScreen Smartwatch
Post by: WakeArray on March 21, 2015, 12:34:04 AM
So while looking for a fix for the bluetooth connection crashing I've found a filed bug report for Android 5 bluetooth issues. They aren't specific to BLE and they seem to all be coming from owners of Nexus and recent Motorola devices. All of which run a vanilla version of Android 5. Having found this and thinking that it was simply an issue with Android 5, I tried the Nordic Semiconductor's app "nRF UART v2.0" and low and behold, it works. Kind of. The watch disconnects like crazy, but I can get it to receive messages I send. The letter D followed by the time in a "yyyy MM dd h m s" format will set the time and get the counter started on the Arduino, sending a 1 followed by a message shows on the top line of the bottom of the screen and sending a 2 shows on the bottom line.

These tests prove that the phone and the OS aren't the reason the app isn't working. This is a plus. I'm just not sure what part of the app isn't working. :/

Edit: It looks like Android 5.0 had a major update to the BluetoothLE scanning API to reduce power consumption. That info is documented here: http://developer.radiusnetworks.com/2014/10/28/android-5.0-scanning.html

Far as I can tell, the older offending code lies in this block. Lines 108-146 of ScanActivity.java. Android studio is enjoying pointing out that 'startLeScan' and 'stopLeScan' are currently depreciated. I'll attempt to adjust this code tomorrow. Currently, I'm a bit too sleepy. Also, Ben Rose might be a bit better at doing this if he has time.

Code: [Select]
    private BluetoothAdapter.LeScanCallback mLeScanCallback =
            new BluetoothAdapter.LeScanCallback() {
                @Override
                public void onLeScan(final BluetoothDevice device, int rssi,
                                     byte[] scanRecord) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            mLeDeviceListAdapter.addDevice(device);
                            mLeDeviceListAdapter.notifyDataSetChanged();
                        }
                    });
                }
            };

    private void scanLeDevice(final boolean enable) {
        if (enable) {
            handler = new Handler();
            // Stops scanning after a pre-defined scan period.
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Debug.ShowText(getApplicationContext(),"scan timed out after " + SCAN_PERIOD/1000 + " seconds.");
                    isScanning = false;
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                    invalidateOptionsMenu();
                }
            }, SCAN_PERIOD);

            isScanning = true;
            mBluetoothAdapter.startLeScan(mLeScanCallback);
        } else {
            isScanning = false;
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }


    }
Title: Re: TinyScreen Smartwatch
Post by: benjgorman on March 23, 2015, 05:38:53 PM
Managed to get the nRF UART app and the tinyduino to talk to one another. Does anyone happen to have an empty iOS app which only does the bluetooth connection/data transmission?
Title: Re: TinyScreen Smartwatch
Post by: ralphcrutzen on March 24, 2015, 03:52:16 PM
I have the same problem with the BLEWatch app crashing. Sending messagas to the TinyDuino with the nRF UART v2.0 app works fine. I have a Nexus 5 with Cyanogenmod 11.

Did someone already manage to fix this?

I looked at the code of the Android App myself, but the only thing I found out is that you have to use
Code: [Select]
BluetoothLeScanner.startScan(List, ScanSettings, ScanCallback) instead of
Code: [Select]
BluetoothAdapter.startLeScan(LeScanCallback)But after that I'm stuck because I'm just not experienced enough to understand how to use those three arguments in the startScan() method...
Title: Re: TinyScreen Smartwatch
Post by: baritonehands on May 22, 2015, 05:31:13 PM
Does anyone happen to have an empty iOS app which only does the bluetooth connection/data transmission?

I just posted my semi-working code (no connection cleanup) in Swift (which I don't plan to finish):
https://github.com/baritonehands/TinyScreen_Smartwatch_iOS

I plan to finish this one in Ionic/JS:
https://github.com/baritonehands/TinyScreen_Smartwatch_Ionic