Updating the Orbotix Sphero* in response to tweets using the Intel® Edison board

This guide contains steps to have your Orbotix Sphero* check Twitter and change its colored lights in response to new tweets posted using the hashtag #intelmaker.


You must have:

This section contains steps to create a new project in the Intel XDK, with the appropriate code to update your Sphero.

  1. In the Intel XDK, click the Projects tab. Click Start a New Project.

    Click Start a New Project

  2. Under Internet of Things Embedded Application, click Templates.
  3. Click Blank Template, then click Continue.
  4. In the Project Name field, type a name for your project and click Create.

    Type a name for your project and click Create

  5. Your new project opens, with the main.js file displayed. Delete the contents of main.js and paste the following code into the file:
    var twitter = require('mtwitter');
    var colors = require('colors');
    var moment = require('moment');
    var spheron = require('spheron');
    var sphero = spheron.sphero();
    var spheroPort = '/dev/rfcomm0';
    var COLORS = spheron.toolbelt.COLORS;
    var newMessage = false;
    var lastTweet = '21:35:5';
    var twit = new twitter({
        consumer_key : 'xxxxxxxxxxxxxxxxxxxxx',
        consumer_secret : 'xxxxxxxxxxxxxxxxxxxxx',
        access_token_key : 'xxxxxxxxxxxxxxxxxxxxx',
        access_token_secret : 'xxxxxxxxxxxxxxxxxxxxx'
    setInterval(function() {
        twit.get('search/tweets', {q: '#intelmaker'}, function(err, item) {
            console.log(item.statuses[0].created_at.substring(11, 18).cyan)
            console.log("From isNew(): ", newMessage);
            if(item.statuses[0].created_at.substring(11, 18) === lastTweet) {
                console.log("we here");
                newMessage = false;
                newMessage = true
                lastTweet = item.statuses[0].created_at.substring(11, 18);
     }, 1000);
     function updateSphero(flag)
        console.log('updating sphero');
        sphero.on('open', function() {
            sphero.setRGB(COLORS.RED, false);
            setTimeout(function(){sphero.setRGB(COLORS.BLUE, false);}, 2000);
  6. From the left, select package.json. In the dependencies section, be sure to add an entry for each of the modules required by the code:
            "dependencies": {
    Add the required modules to the dependencies section.

This section contains steps to create a new Twitter app and retrieve the appropriate keys to allow your code to interact with Twitter.

  1. Navigate to the Twitter Apps site at https://apps.twitter.com/ and sign in using your Twitter account.
  2. Click Create New App. The Create an application page opens.

    Click Create New App

  3. On the Create an application page, do the following:
    1. Type your name in the Name field.
    2. Type a description of your app in the Description field.
    3. Type a placeholder URL in the Website field.
    Supply your name, app description, and a placeholder URL

  4. Read the terms and conditions of use, then select the Yes, I agree check box. Click Create your Twitter application.

    Terms and conditions to create your Twitter application
  5. Click the Keys and Access Tokens tab.

    Click the Keys and Access Tokens tab

  6. In the Application Settings section, copy and paste the consumer key from the Consumer Key (API Key) field and the consumer secret from the Consumer Secret (API Secret) field into a separate text editing program, such as Notepad.

    Copy and save the consumer key and consumer secret
  7. In the Your Access Token section, click Create my access token.

    Click Create my access token

  8. Copy and paste the access token key from the Access Token fieldand the access token secret from the Access Token Secret field into your text editing program.

    Copy and save the access token key and access token secret

  9. In the Intel XDK, navigate to the line that begins with consumer_key. Replace the placeholder text in the code with the consumer key, consumer secret, access token, and access token secret.

    Supply the consumer key, consumer secret, access token key, and access token secret

This section contains steps to connect your board to Sphero using Bluetooth*.

  1. Connect to your board in a serial communication window.
  2. To activate Bluetooth and scan for Bluetooth-enabled devices, enter the following commands:
    rfkill unblock bluetooth

  3. The MAC address of your Sphero should be displayed at the bottom of the Sphero's box, in the format XX-XX-XX-XX-XX-XX. If you cannot locate the Sphero's MAC address, do the following:
    1. Enter the command:
      scan on
    2. Locate your Sphero in the list and copy the MAC address.
    3. Enter the command:
      scan off
  4. Pair your board with the Sphero by entering the following commands:
    pair SpheroMacAddress
    rfcomm bind 0 SpheroMacAddress 1

    The MAC address should be in the format XX:XX:XX:XX:XX:XX. This will create a Sphero connection.

This section contains steps to build, upload, and run your code. After completing the steps, the color of your Sphero will change in response to tweets.

  1. In the bottom toolbar, click the Upload icon Upload icon to upload the project to your board.
  2. Click the Run icon Run iconto run your project. Your Sphero checks Twitter once a second and turns blue when someone tweets using the hashtag #intelmaker.
Для получения подробной информации о возможностях оптимизации компилятора обратитесь к нашему Уведомлению об оптимизации.