Mark Easley
Published

UTD IEEE Innovation Week: MSP432 IoT Workshop

Building your own Internet of Things (IoT) device can be easy with the MSP432 LaunchPad + SimpleLink Wi-Fi® CC3100 + EDUMKII BoosterPack.

BeginnerFull instructions provided1,414
UTD IEEE Innovation Week: MSP432 IoT Workshop

Things used in this project

Story

Read more

Code

Twitter_stick.ino

C/C++
///
/// @mainpage	LCD_Joystick
///
/// @details	Joystick controlled cursor
/// @n
/// @n @a		Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author		Rei Vilo
/// @author		http://embeddedcomputing.weebly.com
/// @date		11/12/2013 10:19
/// @version	101
///
/// @copyright	(c) Rei Vilo, 2013
/// @copyright	CC = BY SA NC
///
/// @see		ReadMe.txt for references
///


///
/// @file		LCD_Joystick.ino
/// @brief		Main sketch
///
/// @details	Joystick controlled cursor
/// @n @a		Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author		Rei Vilo
/// @author		http://embeddedcomputing.weebly.com
/// @date		11/12/2013 10:19
/// @version	101
///
/// @copyright	(c) Rei Vilo, 2013
/// @copyright	CC = BY SA NC
///
/// @see		ReadMe.txt for references
/// @n
///
#define ENERGIA

// Core library for code-sense
#if defined(ENERGIA) // LaunchPad MSP430, Stellaris and Tiva, Experimeter Board FR5739 specific
#include "Energia.h"
#else // error
#error Platform not defined
#endif

#define TEMBOO_ACCOUNT "yertnamreg"  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // Your Temboo app name
#define TEMBOO_APP_KEY "2b3c97ee293947dfa10c8b9621016a3f"  // Your Temboo app key

#define WIFI_SSID "AndroidAP"


// Prototypes


// Include application, user and local libraries
#include <SPI.h>

#include <LCD_screen.h>
#include <LCD_screen_font.h>
#include <LCD_utilities.h>
#include <Screen_HX8353E.h>
#include <Terminal12e.h>
#include <Terminal6e.h>
#include <Terminal8e.h>


#include <WiFi.h>
#include <WiFiClient.h>

#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information


Screen_HX8353E myScreen;
WiFiClient client;
TembooChoreo StatusesUpdateChoreo(client);



// Define variables and constants
#define joystickX 2
#define joystickY 26
uint16_t x, y, x00, y00;
uint16_t colour;
uint32_t z;


// Add setup code
void setup()
{
  
    int wifiStatus = WL_IDLE_STATUS;

    Serial.begin(9600);
 
    // By default MSP432 has analogRead() set to 10 bits. 
    // This Sketch assumes 12 bits. Uncomment to line below to set analogRead()
    // to 12 bit resolution for MSP432.
    analogReadResolution(12);

    myScreen.begin();
    x00 = 0;
    y00 = 0;
    
    // Determine if the WiFi Shield is present
    Serial.print("\n\nShield:");
    if (WiFi.status() == WL_NO_SHIELD) {
      Serial.println("FAIL");

      // If there's no WiFi shield, stop here
      while(true);
    }
  
    // Try to connect to the local WiFi network
    while(wifiStatus != WL_CONNECTED) {
      Serial.print("WiFi:");
      wifiStatus = WiFi.begin(WIFI_SSID);
      if (wifiStatus == WL_CONNECTED) {
        Serial.println("OK");
      } else {
        Serial.println("FAIL");
      }
      delay(5000);
    }

    
}

void configureTemboo(void)
{

    // Invoke the Temboo client
    StatusesUpdateChoreo.begin();

    // Set Temboo account credentials
    StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
    StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String AccessTokenValue = "3361531038-PfYFeP3r9ykZ9hZzWCcsaQp4AHSHAX0BcBbVQ2K";
    StatusesUpdateChoreo.addInput("AccessToken", AccessTokenValue);
    String AccessTokenSecretValue = "RzlVqDmPHKaD1L315bvJ2MqhKfJW7Zsr76YfkomuKrL2a";
    StatusesUpdateChoreo.addInput("AccessTokenSecret", AccessTokenSecretValue);
    String ConsumerSecretValue = "f1S7cqL2aJi3HVyFOnQ9wCihao0080OIQxm0rpp41AB1yc91xJ";
    StatusesUpdateChoreo.addInput("ConsumerSecret", ConsumerSecretValue);
    String ConsumerKeyValue = "oa1pgd6ibazJFOa8X9Gp5BrmF";
    StatusesUpdateChoreo.addInput("ConsumerKey", ConsumerKeyValue);

    // Identify the Choreo to run
    StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");  
  
}

void tweetData(int x, int y)
{
    //Update text
    String StatusUpdateValue = "Look ma, I'm on twitter! x=" + i32toa(x) + " y=" + i32toa(y);
    StatusesUpdateChoreo.addInput("StatusUpdate", StatusUpdateValue);

    // Run the Choreo
    StatusesUpdateChoreo.run();
    

    //StatusesUpdateChoreo.close();
  
  
}

// Add loop code
void loop()
{
    x = map(analogRead(joystickX), 0, 4096, 0, 128);
    y = map(analogRead(joystickY), 0, 4096, 128, 0);
    if (x < 1)      x = 1;
    if (x > 126)    x = 126;
    if (y < 1)      y = 1;
    if (y > 126)    y = 126;
    
    if ((x00 != x) || (y00 != y)) {
        z = (uint32_t)((x-64)*(x-64)+(y-64)*(y-64)) >> 8;
        if (z > 4)      colour = redColour;
        else if (z > 1) colour = yellowColour;
        else            colour = greenColour;
        
        myScreen.dRectangle(x00-1, y00-1, 3, 3, blackColour);
        myScreen.dRectangle(x-1, y-1, 3, 3, colour);
        x00 = x;
        y00 = y;
    }
    
    
    myScreen.gText(0, myScreen.screenSizeY()-myScreen.fontSizeY(),
                   "x=" + i32toa((int16_t)x-64, 10, 1, 6) +" y=" + i32toa(64-(int16_t)y, 10, 1, 6),
                   colour);
                   
   if(digitalRead(32)){
     tweetData((int16_t)x-64, 64-(int16_t)y);  
     
     
     
   }
}

Credits

Mark Easley

Mark Easley

65 projects • 137 followers
Texas Instruments LaunchPad SW Engineer

Comments