Introduction: PIC KICK TWEET !

About: ENTESLA is an Embedded Systems Design and Solution provider based in Mumbai,India.
This is an Instructable showing you how to integrate Twitter in your embedded application. Watch this Instructable in Action https://www.instructables.com/id/PIC-KICK-TWEET-1/

Working: A desktop application is created with ease for grabbing the latest tweet from your twitter account. The application then forwards the tweet to the serial port to which the embedded device is connected. A firmware is written to capture the tweet sent by the application. The tweet is displayed on the 16x2 CLCD on the embedded device.

Stuffs your need to complete this Instructable with ease:

  1. A Workstation with a USB port.
  2. Internet connectivity for the Workstation.
  3. A Twitter account from which the tweets are to becaptured.
  4. Processing IDE for creating the desktop application.
  5. MPLABX IDE with C18 compiler for writing the firmware for the microcontroller.
  6. A PIC KICK development board from www.entesla.com.
  7. Enthusiasm.
For Beginners I would like to brief you to about Processing, MPLABX and PIC KICK....

Processing (or processing.org as known on the web) is a an opensource programming language and environment for people who want to create animations and interactions with a variety of devices and other applications with ease. Initially targeted at artists and designers with no prior programming experience for prototyping, today it is also used by students, researchers, hobbyist and  even professionals to rapidly prototype their ideas by making desktop applications without breaking a sweat. The language is itself based on the popular programming language Java but you need not know Java to start Processing. Processing runs on Windows® OS, MAC® OS and Linux.

MPLABX IDE is a graphical, debugging toolset for all of Microchip's product line of microcontrollers and memory devices.It includes a feature-rich editor, source-level debugger, project manager, software simulator, and supports Microchip’s popular hardware tools.Based on the open-source NetBeans platform, MPLAB X runs on Windows® OS, MAC® OS and Linux, supports many third-party tools, and is compatible with many NetBeans plug-ins.

PIC KICK is an embedded system development board by ENTESLA for Microchip’s 40 pin 8-bit microcontroller. It is a low cost kick start board designed to help professionals, students and amateurs to explore the capability of PIC16, PIC18 architecture and practice application development for various interfaces with minimal hardware reconfiguration. It features a USB-Serial converter on-board, leds,buttons,16x2 Character LCD, Analog Input using a potentiometer and USB. It comes pre-programmed with the ds30Bootloader which makes it easy to program via usb-serial port. And yes.. you can power it using your workstation's USB port.


Step 1: Setup Your Twitter

  1. If you already have a twitter account jump to the developers page for twitter at https://dev.twitter.com/  If you do not have a twitter account create one and jump to the developers page.
  2. Sign In to your twitter account from the developers page.
  3. Create a new application as shown in the image.
  4. Describe your application to twitter.
  5. Goto the Settings tab. Under Application Type select Access type to Read,Write and Access direct Messages. Wait for a couple of minutes and check if the change has been reflected in the Details tab.
  6. Twitter uses OAUTH authentication protocol for authenticating applications before they access a twitter account. More about OAUTH at https://dev.twitter.com/docs/auth/oauth/faq
  7. Once the Access type has been changes Create Access tokens for the application under the Details tab.
  8. It may take a moment to generate the Access tokens. Once created, goto the OAUTH tool tab to find the keys that you need for authenticating the application that you will be making it the next few steps. Copy these keys to your notepad. Do not share these keys with others.
Download the attached images to clearly view the steps mentioned above.

The most critical step is done now. You now need to create you application before you can start accessing the tweets!

Step 2: Firmware for PIC KICK in MPLABX

As mentioned before, we are going to display the tweets on the 16x2 CLCD present on the PIC KICK development board. To accomplish this you need to write a firmware for interfacing the on-board PIC18f4520 microcontroller with CLCD and routines for transmitting and receiving data on the UART. This seems to be a challenging job for beginners. Thankfully ENTESLA provides libraries with demo codes for these peripherals. The user can use these libraries as reference or use them in their applications for rapid prototyping.

If you are eager to set the PIC KICK in action without making any changes in the firmware jump to the next step..otherwise..

The ready-to-use code for the twitter application project for PIC18f4520 can be found as a .zip attachment to this Step. The code works with MPLABX and C18 compiler. You need to download MPLABX with the C18 compiler and install it before you want to make changes to the firmware.

The firmware provided is pretty straight forward and is well commented.



Step 3: Flashing the Microcontroller

The PIC KICK development board comes pre-programmed with the ds30 bootloader. You can flash the microcontroller with the code easily via the USB-UART bridge on-board. You need not buy/build a separate programmer. 
  1. Download the utility used to program the PIC microcontroller.
  2. Download the .hex file to flash the microcontroller from the attachment to this Step.
  3. Execute the ds30 Loader GUI found in the downloaded folder.
  4. Configure the utility with the COM port number assigned to the PIC KICK development board from device manager.
  5. Configure the Device as PIC18f4520 and Baudrate as 9600.
  6. Click Program. You may have to press the RESET button on the PIC KICK board to invoke the ds30Bootloader.

Step 4: Creating the Twitter App Using Processing.org

  1. Download the Processing Environment from http://processing.org/download/ . If you do not have the latest Java environment installed on your workstation download it along the Processing Environment.I am currently using Processing 1.5.1.
  2. Download the sample code for twitter application from the .zip attachment here. Extract it to an accessible location.
  3. Open the Twiiter_App file from the downloaded folder using the processing.exe application downloaded from www.processing.org
  4. Enter the respective keys noted in your Twitter account as in Step 1. into the respective string variables between the double quotes in the Twiiter_App code.
The draw function is like your main function in C language. All the steps mentioned within draw() here will executed infinitely. Your twitter account,application window and the serial port are setup in the setup() function.

void draw()
{
    //Retrieve Last Tweet
    lastTweet=readMsg(1);
   
    //Compare it with last tweet
    if(tempTweet.equals(lastTweet)==false) 
    {
      tempTweet=lastTweet;
      //Write to console
      println(lastTweet);  //for debugging
      //Write to Serial port     
      myPort.write(lastTweet);  //Send the string to serial port
      //postMsg(msgOut);   
    }
    else
    {
 
    }
    delay(20000);  //Refresh every 20 seconds
}

Step 5: Lets TWEET !

Ok.. Before we start to Tweet here are the things you've got to ensure you have done..
  1. Flash the PIC KICK with the .hex provided.
  2. The PIC KICK development board is connected to the USB port of you workstation. Ensure that the device manager shows  the PIC KICK as COM1. Change the COM port number to COM1 if shown a different number.
  3. The String variables of the authentication keys in the Twitter application code is changed to the respective keys of your twitter account.
  4. The Workstation is connected to the Internet.
Open the Twitter_App code in the Processing Environment and Click RUN. The Twitter_App window will be created if the code runs successfully. Your application is ready to communicate with the your online twitter account and PIC KICK. Kindly recheck the above steps if an error is shown.

References:


http://robotgrrl.com
http://twitter4j.org
http://www.microchip.com
http://twitter.com
http://processing.org