Kitty Yeung
Published © CC BY-NC-SA

Arduino101 / tinyTILE BLE: Match-Making Sunglasses

You can make someone else's sunglasses see-through via BLE and check them out from far away, perhaps with your heartbeat.

IntermediateFull instructions provided6 hours19,282

Things used in this project

Hardware components

Intel tinyTILE
Or other BLE modules
×2
Arduino 101
Arduino 101
Optional
×2
Adafruit Liquid Crystal Light Valve – LCD Controllable Blackout Panel
×2
Li-Ion Battery 100mAh
Li-Ion Battery 100mAh
×2
Adafruit JST-PH 2-pin SMT Right Angle Connector
×4
Adafruit JST-PH Battery Extension Cable
×2
Slide Switch
Slide Switch
×2
Resistor 10k ohm
Resistor 10k ohm
×3
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
LED (generic)
LED (generic)
These were used in the development stage and will not be needed for the final prototypes.
×2
Breadboard (generic)
Breadboard (generic)
This was used in the development stage and will not be needed for the final prototypes.
×1
Jumper wires (generic)
Jumper wires (generic)
These were used in the development stage and will not be needed for the final prototypes.
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

universe_frame_kittyyeung_OHEnSGoOkS.STL

heart_frame_kittyyeung_yyh8dY3sFX.STL

Schematics

Central and Peripheral devices

Central uses pin 3 for button and 5 for LCD. Peripheral uses pin 6 for LCD.

Code

Button control for central

Arduino
This is almost the same as the one in the CurieBLE example.
 /*
 * Copyright (c) 2016 Intel Corporation.  All rights reserved.
 * See the bottom of this file for the license terms.
 */

/*
 * Sketch: LedControl.ino
 *
 * Description:
 *   This is a Central sketch that looks for a particular Sevice with a
 *   certain Characteristic from a Peripheral.  Upon succesful discovery,
 *   it reads the state of a button and write that value to the
 *   Peripheral Characteristic.
 *
 * Notes:
 *
 *  - Expected Peripheral Service: 19b10000-e8f2-537e-4f6c-d104768a1214
 *  - Expected Peripheral Characteristic: 19b10001-e8f2-537e-4f6c-d104768a1214
 *  - Expected Peripheral sketch:
 *
 */

#include <CurieBLE.h>

// variables for button
const int buttonPin = 3;
int oldButtonState = LOW;
const int ledPin = 5; // pin to use for the LED


void setup() {
  Serial.begin(9600);

  // configure the button pin as input
  pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);

  // initialize the BLE hardware
  BLE.begin();

  Serial.println("BLE Central - LED control");

  // start scanning for peripherals
  BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}

void loop() {
  // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
    Serial.print("Found ");
    Serial.print(peripheral.address());
    Serial.print(" '");
    Serial.print(peripheral.localName());
    Serial.print("' ");
    Serial.print(peripheral.advertisedServiceUuid());
    Serial.println();

    // stop scanning
    BLE.stopScan();

    controlLed(peripheral);

    // peripheral disconnected, start scanning again
    BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
  }
}

void controlLed(BLEDevice peripheral) {
  // connect to the peripheral
  Serial.println("Connecting ...");

  if (peripheral.connect()) {
    Serial.println("Connected");
  } else {
    Serial.println("Failed to connect!");
    return;
  }

  // discover peripheral attributes
  Serial.println("Discovering attributes ...");
  if (peripheral.discoverAttributes()) {
    Serial.println("Attributes discovered");
  } else {
    Serial.println("Attribute discovery failed!");
    peripheral.disconnect();
    return;
  }

  // retrieve the LED characteristic
  BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");

  if (!ledCharacteristic) {
    Serial.println("Peripheral does not have LED characteristic!");
    peripheral.disconnect();
    return;
  } else if (!ledCharacteristic.canWrite()) {
    Serial.println("Peripheral does not have a writable LED characteristic!");
    peripheral.disconnect();
    return;
  }

  while (peripheral.connected()) {
    // while the peripheral is connection

    // read the button pin
    int buttonState = digitalRead(buttonPin);

    if (oldButtonState != buttonState) {
      // button changed
      oldButtonState = buttonState;

      if (buttonState) {
        Serial.println("button pressed");

        // button is pressed, write 0x01 to turn the LED on
        ledCharacteristic.writeByte(0x01);
        digitalWrite(ledPin, LOW); 
      } else {
        Serial.println("button released");

        // button is released, write 0x00 to turn the LED of
        ledCharacteristic.writeByte(0x00);
        digitalWrite(ledPin, HIGH); 
      }
    }
  }

  Serial.println("Peripheral disconnected");
}

/*
  Arduino BLE Central LED Control example
  Copyright (c) 2016 Arduino LLC. All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

Credits

Kitty Yeung

Kitty Yeung

19 projects • 184 followers
Physicist/Artist/Musician/Fashion Designer/Engineer www.kittyyeung.com
Thanks to Ruiz Brothers.

Comments