Let's Make A SmartWatch

Let's make a SmartWatch
 
The compute module of Intel called Intel Edison is slightly larger than an SD card. After playing around Edison extensively I am completely in love with this tiny computer. The specialty of Edison is – It can be used for wearables also it is enough powerful to control robots. It is a 35.5 × 25.0 × 3.9 mm module also equipped with Yocto, a Linux OS. It has onboard Wi-Fi and Bluetooth, perfect for IoT projects. We can connect to Edison remotely and run commands or access the file system. This gives lots of flexibility to developers via SSH. Its specs will definitely impress you, they are:
 
Intel Edision board
 
Figure 1: Intel Edison board
 
Specs
  • Intel® Atom™ Processor clocked at 500MHz
  • 100MHz Quark MCU
  • 1GB of LPDDR3 RAM
  • 4GB eMMC flash memory
  • WiFi (802.11a/b/g/n)
  • Bluetooth (4.0 and 2.1 EDR),
  • UARTs
  • I2C
  • SPI
  • USB
  • 40 multiplexed GPIO interfaces
Programming Methods
 
Edison can be used with Arduino IDE but to get most out of it you can use other programming languages like Python, Node.js, C/C++. Intel has its own IDE called Intel XDK IoT edition which makes programming with Edison easy. While setting up the programming environment for Edison you can choose between Arduino IDE, Intel XDK or Eclipse.
 
Prototyping with Edison
 
To keep the Edison small all of the I/O pins are broken out to a 70-pin Hirose connector. This 70 pin connector is not prototyping-friendly. Interfacing with these connectors is really difficult so to interface with Edison we need a board with mating Hirose connector.
 
Currently, available interfacing boards are:
  • Arduino Expansion Board
  • Mini Breakout Board
  • SparkFun Edison Blocks
If you are new to Edison and wanted to play around it, Arduino Expansion Board is for you. It will give you Arduino like feel, also Arduino based shield are compatible with this board but slightly larger than Intel Galileo. The features are:
 
Arduino Expansion Board
 
Figure 2: Arduino Expansion Board
  • 20 digital input/output pins including 4 pins as PWM outputs.
  • 6 analog inputs
  • 1 UART (RX/TX)
  • 1 I2C
  • 1 ICSP 6-pin header (SPI)
  • Micro USB device connector OR (via mechanical switch) dedicated standard size USB host Type-A connector.
  • Micro USB device (connected to UART)
  • Micro SD card connector
  • DC power jack (7V – 15V DC input)
If you want to embed Edison into a project than you can use Mini Breakout Board or SparkFun Edison Blocks. They are slightly larger than Intel Edison. Mini Breakout Board has minimal features as:
 
 Image courtesy: Adafruit
 
Figure 3:Mini breakout Board
 
Image courtesy: Adafruit
  • Exposes native 1.8V I/O of the Edison module.
  • 0.1” grid I/O array of through-hole solder points.
  • USB OTG with USB Micro Type-AB connector.
  • USB OTG power switch.
  • Battery charger.
  • USB to device UART bridge with USB Micro Type-B connector.
  • DC power supply jack (7V – 15V DC input).
SparkFun has a whole set of modules for Interfacing, Power, Sensors, and Actuators. You can browse them here and can find one or many suitable for your project with Edison
 
Intel Edision
 
Figure 4: Sparkfun Edison Blocks
 
Why to choose Edison?
 
Edison is a low power IoT computing module, hence for less power consumption processor also slightly larger than a SD card . It is the best choice for a wearable project.
 
Let’s make a SmartWatch
 
Edison is enough small to use in wearable projects, so why not we make a smartwatch with this tiny computer. I am going to use Arduino breakout board for prototyping though this will not look exactly like a smartwatch in prototype stage but will have all the functionalities and later we can work on to make it modular and compact. For the prototyping I used a 16*2 LCD module for display as currently I was not having an OLED display, if you have one you can use the OLED display as it has low power consumption and smaller too. I will soon update this project with an OLED. So let’s see functionalities of our Edison SmartWatch.
  1. Show time continuously.
  2. Monitoring and showing nearby temperature and sending to cloud.
  3. Sending SMS with one touch.
  4. Flashlight
  5. Pedometer and sleep monitor.
Requirements
  • Intel Edison Module
  • Arduino expansion board for Edison
  • Touch Sensor
  • Grove Button
  • LSM303 Accelerometer/Compass Sensor
  • Temperature Sensor
  • 16*2 LCD RGB backlight
  • Grove LED module
  • Super bright LED (White)
  • Grove base shield
  • Power supply
  • Micro USB cable
  • Jumper wires
Requirements
 
Figure 5: Requirements
 
umper wires
 
Figure 6: Flora Accelerometer with hook up wires
 
I am using Grove's sensors as it makes prototyping easy. You will find most of the sensors used in this project in Grove's Starter Kit for Edison. If you are new to IoT, the Seed Studio Grove Starter Kit will help you to easily get started with development since you need not worry about circuits and other electronics stuff. With Grove shield and sensor modules, you can easily create anything without worrying about electronic components much. There is no need to manage sensors using soldering or a breadboard. This article "Grove Starter Kit With Intel Galileo Gen 2: Getting Started" will guide you about how to set up and get running with the Grove Starter Kit plus, though it is with Galileo gen 2 everything is similar for Intel Edison. I am using Adafruit's Flora accelerometer/compass as I am having this one currently with me, it works fine but as this is designed as a sewable module you will have to do a little extra work while making connections with this. If you don't have any I suggest you Grove - 6-Axis Accelerometer & Compass or Adafruit's accelerometer/compass LSM303.
 
First, we have to make Edison ready for programming:
  1. Download the installer depending on your PC’s configuration from https://software.intel.com/en-us/iot/software/installers.
  2. Run the installer, it will ask you about the programming environment and IDE you want to install. Choose one or many according to your preference. For this project I am using Intel XDK and programming using node.js
     
     Intel XDK
     
    Figure 7: Intel XDK
     
  3. Set up Serial terminal: If you want to use your board run commands remotely, you have to set up a serial connection. First, install putty from http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe, Run the installer. Expand Connection in the menu and select Serial. Now in serial line type the COM port to which your Edison is connected. In the Speed field, type 115200 and select Serial in the connection type. Click OK, it will open a serial connection. Press enter, now it will prompt for login. Enter your credentials. Default username is root with no password. Now you will see a terminal port.
     
    Set up Serial termina
     
    Figure 8: Set up Serial terminal
     
  4. Connect to Wi-Fi: Enter this command in serial terminal-
     
    configure_edison- Wifi, Edison will scan for all Wi-Fi networks for approximately 10 seconds. When it is finished, a list of available networks will be displayed. Choose the network by the corresponding number in the list, type Y and press enter. It will ask for network credentials, enter valid credentials and you will be connected to WiFi with your Edison.
     
    Configure_edison
     
    Figure 9: Configure Edison for WiFi
     
  5. In your web browser type the IP address of your Edison or "http://edison.local" will show this page if your Edison is connected to the network.
     
    IP address
     
    Figure 10: Edison connected to a network
     
  6. Now we are all done to start developing with our Edison projects.
Making Connections
  1. Connect your Edison to a power supply and to your PC via USB cable.
  2. It will take 15-20 seconds to boot up, after that stack the Grove Base Shield.
  3. Connect the Temperature Sensor to analog pin A0.
  4. Connect the temperature sensor to A1.
  5. Connect the LCD Display to one of the I2C port.
  6. Connect the Accelerometer to another I2C port.
  7. Connect the Grove button to D2.
  8. Connect the LED module to D3.
  9. Connect the touch sensor to D4.
Making Connections
 
        Figure 11: Connections
 
Programming for SmartWatch
  1. Open Intel XDK IoT edition, if it is not already installed in your PC get it from the following link at Intel Developer Zone.
  2. If you have flashed you Edison with the Flash Lite Tool Node.js will be already installed on your board.=
  3. Connect IDE to your Edison board. It will ask you for username and password, the default username is root with no password.
     
    Connect IDE
     
    Figure 12: Connection to Edison
     
  4. Select a blank Node.js template and create a new project.
     
    Blank Node.JS Template
     
      Figure 13: Blank Node.JS Template
     
    New project
     
      Figure 14: New project
Code for Displaying Time and Temperature
  1. var lcd = new jsUpmI2cLcd.Jhd1313m1(6, 0x3E, 0x62);  
  2. var groveSensor = require('jsupm_grove');  
  3. var today = setInterval(function ()  
  4. {  
  5.     var d = new Date();  
  6.     var b = d.toTimeString();  
  7.     lcd.setColor(0, 255, 0);  
  8.     // Go to the 2nd row, 6th character (0-indexed)  
  9.     lcd.setCursor(0, 0);  
  10.     lcd.write(b);  
  11.     var celsius = temp.value();  
  12.     var fahrenheit = celsius * 9.0 / 5.0 + 32.0;  
  13.     var t = Math.round(fahrenheit);  
  14.     lcd.setCursor(1, 1);  
  15.     lcd.write(t + " *F");  
  16.     v.saveValue(t);  
  17. }, 1000);  
Code for Sending SMS
  1. var twilio = require('twilio');  
  2. // Create a new REST API client to make authenticated requests against the  
  3. // twilio back end  
  4. var TWILIO_ACCOUNT_SID = '';  
  5. var TWILIO_AUTH_TOKEN = '';  
  6. var OUTGOING_NUMBER = '';  
  7. var TWILIO_NUMBER = '';  
  8. var client = new twilio.RestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);  
  9. // Pass in parameters to the REST API using an object literal notation. The  
  10. // REST client will handle authentication and response serialzation for you.  
  11. client.sms.messages.create(  
  12. {  
  13.     to: OUTGOING_NUMBER,  
  14.     from: TWILIO_NUMBER,  
  15.     body: 'Hi, sending from my Edison SmartWatch'  
  16. }, function (error, message)  
  17. {  
  18.     // The HTTP request to Twilio will run asynchronously. This callback  
  19.     // function will be called when a response is received from Twilio  
  20.     // The "error" variable will contain error information, if any.  
  21.     // If the request was successful, this value will be "falsy"  
  22.     if (!error)  
  23.     {  
  24.         // The second argument to the callback will contain the information  
  25.         // sent back by Twilio for the request. In this case, it is the  
  26.         // information about the text messsage you just sent:  
  27.         console.log('Success! The SID for this SMS message is:');  
  28.         console.log(message.sid);  
  29.         console.log('Message sent on:');  
  30.         console.log(message.dateCreated);  
  31.     }  
  32.     else  
  33.     {  
  34.         console.log('error: ' + error.message);  
  35.     }  
  36. });  
Code for Accelerometer and Gyroscope
  1. var accelrCompassSensor = require('jsupm_lsm303');  
  2. // Instantiate LSM303 compass on I2C  
  3. var myAccelrCompass = new accelrCompassSensor.LSM303(0);  
  4. var successFail, coords, outputStr, accel;  
  5. var myInterval = setInterval(function ()  
  6. {  
  7.     // Load coordinates into LSM303 object  
  8.     successFail = myAccelrCompass.getCoordinates();  
  9.     // in XYZ order. The sensor returns XZY,  
  10.     // but the driver compensates and makes it XYZ  
  11.     coords = myAccelrCompass.getRawCoorData();  
  12.     // Print out the X, Y, and Z coordinate data using two different methods  
  13.     outputStr = "coor: rX " + coords.getitem(0) + " - rY " + coords.getitem(1) + " - rZ " + coords.getitem(2);  
  14.     console.log(outputStr);  
  15.     outputStr = "coor: gX " + myAccelrCompass.getCoorX() + " - gY " + myAccelrCompass.getCoorY() + " - gZ " + myAccelrCompass.getCoorZ();  
  16.     console.log(outputStr);  
  17.     // Get and print out the heading  
  18.     console.log("heading: " + myAccelrCompass.getHeading());  
  19.     // Get the acceleration  
  20.     myAccelrCompass.getAcceleration();  
  21.     accel = myAccelrCompass.getRawAccelData();  
  22.     // Print out the X, Y, and Z acceleration data using two different methods  
  23.     outputStr = "acc: rX " + accel.getitem(0) + " - rY " + accel.getitem(1) + " - Z " + accel.getitem(2);  
  24.     console.log(outputStr);  
  25.     outputStr = "acc: gX " + myAccelrCompass.getAccelX() + " - gY " + myAccelrCompass.getAccelY() + " - gZ " + myAccelrCompass.getAccelZ();  
  26.     console.log(outputStr);  
  27.     console.log(" ");  
  28. }, 1000);  
  29. // Print message when exiting  
  30. process.on('SIGINT', function ()  
  31. {  
  32.     clearInterval(myInterval);  
  33.     myAccelrCompass = null;  
  34.     accelrCompassSensor.cleanUp();  
  35.     accelrCompassSensor = null;  
  36.     console.log("Exiting");  
  37.     process.exit(0);  
  38. });  
Code for turning on the flashlight with button press
  1. var groveSensor = require('jsupm_grove');  
  2. // Create the button object using GPIO pin 0  
  3. var button = new groveSensor.GroveButton(2);  
  4. // Read the input and print, waiting one second between readings  
  5. function readButtonValue()  
  6. {  
  7.     console.log(button.name() + " value is " + button.value());  
  8.     var v = button.value();  
  9.     if (v == 1)  
  10.     {  
  11.         led.on();  
  12.     }  
  13.     if (v == 0)  
  14.     {  
  15.         led.off();  
  16.     }  
  17. }  
  18. setInterval(readButtonValue, 1000);  
Sending data to Cloud
  1. var ubidots = require('ubidots');  
  2. var client = ubidots.createClient('YOUR-API-KEY');  
  3.       client.auth(function ()  
  4. {  
  5.     this.getDatasources(function (err, data)  
  6.     {  
  7.         console.log(data.results);  
  8.     });  
  9.     var ds = this.getDatasource('xxxxxxxx');  
  10.     ds.getVariables(function (err, data)  
  11.     {  
  12.         console.log(data.results);  
  13.     });  
  14.     ds.getDetails(function (err, details)  
  15.     {  
  16.         console.log(details);  
  17.     });  
  18.     var v = this.getVariable('xxxxxxx');  
  19.     v.getDetails(function (err, details)  
  20.     {  
  21.         console.log(details);  
  22.     });  
  23.     v.getValues(function (err, data)  
  24.     {  
  25.         console.log(data.results);  
  26.     });  
  27.       }  
Here I am using Ubidots for IoT cloud, with Ubidots we can visualizing the data in an effective way. It supports a wide range of devices and can also trigger some actions like sending mails and messages. It also offers number of API to speed our development with the language of our choice. Hence I have chosen its Node.Js library to interact with my Edison.
 
Setting up Ubidots Cloud
  1. Log in to your Ubidots account or you can create one here.
     
  2. Select the “Sources” tab and then click on “Add Data Source” to create a new data source. Here I have added My Edison.
     
    Add Data Source
     
    Figure 15: Adding Data Source
     
  3. Once the data source is created we have to add variables to it. Here in this project we are going to send Temperature data, hence we will create a single variable.
     
  4. Click on the variable and copy the variable ID. Paste this in your code.
     
    Variable ID
     
    Figure 16: Variable ID
     
  5. Select My Profile->API Keys. Get your API Key from here.
     
    API Key
     
    Figure 17: API Key
     
  6. On your Dashboard add a widget of your choice, depends on how you want to visualize the data.
     
  7. I have chosen a line chart and table values for the temperature sensor. By looking at the Table values you can easily determine at the last value of temperature and with Graph, you can evaluate a sudden variation in temperature.
Working
 
You will need to create a Twilio account for sending the messages. Copy the API key in the code that you get from the Twilio account. Build, Upload and Run your app on Edison. It will download the NPM modules and upload the current project to Edison. While working with Intel XDK IoT edition you need an active internet connection.
 
XDK IoT edition
 
Figure 18: Build, Upload, Run
 
You will see the sensor values in the debug console, if everything works fine you will notice data being send to Ubidots cloud and message send to mobile phone with touch. Press the button and this will turn on the flashlight that will be useful to see you in the dark and the display will show current time and temperature.
 
Current time and Temperature
 
Figure 19: Current time and Temperature
 
Navigate to Ubidots dashboard, you will see all the data sent from the sensor in our widgets. You can see the last value recorded by the temperature sensor and a line graph about variations. Here I have also created some alerts, if the temperature level exceeds up to a certain level (an alert will send to our mobile phone through SMS).
 
 IoT Devise
 
Figure 20: Console log
 
Now when we touch on the touch sensor a text message is sent to my mobile phone immediately. I have used the Twilio trial account, so they have added some other text with the SMS. If you will get a paid account you won't see any Twilio advertisements.
 
Twilio advertisements
 
Figure 21: Visualized data on the cloud
 
 
Figure 22 : SMS on my mobile phone