Trey German
Created August 28, 2015

MSP432 IoT Workshop: Fall 2015

Learn LaunchPad by building incredible IoT applications. Awesome!

BeginnerFull instructions provided1,910
MSP432 IoT Workshop: Fall 2015

Things used in this project

Story

Read more

Code

LCD_Joystick + Twitter

C/C++
Example applications that tweets the X,Y position of the joystick on the Educational BoosterPack
///
/// @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 "XXXXXXX"  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "XXXXXXX"  // Your Temboo app name
#define TEMBOO_APP_KEY "XXXXXXX"  // Your Temboo app key

#define WIFI_SSID "XXXXXXX"


// 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);  
     
     
     
   }
}

Screen_HX8353E.cpp LCD Driver fix for MSP432

C/C++
The LCD drive is missing a #define to enable support for the MSP432 LaunchPad. Dropping this file into:
\energia-0101E0016\hardware\msp432\libraries\EduBPMKII_Screen
will fix the bug.
//
// Screen_HX8353E.cpp
// Library C++ code
// ----------------------------------
// Developed with embedXcode
// http://embedXcode.weebly.com
//
// Project new_screen_HX8353
//
// Created by Rei VILO, mars 07, 2013 09:21
// embedXcode.weebly.com
//
// Apr 25, 2014
// Support for new LaunchPads with
// . MSP430F5529
// . LM4F120H5QR TM4C123GH6PM
// . TM4C1294NCPDT TM4C1294XNCZAD
//
//
// Copyright  Rei VILO, 2013-2014
// License CC = BY NC SA
//
// See Screen_HX8353E.h and ReadMe.txt for references
//
// Library header
#include "Screen_HX8353E.h"
///
#define HX8353E_WIDTH  128
#define HX8353E_HEIGHT 128
#define HX8353E_MADCTL_MY  0x80
#define HX8353E_MADCTL_MX  0x40
#define HX8353E_MADCTL_MV  0x20
#define HX8353E_MADCTL_ML  0x10
#define HX8353E_MADCTL_RGB 0x08
#define HX8353E_MADCTL_MH  0x04
#define HX8353E_NOP     0x00
#define HX8353E_SWRESET 0x01
#define HX8353E_RDDID   0x04
#define HX8353E_RDDST   0x09
#define HX8353E_SLPIN   0x10
#define HX8353E_SLPOUT  0x11
#define HX8353E_PTLON   0x12
#define HX8353E_NORON   0x13
#define HX8353E_INVOFF  0x20
#define HX8353E_INVON   0x21
#define HX8353E_GAMSET  0x26
#define HX8353E_DISPOFF 0x28
#define HX8353E_DISPON  0x29
#define HX8353E_CASET   0x2A
#define HX8353E_RASET   0x2B
#define HX8353E_RAMWR   0x2C
#define HX8353E_RGBSET  0x2d
#define HX8353E_RAMRD   0x2E
#define HX8353E_PTLAR   0x30
#define HX8353E_MADCTL  0x36
#define HX8353E_COLMOD  0x3A
#define HX8353E_SETPWCTR 0xB1
#define HX8353E_SETDISPL 0xB2
#define HX8353E_FRMCTR3  0xB3
#define HX8353E_SETCYC   0xB4
#define HX8353E_SETBGP   0xb5
#define HX8353E_SETVCOM  0xB6
#define HX8353E_SETSTBA  0xC0
#define HX8353E_SETID    0xC3
#define HX8353E_GETHID   0xd0
#define HX8353E_SETGAMMA 0xE0
Screen_HX8353E::Screen_HX8353E() {
#if defined(__LM4F120H5QR__) || defined(__MSP430F5529__) || defined(__TM4C123GH6PM__) || defined(__TM4C1294NCPDT__) || defined(__TM4C1294XNCZAD__) || defined(__MSP432P401R__)
    _pinReset          = 17;
    _pinDataCommand    = 31;
    _pinChipSelect     = 13;
    _pinBacklight      = NULL;
#else
#error Platform not supported
#endif
}
Screen_HX8353E::Screen_HX8353E(uint8_t resetPin, uint8_t dataCommandPin, uint8_t chipSelectPin, uint8_t backlightPin)
{
    _pinReset = resetPin;
    _pinDataCommand = dataCommandPin;
    _pinChipSelect = chipSelectPin;
    _pinBacklight = backlightPin;
};
void Screen_HX8353E::begin()
{
#if defined(__LM4F120H5QR__)
    SPI.setModule(2);
#endif
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV2);
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    if (_pinReset!=NULL) pinMode(_pinReset, OUTPUT);
    if (_pinBacklight!=NULL) pinMode(_pinBacklight, OUTPUT);
    pinMode(_pinDataCommand, OUTPUT);
    pinMode(_pinChipSelect, OUTPUT);
    if (_pinBacklight!=NULL) digitalWrite(_pinBacklight, HIGH);
    if (_pinReset!=NULL) digitalWrite(_pinReset, 1);
    delay(100);
    if (_pinReset!=NULL) digitalWrite(_pinReset, 0);
    delay(50);
    if (_pinReset!=NULL) digitalWrite(_pinReset, 1);
    delay(120);
    _writeCommand(HX8353E_SWRESET);
    delay(150);
    _writeCommand(HX8353E_SLPOUT);
    delay(200);
    _writeRegister(HX8353E_GAMSET, 0x04);
    _writeCommand(HX8353E_SETPWCTR);
    _writeData88(0x0A, 0x14);
    _writeCommand(HX8353E_SETSTBA);
    _writeData88(0x0A, 0x00);
    _writeRegister(HX8353E_COLMOD, 0x05);
    delay(10);
    _writeRegister(HX8353E_MADCTL, HX8353E_MADCTL_RGB);
    _writeCommand(HX8353E_CASET);
    _writeData8888(0x00, 0x00, 0x00, 0x79);
    _writeCommand(HX8353E_RASET);
    _writeData8888(0x00, 0x00, 0x00, 0x79);
    _writeCommand(HX8353E_NORON);
    delay(10);
    _writeCommand(HX8353E_DISPON);
    delay(120);
    _writeCommand(HX8353E_RAMWR);
    setBacklight(true);
    setOrientation(0);
    _screenWidth  = HX8353E_WIDTH;
    _screenHeigth = HX8353E_HEIGHT;
    _penSolid  = false;
    _fontSolid = true;
    _flagRead  = false;
    _touchTrim = 0;
    clear();
}
String Screen_HX8353E::WhoAmI()
{
    return "LCD MKII BoosterPack";
}
void Screen_HX8353E::invert(boolean flag)
{
    _writeCommand(flag ? HX8353E_INVON : HX8353E_INVOFF);
}
void Screen_HX8353E::setBacklight(boolean flag)
{
    if (_pinBacklight!=NULL) digitalWrite(_pinBacklight, flag);
}
void Screen_HX8353E::setDisplay(boolean flag)
{
    if (_pinBacklight!=NULL) setBacklight(flag);
}
void Screen_HX8353E::setOrientation(uint8_t orientation)
{
    _orientation = orientation % 4;
    _writeCommand(HX8353E_MADCTL);
    switch (_orientation) {
        case 0:
            _writeData(HX8353E_MADCTL_MX | HX8353E_MADCTL_MY | HX8353E_MADCTL_RGB);
            break;
        case 1:
            _writeData(HX8353E_MADCTL_MY | HX8353E_MADCTL_MV | HX8353E_MADCTL_RGB);
            break;
        case 2:
            _writeData(HX8353E_MADCTL_RGB);
            break;
        case 3:
            _writeData(HX8353E_MADCTL_MX | HX8353E_MADCTL_MV | HX8353E_MADCTL_RGB);
            break;
    }
}
void Screen_HX8353E::_fastFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t colour)
{
    if (x1 > x2) _swap(x1, x2);
    if (y1 > y2) _swap(y1, y2);
    _setWindow(x1, y1, x2, y2);
    digitalWrite(_pinDataCommand, HIGH);
    digitalWrite(_pinChipSelect, LOW);
    uint8_t hi = highByte(colour);
    uint8_t lo = lowByte(colour);
    for (uint32_t t=(uint32_t)(y2-y1+1)*(x2-x1+1); t>0; t--) {
        SPI.transfer(hi);
        SPI.transfer(lo);
    }
    digitalWrite(_pinChipSelect, HIGH);
}
void Screen_HX8353E::_setPoint(uint16_t x1, uint16_t y1, uint16_t colour)
{
    if( (x1 < 0) || (x1 >= screenSizeX()) || (y1 < 0) || (y1 >= screenSizeY()) ) return;
    _setWindow(x1, y1, x1+1, y1+1);
    _writeData16(colour);
}
void Screen_HX8353E::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
    switch (_orientation) {
        case 0:
            x0 += 2;
            y0 += 3;
            x1 += 2;
            y1 += 3;
            break;
        case 1:
            x0 += 3;
            y0 += 2;
            x1 += 3;
            y1 += 2;
            break;
        case 2:
            x0 += 2;
            y0 += 1;
            x1 += 2;
            y1 += 1;
            break;
        case 3:
            x0 += 1;
            y0 += 2;
            x1 += 1;
            y1 += 2;
            break;
        default:
            break;
    }
    _writeCommand(HX8353E_CASET);
    _writeData16(x0);
    _writeData16(x1);
    _writeCommand(HX8353E_RASET);
    _writeData16(y0);
    _writeData16(y1);
    _writeCommand(HX8353E_RAMWR);
}
void Screen_HX8353E::_writeRegister(uint8_t command8, uint8_t data8)
{
    _writeCommand(command8);
    _writeData(data8);
}
void Screen_HX8353E::_writeCommand(uint8_t command8)
{
    digitalWrite(_pinDataCommand, LOW);
    digitalWrite(_pinChipSelect, LOW);
    SPI.transfer(command8);
    digitalWrite(_pinChipSelect, HIGH);
}
void Screen_HX8353E::_writeData(uint8_t data8)
{
    digitalWrite(_pinDataCommand, HIGH);
    digitalWrite(_pinChipSelect, LOW);
    SPI.transfer(data8);
    digitalWrite(_pinChipSelect, HIGH);
}
void Screen_HX8353E::_writeData16(uint16_t data16)
{
    digitalWrite(_pinDataCommand, HIGH);
    digitalWrite(_pinChipSelect, LOW);
    SPI.transfer(highByte(data16));
    SPI.transfer(lowByte(data16));
    digitalWrite(_pinChipSelect, HIGH);
}
void Screen_HX8353E::_writeData88(uint8_t dataHigh8, uint8_t dataLow8)
{
    digitalWrite(_pinDataCommand, HIGH);
    digitalWrite(_pinChipSelect, LOW);
    SPI.transfer(dataHigh8);
    SPI.transfer(dataLow8);
    digitalWrite(_pinChipSelect, HIGH);
}
void Screen_HX8353E::_writeData8888(uint8_t dataHigh8, uint8_t dataLow8, uint8_t data8_3, uint8_t data8_4)
{
    _writeData(dataHigh8);
    _writeData(dataLow8);
    _writeData(data8_3);
    _writeData(data8_4);
}
void Screen_HX8353E::_getRawTouch(uint16_t &x0, uint16_t &y0, uint16_t &z0)
{
    x0 = 0;
    y0 = 0;
    z0 = 0;
}

getMAC

C/C++
This program will retrieve the MAC address from your CC3100. This is used to register the device on some networks with increased security.
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>

void setup()
{
  // put your setup code here, to run once:

  Serial.begin(115200);
  
    // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(":");
  Serial.print(mac[4], HEX);
  Serial.print(":");
  Serial.print(mac[3], HEX);
  Serial.print(":");
  Serial.print(mac[2], HEX);
  Serial.print(":");
  Serial.print(mac[1], HEX);
  Serial.print(":");
  Serial.println(mac[0], HEX);

  
}

void loop()
{
  // put your main code here, to run repeatedly:
  
}

Workshop Slides

Plain text
Powerpoint Slides
No preview (download only).

Credits

Trey German

Trey German

10 projects • 33 followers
Freelance Engineer, hacker, sky junkie, programmer, designer. All projects are my own.
Thanks to Robert Wessels.

Comments