Introduction: Flora SmartWatch

My first creation, a smart watch.

I hope you like it.

Here is what I used

  • Adafruit Flora
  • Bluetooth Serial Slave Modul HC-06

  • I2C IIC SPI serielle 128 x 64 OLED LCD LED Display

  • GY-80 - Multi Sensor Board

The Bluetooth Board is used to communicate between the clock and my phone to set the time or display different views ( later on I used a Dashboard to control the clock, also though the internet :D )

The Multi Sensor Board GY-80 is for the Pedometer and the Breakout game on the watch, controlled by movement.

Step 1: Connect and Setup

Connect your

  1. Bluethooth ( connection is Serail )

    RX -> TX
    TX-> RX

  2. Display ( connection is I2C )
    SDA -> SDA
    SCL -> SCL
  3. GY-80 ( connection I2C )

    SDA -> SDA
    SCL -> SCL

The great thing about I2C you can connect up to 7 Bit, which leads to 112 "devices" .. awesome :D

Step 2: Let's Get Dirty - the Code

Thanks to Adafruit we can build up our smart watch very fast.

Btw. if you are unsure if your i2C Components are right addressed, use the i2C scanner you'll find it here :

I implemented different views like a clock ( of course ;) ) movement, acceleration, roll & pitch a breakout game, pedometer ( here I 'll come back later )

Simple start

So let's start, first include some header, you'll find them in the Arduino library.

#include SPI.h
#include Wire.h
#include Adafruit_GFX.h
#include Adafruit_SSD1306.h #include L3G4200D.h #include Adafruit_Sensor.h #include Adafruit_ADXL345_U.h #include Adafruit_BMP085.h

Define the obj we later use.

Adafruit_SSD1306 display(4);
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345); Adafruit_BMP085 bmp; L3G4200D gyro;

Init everything we need

void setup()   {                
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // adress display.clearDisplay(); // cls, clear screen Serial.begin(9600); // console output Serial1.begin(9600); // serial bluetooth output display.setTextSize(2); // define some display styles display.setTextColor(WHITE); Wire.begin(); gyro.enableDefault(); accel.begin(); accel.setRange(ADXL345_RANGE_16_G); }

The Tricky Part, time counting

In our loop we will process everything. Getting messages from Serail1 ( bluetooth ) counting the time, display different views etc.

Because of this, we won't delay a second and then increase the time. We need to react quite fast, if there is a message pending in the serail1 queue or of operation time like calculation roll & pitch, displaying information or running the breakout game.

This leads to a dynamic delay time to reduce the error (every calculation costs cpu time )

void loop() {
int mydelay = 100; // get current milli seconds long mimi_start = millis(); long v = 0; bt_settings(); // check bluetooth queue clockTick(); // update periodontally if( counter == 0){ // update these function every second switch( show_screen ){ case CLOCK : renderClock(); break; case TEMP : show_temp(); break; case ACCEL : show_accel(); break; case GYRO : show_gyro(); break; } } // this function will be updated more often if( show_screen == PEDO ){ show_pedo(); } // the game will also be more often be updated if( show_screen == GAME1 ){ play_game_1(); } v = millis() - mimi_start; // dynamical delay calculation // wait const. 100 micro seconds // millis() will be reset after 50 days ! so we will get a delay if( v < 0 ){ mydelay = 100; } else if( v > 100 ){ mydelay = 0; count_error += v - 100; while( count_error > 100 ){ count_error -= 100; counter++; } } else{ mydelay = 100-v; } delay(mydelay); counter++; }

In Fact that's it.

The bt_settings function can also cost a lot of time so we need to handle that. In my case I do some string operations to set different displays or set the time.

void bt_settings(){
if ( Serial1.available() ) { // if there is something in the queue, let's start long v1 = millis(); // we calculate our time error later long v2; BT_Text = Serial1.readString(); // some string operations v2 = (millis() - v1); while( v2 >= 100 ){ v2 -= 100; counter ++; // correct the time if necessary } } }

And finally the clock

void renderClock(){
display.setTextSize(2); display.clearDisplay(); display.setCursor(12,10); display.print( formatValue(std_) + ":" + formatValue(min_) + ":"+ formatValue(sec_) ); display.display(); }

A helper function

String formatValue( int v ){
String s = ""; if( v <10) s = "0"; s += String(v); return s; }

End? -

Step 3: ​Pedometer

To build a good pedometer. It isn't easy ^^ ..

There are different methods : using a threshold, or counting your movement in a time and calculation your moves backwards, doing a fft and so on.

Well .. on the one hand I had some outliers from my sensor and it was time consuming doing the operation on the flora ( 8Mhz). So I used a Dashboard from * I am an early adopter whoo hoo :D *

Public Dashboard