├── Android ├── BLEConnect │ ├── .idea │ │ ├── .name │ │ ├── copyright │ │ │ └── profiles_settings.xml │ │ ├── scopes │ │ │ └── scope_settings.xml │ │ ├── encodings.xml │ │ ├── vcs.xml │ │ ├── modules.xml │ │ ├── misc.xml │ │ ├── gradle.xml │ │ └── compiler.xml │ ├── app │ │ ├── .gitignore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── drawable │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-xxxhdi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── values-v21 │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values │ │ │ │ │ │ ├── styles.xml │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ └── strings.xml │ │ │ │ │ ├── menu │ │ │ │ │ │ └── menu_main.xml │ │ │ │ │ ├── values-w820dp │ │ │ │ │ │ └── dimens.xml │ │ │ │ │ └── layout │ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── beetroot │ │ │ │ │ └── bleconnect │ │ │ │ │ └── MainActivity.java │ │ │ └── androidTest │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── beetroot │ │ │ │ └── bleconnect │ │ │ │ └── ApplicationTest.java │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── app.iml │ ├── settings.gradle │ ├── .gitignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── build.gradle │ ├── gradle.properties │ ├── BLEConnect.iml │ ├── gradlew.bat │ └── gradlew └── BLEDashboard │ ├── .idea │ ├── .name │ ├── copyright │ │ └── profiles_settings.xml │ ├── scopes │ │ └── scope_settings.xml │ ├── encodings.xml │ ├── vcs.xml │ ├── modules.xml │ ├── misc.xml │ ├── gradle.xml │ └── compiler.xml │ ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── drawable-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-v21 │ │ │ │ │ └── styles.xml │ │ │ │ ├── values │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── styles.xml │ │ │ │ │ └── strings.xml │ │ │ │ ├── menu │ │ │ │ │ ├── menu_main.xml │ │ │ │ │ └── menu_dashboard.xml │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ └── layout │ │ │ │ │ ├── row_layout.xml │ │ │ │ │ ├── activity_dashboard.xml │ │ │ │ │ └── activity_main.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── beetroot │ │ │ │ └── bledashboard │ │ │ │ ├── DashboardActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ └── BLEService.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── beetroot │ │ │ └── bledashboard │ │ │ └── ApplicationTest.java │ ├── build.gradle │ ├── proguard-rules.pro │ └── app.iml │ ├── settings.gradle │ ├── .gitignore │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── build.gradle │ ├── gradle.properties │ ├── BLEDashboard.iml │ ├── gradlew.bat │ └── gradlew └── Sketches ├── SimpleSerial └── SimpleSerial.ino ├── SimpleSerialLCD ├── SimpleSerialLCD.ino ├── rgb_lcd.h └── rgb_lcd.cpp └── Dashboard ├── Dashboard.ino ├── rgb_lcd.h └── rgb_lcd.cpp /Android/BLEConnect/.idea/.name: -------------------------------------------------------------------------------- 1 | BLEConnect -------------------------------------------------------------------------------- /Android/BLEConnect/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/.name: -------------------------------------------------------------------------------- 1 | BLEDashboard -------------------------------------------------------------------------------- /Android/BLEDashboard/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android/BLEConnect/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /Android/BLEDashboard/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /Android/BLEConnect/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Android/BLEConnect/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Android/BLEDashboard/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEDashboard/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/drawable-xxxhdi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEConnect/app/src/main/res/drawable-xxxhdi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEDashboard/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEDashboard/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEDashboard/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianstevens/Edison_to_Android_BLE/HEAD/Android/BLEDashboard/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BLEConnect 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android/BLEConnect/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Feb 02 21:36:49 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /Android/BLEDashboard/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Feb 02 21:10:11 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BLE Dashboard 5 | Hello world! 6 | Settings 7 | Refresh 8 | DashboardActivity 9 | 10 | 11 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/menu/menu_dashboard.xml: -------------------------------------------------------------------------------- 1 | 5 | 7 | 8 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/androidTest/java/com/beetroot/bleconnect/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bleconnect; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/androidTest/java/com/beetroot/bledashboard/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bledashboard; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Android/BLEConnect/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.0.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Android/BLEDashboard/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.0.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/layout/row_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | -------------------------------------------------------------------------------- /Sketches/SimpleSerial/SimpleSerial.ino: -------------------------------------------------------------------------------- 1 | 2 | void setup() { 3 | Serial.begin(9600); 4 | 5 | Serial1.begin(9600); //Set BLE baud rate to default 6 | Serial1.print("AT+CLEAR"); //clear all previous settings 7 | Serial1.print("AT+ROLE0"); //set the Grove as a BLE slave 8 | Serial1.print("AT+SAVE1"); //don't save the connection settings 9 | } 10 | 11 | char recvChar; 12 | 13 | void loop() { 14 | if(Serial.available()) 15 | { 16 | recvChar = Serial.read(); 17 | Serial1.print(recvChar); 18 | } 19 | 20 | if(Serial1.available()) 21 | { 22 | recvChar = Serial1.read(); 23 | Serial.print(recvChar); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.1" 6 | 7 | defaultConfig { 8 | applicationId "com.beetroot.bleconnect" 9 | minSdkVersion 18 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.1" 6 | 7 | defaultConfig { 8 | applicationId "com.beetroot.bledashboard" 9 | minSdkVersion 18 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | compile "com.android.support:appcompat-v7:21.0.+" 26 | } 27 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/layout/activity_dashboard.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Adrian\AppData\Local\Android\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Adrian\AppData\Local\Android\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Sketches/SimpleSerialLCD/SimpleSerialLCD.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rgb_lcd.h" 3 | 4 | rgb_lcd lcd; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | 9 | Serial1.begin(9600); //Set BLE baud rate to default 10 | Serial1.print("AT+CLEAR"); //clear all previous settings 11 | Serial1.print("AT+ROLE0"); //set the Grove as a BLE slave 12 | Serial1.print("AT+SAVE1"); //don't save the connection settings 13 | 14 | // set up the LCD's number of columns and rows: 15 | lcd.begin(16, 2); 16 | } 17 | 18 | char recvChar; 19 | 20 | void loop() { 21 | if(Serial.available()) 22 | { 23 | recvChar = Serial.read(); 24 | Serial1.print(recvChar); 25 | } 26 | 27 | if(Serial1.available()) 28 | { 29 | recvChar = Serial1.read(); 30 | Serial.print(recvChar); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Android/BLEConnect/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Android/BLEDashboard/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Android/BLEConnect/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /Android/BLEDashboard/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Android/BLEConnect/BLEConnect.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Android/BLEDashboard/BLEDashboard.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Sketches/Dashboard/Dashboard.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rgb_lcd.h" 3 | 4 | rgb_lcd lcd; 5 | 6 | const int pinLight = A0; 7 | const int pinTemp = A1; 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | 12 | Serial1.begin(9600); //Set BLE baud rate to default 13 | Serial1.print("AT+CLEAR"); //clear all previous settings 14 | Serial1.print("AT+ROLE0"); //set the Grove as a BLE slave 15 | Serial1.print("AT+SAVE1"); //don't save the connection settings 16 | 17 | // set up the LCD's columns and rows 18 | lcd.begin(16, 2); 19 | } 20 | 21 | char recvChar; 22 | 23 | void loop() { 24 | if(Serial.available()) 25 | { 26 | recvChar = Serial.read(); 27 | Serial1.print(recvChar); 28 | 29 | } 30 | 31 | if(Serial1.available()) 32 | { 33 | recvChar = Serial1.read(); 34 | Serial.print(recvChar); 35 | // lcd.print(recvChar); 36 | } 37 | 38 | int sensorValue = analogRead(pinLight); //the light sensor is attached to analog 0 39 | lcd.clear(); 40 | lcd.print(sensorValue); 41 | } 42 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/java/com/beetroot/bledashboard/DashboardActivity.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bledashboard; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | 8 | 9 | public class DashboardActivity extends Activity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_dashboard); 15 | } 16 | 17 | 18 | @Override 19 | public boolean onCreateOptionsMenu(Menu menu) { 20 | // Inflate the menu; this adds items to the action bar if it is present. 21 | getMenuInflater().inflate(R.menu.menu_dashboard, menu); 22 | return true; 23 | } 24 | 25 | @Override 26 | public boolean onOptionsItemSelected(MenuItem item) { 27 | // Handle action bar item clicks here. The action bar will 28 | // automatically handle clicks on the Home/Up button, so long 29 | // as you specify a parent activity in AndroidManifest.xml. 30 | int id = item.getItemId(); 31 | 32 | //noinspection SimplifiableIfStatement 33 | if (id == R.id.action_settings) { 34 | return true; 35 | } 36 | 37 | return super.onOptionsItemSelected(item); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 18 | 19 | 25 | 26 | 34 | 35 | -------------------------------------------------------------------------------- /Android/BLEConnect/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Android/BLEDashboard/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Sketches/Dashboard/rgb_lcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | rgb_lcd.h 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | add rgb backlight fucnction @ 2013-10-15 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | 26 | #ifndef __RGB_LCD_H__ 27 | #define __RGB_LCD_H__ 28 | 29 | #include 30 | #include "Print.h" 31 | 32 | // Device I2C Arress 33 | #define LCD_ADDRESS (0x7c>>1) 34 | #define RGB_ADDRESS (0xc4>>1) 35 | 36 | 37 | // color define 38 | #define WHITE 0 39 | #define RED 1 40 | #define GREEN 2 41 | #define BLUE 3 42 | 43 | #define REG_RED 0x04 // pwm2 44 | #define REG_GREEN 0x03 // pwm1 45 | #define REG_BLUE 0x02 // pwm0 46 | 47 | #define REG_MODE1 0x00 48 | #define REG_MODE2 0x01 49 | #define REG_OUTPUT 0x08 50 | 51 | // commands 52 | #define LCD_CLEARDISPLAY 0x01 53 | #define LCD_RETURNHOME 0x02 54 | #define LCD_ENTRYMODESET 0x04 55 | #define LCD_DISPLAYCONTROL 0x08 56 | #define LCD_CURSORSHIFT 0x10 57 | #define LCD_FUNCTIONSET 0x20 58 | #define LCD_SETCGRAMADDR 0x40 59 | #define LCD_SETDDRAMADDR 0x80 60 | 61 | // flags for display entry mode 62 | #define LCD_ENTRYRIGHT 0x00 63 | #define LCD_ENTRYLEFT 0x02 64 | #define LCD_ENTRYSHIFTINCREMENT 0x01 65 | #define LCD_ENTRYSHIFTDECREMENT 0x00 66 | 67 | // flags for display on/off control 68 | #define LCD_DISPLAYON 0x04 69 | #define LCD_DISPLAYOFF 0x00 70 | #define LCD_CURSORON 0x02 71 | #define LCD_CURSOROFF 0x00 72 | #define LCD_BLINKON 0x01 73 | #define LCD_BLINKOFF 0x00 74 | 75 | // flags for display/cursor shift 76 | #define LCD_DISPLAYMOVE 0x08 77 | #define LCD_CURSORMOVE 0x00 78 | #define LCD_MOVERIGHT 0x04 79 | #define LCD_MOVELEFT 0x00 80 | 81 | // flags for function set 82 | #define LCD_8BITMODE 0x10 83 | #define LCD_4BITMODE 0x00 84 | #define LCD_2LINE 0x08 85 | #define LCD_1LINE 0x00 86 | #define LCD_5x10DOTS 0x04 87 | #define LCD_5x8DOTS 0x00 88 | 89 | class rgb_lcd : public Print 90 | { 91 | 92 | public: 93 | rgb_lcd(); 94 | 95 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 96 | 97 | void clear(); 98 | void home(); 99 | 100 | void noDisplay(); 101 | void display(); 102 | void noBlink(); 103 | void blink(); 104 | void noCursor(); 105 | void cursor(); 106 | void scrollDisplayLeft(); 107 | void scrollDisplayRight(); 108 | void leftToRight(); 109 | void rightToLeft(); 110 | void autoscroll(); 111 | void noAutoscroll(); 112 | 113 | void createChar(uint8_t, uint8_t[]); 114 | void setCursor(uint8_t, uint8_t); 115 | 116 | virtual size_t write(uint8_t); 117 | void command(uint8_t); 118 | 119 | // color control 120 | void setRGB(unsigned char r, unsigned char g, unsigned char b); // set rgb 121 | void setPWM(unsigned char color, unsigned char pwm){setReg(color, pwm);} // set pwm 122 | 123 | void setColor(unsigned char color); 124 | void setColorAll(){setRGB(0, 0, 0);} 125 | void setColorWhite(){setRGB(255, 255, 255);} 126 | 127 | using Print::write; 128 | 129 | private: 130 | void send(uint8_t, uint8_t); 131 | void setReg(unsigned char addr, unsigned char dta); 132 | 133 | uint8_t _displayfunction; 134 | uint8_t _displaycontrol; 135 | uint8_t _displaymode; 136 | 137 | uint8_t _initialized; 138 | 139 | uint8_t _numlines,_currline; 140 | }; 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /Sketches/SimpleSerialLCD/rgb_lcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | rgb_lcd.h 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | add rgb backlight fucnction @ 2013-10-15 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | 26 | #ifndef __RGB_LCD_H__ 27 | #define __RGB_LCD_H__ 28 | 29 | #include 30 | #include "Print.h" 31 | 32 | // Device I2C Arress 33 | #define LCD_ADDRESS (0x7c>>1) 34 | #define RGB_ADDRESS (0xc4>>1) 35 | 36 | 37 | // color define 38 | #define WHITE 0 39 | #define RED 1 40 | #define GREEN 2 41 | #define BLUE 3 42 | 43 | #define REG_RED 0x04 // pwm2 44 | #define REG_GREEN 0x03 // pwm1 45 | #define REG_BLUE 0x02 // pwm0 46 | 47 | #define REG_MODE1 0x00 48 | #define REG_MODE2 0x01 49 | #define REG_OUTPUT 0x08 50 | 51 | // commands 52 | #define LCD_CLEARDISPLAY 0x01 53 | #define LCD_RETURNHOME 0x02 54 | #define LCD_ENTRYMODESET 0x04 55 | #define LCD_DISPLAYCONTROL 0x08 56 | #define LCD_CURSORSHIFT 0x10 57 | #define LCD_FUNCTIONSET 0x20 58 | #define LCD_SETCGRAMADDR 0x40 59 | #define LCD_SETDDRAMADDR 0x80 60 | 61 | // flags for display entry mode 62 | #define LCD_ENTRYRIGHT 0x00 63 | #define LCD_ENTRYLEFT 0x02 64 | #define LCD_ENTRYSHIFTINCREMENT 0x01 65 | #define LCD_ENTRYSHIFTDECREMENT 0x00 66 | 67 | // flags for display on/off control 68 | #define LCD_DISPLAYON 0x04 69 | #define LCD_DISPLAYOFF 0x00 70 | #define LCD_CURSORON 0x02 71 | #define LCD_CURSOROFF 0x00 72 | #define LCD_BLINKON 0x01 73 | #define LCD_BLINKOFF 0x00 74 | 75 | // flags for display/cursor shift 76 | #define LCD_DISPLAYMOVE 0x08 77 | #define LCD_CURSORMOVE 0x00 78 | #define LCD_MOVERIGHT 0x04 79 | #define LCD_MOVELEFT 0x00 80 | 81 | // flags for function set 82 | #define LCD_8BITMODE 0x10 83 | #define LCD_4BITMODE 0x00 84 | #define LCD_2LINE 0x08 85 | #define LCD_1LINE 0x00 86 | #define LCD_5x10DOTS 0x04 87 | #define LCD_5x8DOTS 0x00 88 | 89 | class rgb_lcd : public Print 90 | { 91 | 92 | public: 93 | rgb_lcd(); 94 | 95 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 96 | 97 | void clear(); 98 | void home(); 99 | 100 | void noDisplay(); 101 | void display(); 102 | void noBlink(); 103 | void blink(); 104 | void noCursor(); 105 | void cursor(); 106 | void scrollDisplayLeft(); 107 | void scrollDisplayRight(); 108 | void leftToRight(); 109 | void rightToLeft(); 110 | void autoscroll(); 111 | void noAutoscroll(); 112 | 113 | void createChar(uint8_t, uint8_t[]); 114 | void setCursor(uint8_t, uint8_t); 115 | 116 | virtual size_t write(uint8_t); 117 | void command(uint8_t); 118 | 119 | // color control 120 | void setRGB(unsigned char r, unsigned char g, unsigned char b); // set rgb 121 | void setPWM(unsigned char color, unsigned char pwm){setReg(color, pwm);} // set pwm 122 | 123 | void setColor(unsigned char color); 124 | void setColorAll(){setRGB(0, 0, 0);} 125 | void setColorWhite(){setRGB(255, 255, 255);} 126 | 127 | using Print::write; 128 | 129 | private: 130 | void send(uint8_t, uint8_t); 131 | void setReg(unsigned char addr, unsigned char dta); 132 | 133 | uint8_t _displayfunction; 134 | uint8_t _displaycontrol; 135 | uint8_t _displaymode; 136 | 137 | uint8_t _initialized; 138 | 139 | uint8_t _numlines,_currline; 140 | }; 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/java/com/beetroot/bledashboard/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bledashboard; 2 | 3 | import android.app.ListActivity; 4 | import android.bluetooth.BluetoothAdapter; 5 | import android.bluetooth.BluetoothClass; 6 | import android.bluetooth.BluetoothDevice; 7 | import android.bluetooth.BluetoothManager; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.pm.PackageManager; 11 | import android.os.Bundle; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.view.Window; 16 | import android.widget.ArrayAdapter; 17 | import android.widget.ListView; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class MainActivity extends ListActivity { 25 | 26 | private static final int REQUEST_ENABLE_BT = 1; 27 | private static final long SEARCH_TIMEOUT = 10000; //10 seconds should be plenty 28 | 29 | private BluetoothAdapter mBluetoothAdapter; 30 | private static List mBleDevices = new ArrayList(); 31 | private Context context; 32 | 33 | private TextView statusText; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | 39 | context = this; 40 | 41 | requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 42 | 43 | setContentView(R.layout.activity_main); 44 | 45 | InitBLE (); 46 | SearchForBLEDevices (); 47 | } 48 | 49 | private void InitBLE() 50 | { 51 | if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) == false) { 52 | Toast.makeText(this, "BLE not supported", Toast.LENGTH_SHORT).show(); 53 | finish(); 54 | } 55 | 56 | final BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 57 | mBluetoothAdapter = mBluetoothManager.getAdapter(); 58 | 59 | if (mBluetoothAdapter == null) { 60 | Toast.makeText(this, "BLE not supported", Toast.LENGTH_SHORT).show(); 61 | finish(); 62 | } 63 | 64 | if (mBluetoothAdapter.isEnabled() == false) { 65 | Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 66 | startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 67 | } 68 | } 69 | 70 | private void SearchForBLEDevices () 71 | { 72 | new Thread() { 73 | 74 | @Override 75 | public void run() { 76 | mBluetoothAdapter.startLeScan(mBleScanCallback); 77 | 78 | try { 79 | Thread.sleep(SEARCH_TIMEOUT); 80 | } catch (InterruptedException e) { 81 | e.printStackTrace(); 82 | } 83 | 84 | mBluetoothAdapter.stopLeScan(mBleScanCallback); 85 | } 86 | }.start(); 87 | } 88 | 89 | private BluetoothAdapter.LeScanCallback mBleScanCallback = new BluetoothAdapter.LeScanCallback() 90 | { 91 | @Override 92 | public void onLeScan(final BluetoothDevice device, final int rssi, 93 | byte[] scanRecord) { 94 | runOnUiThread(new Runnable() { 95 | @Override 96 | public void run() { 97 | if (device != null) { 98 | if (mBleDevices.indexOf(device) == -1) //only add new devices 99 | { 100 | mBleDevices.add(device); 101 | 102 | ArrayList listValues = new ArrayList(); 103 | 104 | for (BluetoothDevice device : mBleDevices) 105 | { 106 | listValues.add(device.getName()); 107 | } 108 | 109 | ArrayAdapter myAdapter = new ArrayAdapter(context, R.layout.row_layout, R.id.listText, listValues); 110 | 111 | setListAdapter(myAdapter); 112 | } 113 | } 114 | } 115 | 116 | 117 | 118 | }); 119 | } 120 | }; 121 | 122 | 123 | 124 | @Override 125 | public boolean onCreateOptionsMenu(Menu menu) { 126 | // Inflate the menu; this adds items to the action bar if it is present. 127 | getMenuInflater().inflate(R.menu.menu_main, menu); 128 | return true; 129 | } 130 | 131 | @Override 132 | public boolean onOptionsItemSelected(MenuItem item) { 133 | // Handle action bar item clicks here. The action bar will 134 | // automatically handle clicks on the Home/Up button, so long 135 | // as you specify a parent activity in AndroidManifest.xml. 136 | int id = item.getItemId(); 137 | 138 | //noinspection SimplifiableIfStatement 139 | if (id == R.id.action_settings) { 140 | return true; 141 | } 142 | 143 | return super.onOptionsItemSelected(item); 144 | } 145 | 146 | @Override 147 | protected void onListItemClick (ListView l, View v, int position, long id) { 148 | Toast.makeText(this, "Clicked row " + position, Toast.LENGTH_SHORT).show(); 149 | 150 | //navigate to dashboard 151 | Intent dashboardIntent = new Intent(getApplicationContext(), 152 | DashboardActivity.class); 153 | startActivity(dashboardIntent); 154 | 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Android/BLEConnect/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Android/BLEDashboard/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/src/main/java/com/beetroot/bledashboard/BLEService.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bledashboard; 2 | 3 | import android.app.Service; 4 | import android.bluetooth.BluetoothAdapter; 5 | import android.bluetooth.BluetoothDevice; 6 | import android.bluetooth.BluetoothGatt; 7 | import android.bluetooth.BluetoothGattCallback; 8 | import android.bluetooth.BluetoothGattService; 9 | import android.bluetooth.BluetoothManager; 10 | import android.bluetooth.BluetoothProfile; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | import android.content.pm.PackageManager; 14 | import android.os.Binder; 15 | import android.os.IBinder; 16 | import android.util.Log; 17 | import android.support.v4.content.LocalBroadcastManager; 18 | import android.widget.Toast; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * Created by Adrian on 2/2/2015. 25 | */ 26 | public class BLEService extends Service { 27 | private final static String TAG = "BLEDashBoard"; 28 | // Binder given to clients 29 | private final IBinder mBinder = new BLEServiceBinder(); 30 | 31 | //these values are specific to the Grove BLE V1 - update if you're using a different module 32 | private static String GROVE_SERVICE = "0000ffe0-0000-1000-8000-00805f9b34fb"; 33 | private static String CHARACTERISTIC_TX = "0000ffe1-0000-1000-8000-00805f9b34fb"; 34 | private static String CHARACTERISTIC_RX = "0000ffe1-0000-1000-8000-00805f9b34fb"; 35 | 36 | private static final int REQUEST_ENABLE_BT = 1; 37 | private static final long SCAN_PERIOD = 5000; //5 seconds 38 | private static final String DEVICE_NAME = "HMSoft"; //display name for Grove BLE 39 | 40 | private BluetoothManager mBluetoothManager; 41 | private BluetoothAdapter mBluetoothAdapter;//our local adapter 42 | private BluetoothGatt mBluetoothGatt; //provides the GATT functionality for communication 43 | private BluetoothGattService mBluetoothGattService; //service on mBlueoothGatt 44 | private static List mDevices = new ArrayList();//discovered devices in range 45 | private BluetoothDevice mDevice; //external BLE device (Grove BLE module) 46 | 47 | /** 48 | * Class used for the client Binder. Because we know this service always 49 | * runs in the same process as its clients, we don't need to deal with IPC. 50 | */ 51 | public class BLEServiceBinder extends Binder { 52 | BLEService getService() { 53 | // Return this instance of LocalService so clients can call public methods 54 | return BLEService.this; 55 | } 56 | } 57 | 58 | @Override 59 | public IBinder onBind(Intent intent) { 60 | return mBinder; 61 | } 62 | 63 | @Override 64 | public boolean onUnbind(Intent intent) { 65 | //clean up 66 | if (mBluetoothGatt != null) { 67 | mBluetoothGatt.close(); 68 | mBluetoothGatt = null; 69 | } 70 | return super.onUnbind(intent); 71 | } 72 | 73 | private void sendBroadcast(final String message) { 74 | Log.d("BLE", "sendBroadcast: " + message); 75 | 76 | Intent intent = new Intent(message); 77 | 78 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent); 79 | } 80 | 81 | //output helper method 82 | private void statusUpdate (final String msg) { 83 | Log.w("BLE", msg); 84 | } 85 | 86 | public boolean initBLE () 87 | { 88 | //check to see if Bluetooth Low Energy is supported on this device 89 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { 90 | Toast.makeText(this, "BLE not supported on this device", Toast.LENGTH_SHORT).show(); 91 | statusUpdate("BLE not supported on this device"); 92 | return false; 93 | } 94 | 95 | statusUpdate("BLE supported on this device"); 96 | 97 | //get a reference to the Bluetooth Manager 98 | final BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 99 | mBluetoothAdapter = mBluetoothManager.getAdapter(); 100 | if (mBluetoothAdapter == null) { 101 | Toast.makeText(this, "BLE not supported on this device", Toast.LENGTH_SHORT).show(); 102 | return false; 103 | } 104 | 105 | //Open settings if Bluetooth isn't enabled 106 | //move this to the Activity 107 | if (!mBluetoothAdapter.isEnabled()) { 108 | Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 109 | // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 110 | } 111 | 112 | if (mBluetoothAdapter == null) { 113 | Toast.makeText(this, "Bluetooth disabled", Toast.LENGTH_SHORT).show(); 114 | return false; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { 121 | @Override 122 | public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { 123 | if (newState == BluetoothProfile.STATE_CONNECTED) { 124 | statusUpdate("Connected"); 125 | statusUpdate("Searching for services"); 126 | mBluetoothGatt.discoverServices(); 127 | } 128 | else if (newState == BluetoothProfile.STATE_DISCONNECTED) { 129 | statusUpdate("Device disconnected"); 130 | } 131 | } 132 | 133 | @Override 134 | public void onServicesDiscovered(BluetoothGatt gatt, int status) { 135 | if (status == BluetoothGatt.GATT_SUCCESS) { 136 | List gattServices = mBluetoothGatt.getServices(); 137 | 138 | for(BluetoothGattService gattService : gattServices) { 139 | statusUpdate("Service discovered: " + gattService.getUuid()); 140 | if(GROVE_SERVICE.equals(gattService.getUuid().toString())) 141 | { 142 | mBluetoothGattService = gattService; 143 | statusUpdate("Found communication Service"); 144 | //sendMessage(); 145 | } 146 | } 147 | } else { 148 | statusUpdate("onServicesDiscovered received: " + status); 149 | } 150 | } 151 | }; 152 | } 153 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Android/BLEDashboard/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Sketches/Dashboard/rgb_lcd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | rgb_lcd.cpp 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "rgb_lcd.h" 30 | 31 | void i2c_send_byte(unsigned char dta) 32 | { 33 | Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4 34 | Wire.write(dta); // sends five bytes 35 | Wire.endTransmission(); // stop transmitting 36 | } 37 | 38 | void i2c_send_byteS(unsigned char *dta, unsigned char len) 39 | { 40 | Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4 41 | for(int i=0; i 1) { 58 | _displayfunction |= LCD_2LINE; 59 | } 60 | _numlines = lines; 61 | _currline = 0; 62 | 63 | // for some 1 line displays you can select a 10 pixel high font 64 | if ((dotsize != 0) && (lines == 1)) { 65 | _displayfunction |= LCD_5x10DOTS; 66 | } 67 | 68 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 69 | // according to datasheet, we need at least 40ms after power rises above 2.7V 70 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 71 | delayMicroseconds(50000); 72 | 73 | 74 | // this is according to the hitachi HD44780 datasheet 75 | // page 45 figure 23 76 | 77 | // Send function set command sequence 78 | command(LCD_FUNCTIONSET | _displayfunction); 79 | delayMicroseconds(4500); // wait more than 4.1ms 80 | 81 | // second try 82 | command(LCD_FUNCTIONSET | _displayfunction); 83 | delayMicroseconds(150); 84 | 85 | // third go 86 | command(LCD_FUNCTIONSET | _displayfunction); 87 | 88 | 89 | // finally, set # lines, font size, etc. 90 | command(LCD_FUNCTIONSET | _displayfunction); 91 | 92 | // turn the display on with no cursor or blinking default 93 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 94 | display(); 95 | 96 | // clear it off 97 | clear(); 98 | 99 | // Initialize to default text direction (for romance languages) 100 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 101 | // set the entry mode 102 | command(LCD_ENTRYMODESET | _displaymode); 103 | 104 | 105 | // backlight init 106 | setReg(0, 0); 107 | setReg(1, 0); 108 | setReg(0x08, 0xAA); // all led control by pwm 109 | 110 | setColorWhite(); 111 | 112 | } 113 | 114 | /********** high level commands, for the user! */ 115 | void rgb_lcd::clear() 116 | { 117 | command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero 118 | delayMicroseconds(2000); // this command takes a long time! 119 | } 120 | 121 | void rgb_lcd::home() 122 | { 123 | command(LCD_RETURNHOME); // set cursor position to zero 124 | delayMicroseconds(2000); // this command takes a long time! 125 | } 126 | 127 | void rgb_lcd::setCursor(uint8_t col, uint8_t row) 128 | { 129 | 130 | col = (row == 0 ? col|0x80 : col|0xc0); 131 | unsigned char dta[2] = {0x80, col}; 132 | 133 | i2c_send_byteS(dta, 2); 134 | 135 | } 136 | 137 | // Turn the display on/off (quickly) 138 | void rgb_lcd::noDisplay() 139 | { 140 | _displaycontrol &= ~LCD_DISPLAYON; 141 | command(LCD_DISPLAYCONTROL | _displaycontrol); 142 | } 143 | 144 | void rgb_lcd::display() { 145 | _displaycontrol |= LCD_DISPLAYON; 146 | command(LCD_DISPLAYCONTROL | _displaycontrol); 147 | } 148 | 149 | // Turns the underline cursor on/off 150 | void rgb_lcd::noCursor() 151 | { 152 | _displaycontrol &= ~LCD_CURSORON; 153 | command(LCD_DISPLAYCONTROL | _displaycontrol); 154 | } 155 | 156 | void rgb_lcd::cursor() { 157 | _displaycontrol |= LCD_CURSORON; 158 | command(LCD_DISPLAYCONTROL | _displaycontrol); 159 | } 160 | 161 | // Turn on and off the blinking cursor 162 | void rgb_lcd::noBlink() 163 | { 164 | _displaycontrol &= ~LCD_BLINKON; 165 | command(LCD_DISPLAYCONTROL | _displaycontrol); 166 | } 167 | void rgb_lcd::blink() 168 | { 169 | _displaycontrol |= LCD_BLINKON; 170 | command(LCD_DISPLAYCONTROL | _displaycontrol); 171 | } 172 | 173 | // These commands scroll the display without changing the RAM 174 | void rgb_lcd::scrollDisplayLeft(void) 175 | { 176 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 177 | } 178 | void rgb_lcd::scrollDisplayRight(void) 179 | { 180 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 181 | } 182 | 183 | // This is for text that flows Left to Right 184 | void rgb_lcd::leftToRight(void) 185 | { 186 | _displaymode |= LCD_ENTRYLEFT; 187 | command(LCD_ENTRYMODESET | _displaymode); 188 | } 189 | 190 | // This is for text that flows Right to Left 191 | void rgb_lcd::rightToLeft(void) 192 | { 193 | _displaymode &= ~LCD_ENTRYLEFT; 194 | command(LCD_ENTRYMODESET | _displaymode); 195 | } 196 | 197 | // This will 'right justify' text from the cursor 198 | void rgb_lcd::autoscroll(void) 199 | { 200 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 201 | command(LCD_ENTRYMODESET | _displaymode); 202 | } 203 | 204 | // This will 'left justify' text from the cursor 205 | void rgb_lcd::noAutoscroll(void) 206 | { 207 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 208 | command(LCD_ENTRYMODESET | _displaymode); 209 | } 210 | 211 | // Allows us to fill the first 8 CGRAM locations 212 | // with custom characters 213 | void rgb_lcd::createChar(uint8_t location, uint8_t charmap[]) 214 | { 215 | 216 | location &= 0x7; // we only have 8 locations 0-7 217 | command(LCD_SETCGRAMADDR | (location << 3)); 218 | 219 | 220 | unsigned char dta[9]; 221 | dta[0] = 0x40; 222 | for(int i=0; i<8; i++) 223 | { 224 | dta[i+1] = charmap[i]; 225 | } 226 | i2c_send_byteS(dta, 9); 227 | } 228 | 229 | /*********** mid level commands, for sending data/cmds */ 230 | 231 | // send command 232 | inline void rgb_lcd::command(uint8_t value) 233 | { 234 | unsigned char dta[2] = {0x80, value}; 235 | i2c_send_byteS(dta, 2); 236 | } 237 | 238 | // send data 239 | inline size_t rgb_lcd::write(uint8_t value) 240 | { 241 | 242 | unsigned char dta[2] = {0x40, value}; 243 | i2c_send_byteS(dta, 2); 244 | return 1; // assume sucess 245 | } 246 | 247 | void rgb_lcd::setReg(unsigned char addr, unsigned char dta) 248 | { 249 | Wire.beginTransmission(RGB_ADDRESS); // transmit to device #4 250 | Wire.write(addr); 251 | Wire.write(dta); 252 | Wire.endTransmission(); // stop transmitting 253 | } 254 | 255 | void rgb_lcd::setRGB(unsigned char r, unsigned char g, unsigned char b) 256 | { 257 | setReg(REG_RED, r); 258 | setReg(REG_GREEN, g); 259 | setReg(REG_BLUE, b); 260 | } 261 | 262 | const unsigned char color_define[4][3] = 263 | { 264 | {255, 255, 255}, // white 265 | {255, 0, 0}, // red 266 | {0, 255, 0}, // green 267 | {0, 0, 255}, // blue 268 | }; 269 | 270 | void rgb_lcd::setColor(unsigned char color) 271 | { 272 | if(color > 3)return ; 273 | setRGB(color_define[color][0], color_define[color][1], color_define[color][2]); 274 | } 275 | -------------------------------------------------------------------------------- /Sketches/SimpleSerialLCD/rgb_lcd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | rgb_lcd.cpp 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "rgb_lcd.h" 30 | 31 | void i2c_send_byte(unsigned char dta) 32 | { 33 | Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4 34 | Wire.write(dta); // sends five bytes 35 | Wire.endTransmission(); // stop transmitting 36 | } 37 | 38 | void i2c_send_byteS(unsigned char *dta, unsigned char len) 39 | { 40 | Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4 41 | for(int i=0; i 1) { 58 | _displayfunction |= LCD_2LINE; 59 | } 60 | _numlines = lines; 61 | _currline = 0; 62 | 63 | // for some 1 line displays you can select a 10 pixel high font 64 | if ((dotsize != 0) && (lines == 1)) { 65 | _displayfunction |= LCD_5x10DOTS; 66 | } 67 | 68 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 69 | // according to datasheet, we need at least 40ms after power rises above 2.7V 70 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 71 | delayMicroseconds(50000); 72 | 73 | 74 | // this is according to the hitachi HD44780 datasheet 75 | // page 45 figure 23 76 | 77 | // Send function set command sequence 78 | command(LCD_FUNCTIONSET | _displayfunction); 79 | delayMicroseconds(4500); // wait more than 4.1ms 80 | 81 | // second try 82 | command(LCD_FUNCTIONSET | _displayfunction); 83 | delayMicroseconds(150); 84 | 85 | // third go 86 | command(LCD_FUNCTIONSET | _displayfunction); 87 | 88 | 89 | // finally, set # lines, font size, etc. 90 | command(LCD_FUNCTIONSET | _displayfunction); 91 | 92 | // turn the display on with no cursor or blinking default 93 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 94 | display(); 95 | 96 | // clear it off 97 | clear(); 98 | 99 | // Initialize to default text direction (for romance languages) 100 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 101 | // set the entry mode 102 | command(LCD_ENTRYMODESET | _displaymode); 103 | 104 | 105 | // backlight init 106 | setReg(0, 0); 107 | setReg(1, 0); 108 | setReg(0x08, 0xAA); // all led control by pwm 109 | 110 | setColorWhite(); 111 | 112 | } 113 | 114 | /********** high level commands, for the user! */ 115 | void rgb_lcd::clear() 116 | { 117 | command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero 118 | delayMicroseconds(2000); // this command takes a long time! 119 | } 120 | 121 | void rgb_lcd::home() 122 | { 123 | command(LCD_RETURNHOME); // set cursor position to zero 124 | delayMicroseconds(2000); // this command takes a long time! 125 | } 126 | 127 | void rgb_lcd::setCursor(uint8_t col, uint8_t row) 128 | { 129 | 130 | col = (row == 0 ? col|0x80 : col|0xc0); 131 | unsigned char dta[2] = {0x80, col}; 132 | 133 | i2c_send_byteS(dta, 2); 134 | 135 | } 136 | 137 | // Turn the display on/off (quickly) 138 | void rgb_lcd::noDisplay() 139 | { 140 | _displaycontrol &= ~LCD_DISPLAYON; 141 | command(LCD_DISPLAYCONTROL | _displaycontrol); 142 | } 143 | 144 | void rgb_lcd::display() { 145 | _displaycontrol |= LCD_DISPLAYON; 146 | command(LCD_DISPLAYCONTROL | _displaycontrol); 147 | } 148 | 149 | // Turns the underline cursor on/off 150 | void rgb_lcd::noCursor() 151 | { 152 | _displaycontrol &= ~LCD_CURSORON; 153 | command(LCD_DISPLAYCONTROL | _displaycontrol); 154 | } 155 | 156 | void rgb_lcd::cursor() { 157 | _displaycontrol |= LCD_CURSORON; 158 | command(LCD_DISPLAYCONTROL | _displaycontrol); 159 | } 160 | 161 | // Turn on and off the blinking cursor 162 | void rgb_lcd::noBlink() 163 | { 164 | _displaycontrol &= ~LCD_BLINKON; 165 | command(LCD_DISPLAYCONTROL | _displaycontrol); 166 | } 167 | void rgb_lcd::blink() 168 | { 169 | _displaycontrol |= LCD_BLINKON; 170 | command(LCD_DISPLAYCONTROL | _displaycontrol); 171 | } 172 | 173 | // These commands scroll the display without changing the RAM 174 | void rgb_lcd::scrollDisplayLeft(void) 175 | { 176 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 177 | } 178 | void rgb_lcd::scrollDisplayRight(void) 179 | { 180 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 181 | } 182 | 183 | // This is for text that flows Left to Right 184 | void rgb_lcd::leftToRight(void) 185 | { 186 | _displaymode |= LCD_ENTRYLEFT; 187 | command(LCD_ENTRYMODESET | _displaymode); 188 | } 189 | 190 | // This is for text that flows Right to Left 191 | void rgb_lcd::rightToLeft(void) 192 | { 193 | _displaymode &= ~LCD_ENTRYLEFT; 194 | command(LCD_ENTRYMODESET | _displaymode); 195 | } 196 | 197 | // This will 'right justify' text from the cursor 198 | void rgb_lcd::autoscroll(void) 199 | { 200 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 201 | command(LCD_ENTRYMODESET | _displaymode); 202 | } 203 | 204 | // This will 'left justify' text from the cursor 205 | void rgb_lcd::noAutoscroll(void) 206 | { 207 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 208 | command(LCD_ENTRYMODESET | _displaymode); 209 | } 210 | 211 | // Allows us to fill the first 8 CGRAM locations 212 | // with custom characters 213 | void rgb_lcd::createChar(uint8_t location, uint8_t charmap[]) 214 | { 215 | 216 | location &= 0x7; // we only have 8 locations 0-7 217 | command(LCD_SETCGRAMADDR | (location << 3)); 218 | 219 | 220 | unsigned char dta[9]; 221 | dta[0] = 0x40; 222 | for(int i=0; i<8; i++) 223 | { 224 | dta[i+1] = charmap[i]; 225 | } 226 | i2c_send_byteS(dta, 9); 227 | } 228 | 229 | /*********** mid level commands, for sending data/cmds */ 230 | 231 | // send command 232 | inline void rgb_lcd::command(uint8_t value) 233 | { 234 | unsigned char dta[2] = {0x80, value}; 235 | i2c_send_byteS(dta, 2); 236 | } 237 | 238 | // send data 239 | inline size_t rgb_lcd::write(uint8_t value) 240 | { 241 | 242 | unsigned char dta[2] = {0x40, value}; 243 | i2c_send_byteS(dta, 2); 244 | return 1; // assume sucess 245 | } 246 | 247 | void rgb_lcd::setReg(unsigned char addr, unsigned char dta) 248 | { 249 | Wire.beginTransmission(RGB_ADDRESS); // transmit to device #4 250 | Wire.write(addr); 251 | Wire.write(dta); 252 | Wire.endTransmission(); // stop transmitting 253 | } 254 | 255 | void rgb_lcd::setRGB(unsigned char r, unsigned char g, unsigned char b) 256 | { 257 | setReg(REG_RED, r); 258 | setReg(REG_GREEN, g); 259 | setReg(REG_BLUE, b); 260 | } 261 | 262 | const unsigned char color_define[4][3] = 263 | { 264 | {255, 255, 255}, // white 265 | {255, 0, 0}, // red 266 | {0, 255, 0}, // green 267 | {0, 0, 255}, // blue 268 | }; 269 | 270 | void rgb_lcd::setColor(unsigned char color) 271 | { 272 | if(color > 3)return ; 273 | setRGB(color_define[color][0], color_define[color][1], color_define[color][2]); 274 | } 275 | -------------------------------------------------------------------------------- /Android/BLEConnect/app/src/main/java/com/beetroot/bleconnect/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.beetroot.bleconnect; 2 | 3 | import android.app.Activity; 4 | import android.bluetooth.BluetoothAdapter; 5 | import android.bluetooth.BluetoothGatt; 6 | import android.bluetooth.BluetoothGattCallback; 7 | import android.bluetooth.BluetoothGattCharacteristic; 8 | import android.bluetooth.BluetoothGattService; 9 | import android.bluetooth.BluetoothManager; 10 | import android.bluetooth.BluetoothProfile; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | import android.content.pm.PackageManager; 14 | import android.os.Bundle; 15 | import android.util.Log; 16 | 17 | import android.bluetooth.BluetoothDevice; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Timer; 24 | import java.util.TimerTask; 25 | import java.util.UUID; 26 | 27 | 28 | public class MainActivity extends Activity { 29 | //these values are specific to the Grove BLE V1 - update if you're using a different module 30 | private static String GROVE_SERVICE = "0000ffe0-0000-1000-8000-00805f9b34fb"; 31 | private static String CHARACTERISTIC_TX = "0000ffe1-0000-1000-8000-00805f9b34fb"; 32 | private static String CHARACTERISTIC_RX = "0000ffe1-0000-1000-8000-00805f9b34fb"; 33 | 34 | private static final int REQUEST_ENABLE_BT = 1; 35 | private static final long SCAN_PERIOD = 5000; //5 seconds 36 | private static final String DEVICE_NAME = "HMSoft"; //display name for Grove BLE 37 | 38 | private BluetoothAdapter mBluetoothAdapter;//our local adapter 39 | private BluetoothGatt mBluetoothGatt; //provides the GATT functionality for communication 40 | private BluetoothGattService mBluetoothGattService; //service on mBlueoothGatt 41 | private static List mDevices = new ArrayList();//discovered devices in range 42 | private BluetoothDevice mDevice; //external BLE device (Grove BLE module) 43 | 44 | private TextView mainText; 45 | 46 | private Timer mTimer; 47 | 48 | @Override 49 | protected void onCreate(Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_main); 52 | 53 | mainText = (TextView) findViewById(R.id.mainText); 54 | mainText.setText("Hello Bluetooth LE!"); 55 | 56 | mTimer = new Timer(); 57 | 58 | //check to see if Bluetooth Low Energy is supported on this device 59 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { 60 | Toast.makeText(this, "BLE not supported on this device", Toast.LENGTH_SHORT).show(); 61 | finish(); 62 | } 63 | 64 | statusUpdate("BLE supported on this device"); 65 | 66 | //get a reference to the Bluetooth Manager 67 | final BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 68 | mBluetoothAdapter = mBluetoothManager.getAdapter(); 69 | if (mBluetoothAdapter == null) { 70 | Toast.makeText(this, "BLE not supported on this device", Toast.LENGTH_SHORT).show(); 71 | finish(); 72 | return; 73 | } 74 | 75 | //Open settings if Bluetooth isn't enabled 76 | if (!mBluetoothAdapter.isEnabled()) { 77 | Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 78 | startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 79 | } 80 | 81 | if (mBluetoothAdapter == null) { 82 | Toast.makeText(this, "Bluetooth disabled", Toast.LENGTH_SHORT).show(); 83 | finish(); 84 | return; 85 | } 86 | 87 | //try to find the Grove BLE V1 module 88 | searchForDevices(); 89 | } 90 | 91 | private void searchForDevices () 92 | { 93 | statusUpdate("Searching for devices ..."); 94 | 95 | if(mTimer != null) { 96 | mTimer.cancel(); 97 | } 98 | 99 | scanLeDevice(); 100 | mTimer = new Timer(); 101 | mTimer.schedule(new TimerTask() { 102 | @Override 103 | public void run() { 104 | statusUpdate("Search complete"); 105 | findGroveBLE(); 106 | } 107 | }, SCAN_PERIOD); 108 | } 109 | 110 | private void findGroveBLE () 111 | { 112 | if(mDevices == null || mDevices.size() == 0) 113 | { 114 | statusUpdate("No BLE devices found"); 115 | return; 116 | } 117 | else if(mDevice == null) 118 | { 119 | statusUpdate("Unable to find Grove BLE"); 120 | return; 121 | } 122 | else 123 | { 124 | statusUpdate("Found Grove BLE V1"); 125 | statusUpdate("Address: " + mDevice.getAddress()); 126 | connectDevice(); 127 | } 128 | } 129 | 130 | private boolean connectDevice () 131 | { 132 | BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mDevice.getAddress()); 133 | if (device == null) { 134 | statusUpdate("Unable to connect"); 135 | return false; 136 | } 137 | // directly connect to the device 138 | statusUpdate("Connecting ..."); 139 | mBluetoothGatt = device.connectGatt(this, false, mGattCallback); 140 | return true; 141 | } 142 | 143 | private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { 144 | @Override 145 | public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { 146 | if (newState == BluetoothProfile.STATE_CONNECTED) { 147 | statusUpdate("Connected"); 148 | statusUpdate("Searching for services"); 149 | mBluetoothGatt.discoverServices(); 150 | } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { 151 | statusUpdate("Device disconnected"); 152 | } 153 | } 154 | 155 | @Override 156 | public void onServicesDiscovered(BluetoothGatt gatt, int status) { 157 | if (status == BluetoothGatt.GATT_SUCCESS) { 158 | List gattServices = mBluetoothGatt.getServices(); 159 | 160 | for(BluetoothGattService gattService : gattServices) { 161 | statusUpdate("Service discovered: " + gattService.getUuid()); 162 | if(GROVE_SERVICE.equals(gattService.getUuid().toString())) 163 | { 164 | mBluetoothGattService = gattService; 165 | statusUpdate("Found communication Service"); 166 | sendMessage(); 167 | } 168 | } 169 | } else { 170 | statusUpdate("onServicesDiscovered received: " + status); 171 | } 172 | } 173 | }; 174 | 175 | private void sendMessage () 176 | { 177 | if (mBluetoothGattService == null) 178 | return; 179 | 180 | statusUpdate("Finding Characteristic..."); 181 | BluetoothGattCharacteristic gattCharacteristic = 182 | mBluetoothGattService.getCharacteristic(UUID.fromString(CHARACTERISTIC_TX)); 183 | 184 | if(gattCharacteristic == null) { 185 | statusUpdate("Couldn't find TX characteristic: " + CHARACTERISTIC_TX); 186 | return; 187 | } 188 | 189 | statusUpdate("Found TX characteristic: " + CHARACTERISTIC_TX); 190 | 191 | statusUpdate("Sending message 'Hello Grove BLE'"); 192 | 193 | String msg = "Hello Grove BLE"; 194 | 195 | byte b = 0x00; 196 | byte[] temp = msg.getBytes(); 197 | byte[] tx = new byte[temp.length + 1]; 198 | tx[0] = b; 199 | 200 | for(int i = 0; i < temp.length; i++) 201 | tx[i+1] = temp[i]; 202 | 203 | gattCharacteristic.setValue(tx); 204 | mBluetoothGatt.writeCharacteristic(gattCharacteristic); 205 | } 206 | 207 | private void scanLeDevice() { 208 | new Thread() { 209 | 210 | @Override 211 | public void run() { 212 | mBluetoothAdapter.startLeScan(mLeScanCallback); 213 | 214 | try { 215 | Thread.sleep(SCAN_PERIOD); 216 | } catch (InterruptedException e) { 217 | e.printStackTrace(); 218 | } 219 | 220 | mBluetoothAdapter.stopLeScan(mLeScanCallback); 221 | } 222 | }.start(); 223 | } 224 | 225 | private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { 226 | 227 | @Override 228 | public void onLeScan(final BluetoothDevice device, final int rssi, 229 | byte[] scanRecord) { 230 | if (device != null) { 231 | if (mDevices.indexOf(device) == -1)//to avoid duplicate entries 232 | { 233 | if (DEVICE_NAME.equals(device.getName())) { 234 | mDevice = device;//we found our device! 235 | } 236 | mDevices.add(device); 237 | statusUpdate("Found device " + device.getName()); 238 | } 239 | } 240 | } 241 | }; 242 | 243 | //output helper method 244 | private void statusUpdate (final String msg) { 245 | runOnUiThread(new Runnable() { 246 | @Override 247 | public void run() { 248 | Log.w("BLE", msg); 249 | mainText.setText(mainText.getText() + "\r\n" + msg); 250 | } 251 | }); 252 | } 253 | } 254 | --------------------------------------------------------------------------------