Connecting CC3200 to internet via Proxy Server with authentication

 

DSC02320If you have unrestricted internet access then this example will work right out of the box. But that is not the case with me, i am behind a proxy server. Hence in this post i will tell you how i worked around this problem in details.
The example we will be using is “WifiWebClient” example.
If you upload the code then you will see that it fails to connect. Now if you read How Proxy Servers work then you will realize that instead of connecting directly to the required server/page you actually need to connect to the proxy server and request it to fetch the required data from the webpage for you.

Diagram of two computers connected only via a proxy server. The first computer says to the proxy server: "ask the second computer what the time is".

Hence in the “server” variable we will write the IP of our proxy server which in my case is 202.141.80.24. Now the port information is also very important. The default port used in the code is 80 but you might need to change it according to your needs, in my case it is 3128 as specified to us by the university. Now its time to upload the code and check what happens.


#ifndef __CC3200R1M1RGC__
#include <SPI.h>
#endif
#include <WiFi.h>

// your network name also called SSID
char ssid[] = "******";
// your network password
char password[] = "*****;

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(202,141,80,24);  // numeric IP for Google (no DNS)
WiFiClient client;

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);

// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(300);
}

Serial.println("\nYou're connected to the network");
Serial.println("Waiting for an ip address");

while (WiFi.localIP() == INADDR_NONE) {
// print dots while we wait for an ip addresss
Serial.print(".");
delay(300);
}

Serial.println("\nIP Address obtained");
printWifiStatus();

Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 3128)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /hello.html HTTP/1.1");
client.println("Host: energia.nu");
client.println("Connection: close");
client.println();
}
}

void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();

// do nothing forevermore:
while (true);
}
}


void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

On the serial monitor this is what i saw -> we get a 400:bad request error.

400: Bad RequestAfter some researching on that issue i came across this wonderful page. According to this page , when requesting through a proxy the GET request must be absolute.

direct_vs_proxy
The absoluteURI form is required when the request is being made to a proxy.
Proxy server will convert absolute URI to relative URI.

 

Note: We are connecting to energia.nu/hello.html in this example which just displays “Hello world!”.

 

 

Hence we need to enter the absolute URI of the  page, for that we change that code to —


client.println("GET http://energia.nu/hello.html HTTP/1.1");

After uploading i got this -> The authentication 407 error.

407:Proxy AuthenticationWe are making some progress aren’t we !!.

Now we need to figure out how to send the authentication data in the http request as well.

So upon reading the HTTP1.1 manual i saw that the proxy authentication data goes as another header which is like this -> Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Here is a list of all the headers. Scroll down to approximately 1/3rd of the page to see this –

Proxy headerNow the important thing to understand is that your details go in this format : Proxy-Authorization: Basic username:password. But the “username:password” string needs to be base64 encoded. You can use any online utility to do that. Maybe something like this .

So i made these changes to the request –


client.println("GET http://energia.nu/hello.html HTTP/1.1");
client.println("Host: energia.nu");
client.println("Proxy-Authorization: Basic your_base64_encoded_details_go_here");
client.println("Connection: close");
client.println();

And voila it worked !!. Here is a screen shot and as you can see the message -> 200: Ok and the “Hello World!” message that the webpage has !.

success

This is how i got my Launchpad to work across proxy !!. Enjoy, till then keep making and hacking !!.

Advertisements
Posted in CC3200, Internet of Things, Proxy Server | Tagged , , , , , , , , | Leave a comment

IoT with CC3200 using UDP packets on LAN

CC3200First of all we need to setup the CC3200 LAUNCHXL. For that visit all the following links and do whatever is written there.

OR just watch this video for the most basic setup.

NOTE: If you already have installed Code Composer Studio and if you checked the box for CC3200 based devices then there is no need to install the device drivers as they have already been installed otherwise you must install the drivers cause without that your device wont be recognized and you wont be able to upload codes.

  • For installing drivers visit this page .
  • If you are a windows 8/8.1 user you will need to disable device signature. Learn how to do that from here .
  • Unfortunately there is a hardware related inconvenience, to work around that you need to use a jumper wire to connect two pins. More info on this page .
  • On the same page as above there is a section on how to upgrade the firmware. I strongly suggest you do that.

Here is a pinout of the CC3200 Launchxl. Note the white line connecting two pins, that is where you need to place the jumper.
LaunchPads-CC3200-—-Pins-Maps-12-28Now, i am behind a corporate proxy which renders almost every example useless. But i am trying to get some of them to work atleast on the LAN.

For this post we will be using the “WifiUdpSendReceiveString” example. For that we will need a piece of software that can send/receive UDP and(or) TCP packets. So i downloaded “Packet Sender” (UDP and TCP network test utility) from here . I downloaded the Portable version, but either the installer or the portable version should work just fine.

I edited the code such a way that whenever i sent a particular string the RED led would glow and YELLOW led would stop glowing and whenever it received something else the vice-versa would happen. Here is the edited code –


#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>

// your network name also called SSID
char ssid[] = "*******";
// your network password
char password[] = "*******";

unsigned int localPort = 2390;      // local port to listen on

char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged"; // a string to send back

char check[255] = "shantam"; // this is the string i send back. i store it here so that i can check it against the received packet.

WiFiUDP Udp;

void setup() {
pinMode(RED_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
//Initialize serial and wait for port to open:
Serial.begin(115200);

// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(300);
}

Serial.println("\nYou're connected to the network");
Serial.println("Waiting for an ip address");

while (WiFi.localIP() == INADDR_NONE) {
// print dots while we wait for an ip addresss
Serial.print(".");
delay(300);
}

Serial.println("\nIP Address obtained");
printWifiStatus();

Serial.println("\nWaiting for a connection from a client...");
Udp.begin(localPort);
}

void loop() {
int count = 0;

// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());

// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
Serial.println("Contents:");
Serial.println(packetBuffer);

// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();

for(int i= 0; i < packetSize; i++)
{
if(packetBuffer[i] == check[i])
{
count++;
}
else

{
count = 60;
}
}
if(count == 7)
{
//Serial.println("GOT IT");
digitalWrite(RED_LED,HIGH);
digitalWrite(YELLOW_LED,LOW);
}

else
{
//Serial.println("INCORRECT PACKET");
digitalWrite(YELLOW_LED,HIGH);
digitalWrite(RED_LED,LOW);
}
}
}

void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}

Packet Sender configuration

This is what it looks like when u run it on windows..

Screenshot (83)The GUI is pretty straightforward to use. Just write the name of the packet in the first box. The contents of the packet itself in the following box in ASCII. The software itself generates the hex codes in the following box. After that you need to write the IP address assigned to the Launchpad in the box just below, for me it was 192.168.89.102. You can check yours by the GUI of the router you are using or by just uploading the code and opening the serial monitor. The Launchpad will print its IP address itself. Adjacent to that you need to write the port over which the communication is happening which as mentioned in the example code is 2390.

pcket sender)As of now i do not own a router and am using “Connectify”. It used to give me a lot of trouble but after upgrading to “PRO” and to the latest version there are no connection drops !!. Well frankly speaking i got that for free as last year they were providing it free to university students !!.

The demonstration video for this should be up by this week. Till then – keep hacking and happy making !!.

Posted in CC3200, Internet of Things | Tagged , , , , , , | Leave a comment

Install Eagle on Ubuntu with its proper Icon

I tried to install eagle on Ubuntu a couple of times and i did succeed but the biggest disappointment was the fact that there was no icon of eagle anywhere. You can search your Dash for eagle and the search results will show you folders. The only way to run eagle was to go to the installed directory, then goto “bin” and finally double click on the pyramid shaped icon named “eagle”  Screenshot from 2015-10-03 09:16:23without any extensions. And it does run !. But alas no way to get that good looking eagle icon on Desktop or on the Launcher. After some research and a lot of trials i found the perfect solution (along with a near perfect solution too! )!!. Here we will only talk about the best solution.

I am assuming you have already installed Eagle on your system. If not then please visit the website and follow the instructions, its pretty easy.

Note: Eagle still dosent run when you type “eagle” in the terminal, but thats not the point of this post and anyways that can be solved by proper environment variables , but once you have a desktop or launcher icon i really see no point in doing that. Okay enough of this preaching, lets see how to do it…

In terminal type this – (you can leave $USER as it is or replace it with your username instead)

sudo gedit /home/$USER/.local/share/applications/eagle.desktop

This is the place where the information about every desktop icon or launcher icon or application icon is kept and “eagle.desktop” is the file that we are creating corresponding to the eagle icon that we want so that Ubuntu gets to know about it. After that you need to write these according to your installation of eagle and save the file.


#!/usr/bin/env xdg-open

[Desktop Entry]
Version=7.4.0
Type=Application
Terminal=false
Icon=/home/shantam/eagle-7.4.0/bin/eagleicon50.png
Name=Eagle
Exec=/home/shantam/eagle-7.4.0/bin/eagle
Comment=Eagle CAD

NOTE:

  • For “Version” mention the version of your installation.
  • For “Icon” you need to provide the path of the eagle icon in the “bin” folder of installation directory.
  • For “Exec” you need to provide the path for that executable that you double clicked on to open eagle in the “bin” folder of installation directory.
  • Rest is pretty self explanatory.

Screenshot from 2015-10-03 09:22:24Once you do that go to your Dash and type “eagle”, the icon should appear. If it dosent then just log out and login once again and you should be good to go !!. Then just click on it and eagle should start. Now you can drag the ico from Dash to your Desktop or you can right click on the eagle icon in Launcher (after running eagle) and click on “Add to favorites” and voila the eagle icon will be fixed !!.

Here is a screenshot of the icon in my Launcher –

Screenshot from 2015-10-03 07:31:01

Posted in Eagle, Uncategorized | Tagged , , , | 1 Comment

Displaying bitmaps on MSP-EXP430F5438

I have been planning to implement some games on the MSP430F5438 Experimenters Board that i have. So my first stop is to learn what the library has to provide. In this post i will tell you how to display bitmaps.After that i will probably implement Conway’s game of life and then i might start writing code for a game.
Video demo –
For starters you will have to download the msp430 graphics library from Ti’s website.
We need to understand that we can display only black and white images . I have a feeling that grey-scale images can also be displayed but as of now i have not tried that.
To display images either you can use the “image-reformer” tool that comes with the library or write a function in which you mention the state of each and every pixel.

Number of colors Bits needed
2 color bitmap 1 bit
4 color bitmap 2 bit
16 color bitmap 4 bit
256 color bitmap 8 bit

But you must understand that although the image-reformer tool is capable of generating proper files for colored images too but the LCD is capable of displaying only greyscale images… so a 256 color bitmap of looks like this but on the LCD looks like this .
Screenshot (38)

 

 

 

This is what the bit map of the same image looks like with different color/bit settings –

Screenshot (36)

Screenshot (37)
Screenshot (38)
There is almost no difference between images of different settings. So i would recommend to go for the 2 color bitmap as it loads the fastest (the higher the number of bits, the slower it gets to load and display the image on the screen).
Here is hackaday logo on 2 bit and 1 bit setting (no difference apparently) –
DSC02270
DSC02269
Now if u are an expert in using CCS then its alright , u already know what to do and how to open the example etc.
But if you are a noob like me then its extremely difficult to get all the correct files by creating a New Project, so as a work around follow these steps –
1. Import the extracted folder into your workspace.
2. Right click on “MSP-EXP430F5438_Grlib_Example” folder and paste it there it self(just do Ctrl+V). Screenshot (41) 3. A dialogue box will open up asking you to fill some particulars…. better change the name of the project, in my case it is “My_msp430f5438_grlib_trial”.
4. Now you are ready to change the “main.c” and other files in your project.

Now select the images that you want to display and rename them properly…. this step is necessary as the image reformer tool will name your variables and constants accordingly in the file that it creates. Then execute the image reformer tool by clicking on the gear icon and the files will be stored wherever u want it to.

After that u need to bring those files to the “images” folder in the folder that you created when you were copying the existing example from the workspace.

Then you need to add some additional lines in the “image.h” file in the images folder. Those lines are just initializations of the image files that you copied. For e.g: Before editing it looked something like this –

#include "grlib.h"

#ifndef __IMAGES_H__
#define __IMAGES_H__

//*****************************************************************************
//
// Prototypes for the image arrays.
//
//*****************************************************************************
extern const Graphics_Image LPRocket_130x50_1BPP_UNCOMP;
extern const Graphics_Image TI_Logo_107x100_1BPP_UNCOMP;

#endif // __IMAGES_H__

After editing this is what it looks like –

<pre>#include "grlib.h"

#ifndef __IMAGES_H__
#define __IMAGES_H__

//*****************************************************************************
//
// Prototypes for the image arrays.
//
//*****************************************************************************
extern const Graphics_Image LPRocket_130x50_1BPP_UNCOMP;
extern const Graphics_Image TI_Logo_107x100_1BPP_UNCOMP;
extern const Graphics_Image flame1BPP_UNCOMP;
extern const Graphics_Image hack1BPP_COMP_RLE4;
extern const Graphics_Image hack_a1BPP_UNCOMP;
extern const Graphics_Image pic1BPP_UNCOMP;
extern const Graphics_Image rev1BPP_UNCOMP;
extern const Graphics_Image nodejs1BPP_UNCOMP;
extern const Graphics_Image nordic2BPP_UNCOMP;
extern const Graphics_Image nrf1BPP_UNCOMP;
extern const Graphics_Image ti1BPP_UNCOMP;
#endif // __IMAGES_H__

[The correct names to be copied to the images.h file can be found from the files that were generated after you clicked on the gear button of the image reformer tool.]

Now you need to edit the main.c file….This is what it looks like– i encourage you to find out the differences yourself and understand how i added the extra code.



#include "grlib.h"
#include "radioButton.h"
#include "checkbox.h"
#include "LcdDriver/Hitachi138x110_HD66753.h"
#include "LcdDriver/HAL_MSP_EXP430F5438_HITACHI138x110_HD66753.h"
#include "images/images.h"
#include "driverlib.h"

Graphics_Context g_sContext;
int32_t stringWidth = 0;

void boardInit(void);
void clockInit();
void Delay(void);


/**********************************************************************//**
 * @brief  This is the example code's main function.
 *
 * @param  none
 *
 * @return none
 *************************************************************************/

void main(void)
{
    // Basic GPIO Initialization
    boardInit();
    clockInit();

    // Set up LCD
    Hitachi138x110_HD66753_initDisplay();
    Graphics_initContext(&g_sContext, &g_sHitachi138x110_HD66753);
    Graphics_setForegroundColor(&g_sContext, ClrBlack);
    Graphics_setBackgroundColor(&g_sContext, ClrWhite);
    Graphics_setFont(&g_sContext, &g_sFontCmss12b);
    Graphics_clearDisplay(&g_sContext);

    //**********************************************
    //***************** Note ***********************
    //**********************************************
    // This LCD display has adjustable contrast.
    // The default contrast setting likely needs
    // adjustment for optimal performance.
    //**********************************************
    Hitachi138x110_HD66753_setContrast(110);
    Hitachi138x110_HD66753_setBacklight(2);

    // Intro Screen
    Graphics_drawStringCentered(&g_sContext,
                                "By",
                                AUTO_STRING_LENGTH,
                                69,
                                27,
                                TRANSPARENT_TEXT);
    Graphics_drawStringCentered(&g_sContext,
                                "SHANTAM RAJ",
                                AUTO_STRING_LENGTH,
                                69,
                                54,
                                TRANSPARENT_TEXT);
    Graphics_drawStringCentered(&g_sContext,
                                "ECE, IIT Ghy",
                                AUTO_STRING_LENGTH,
                                69,
                                81,
                                TRANSPARENT_TEXT);
    Delay();

    Graphics_clearDisplay(&g_sContext);
    // Draw Images on the display
    Graphics_drawImage(&g_sContext, &LPRocket_130x50_1BPP_UNCOMP, 4, 30);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &TI_Logo_107x100_1BPP_UNCOMP, 15, 5);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &flame1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &rev1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &hack1BPP_COMP_RLE4, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &hack_a1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &pic1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nodejs1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nordic2BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nrf1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &ti1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    while(1)
    {
        Graphics_drawStringCentered(&g_sContext,
                                            "Thats it folks !!",
                                            AUTO_STRING_LENGTH,
                                            69,
                                            27,
                                            TRANSPARENT_TEXT);
    }
}

void boardInit(void)
{
    //Tie unused ports
    GPIO_setAsOutputPin(
        GPIO_PORT_PA,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PA,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PB,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PB,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PC,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PC,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PD,
        GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
        GPIO_PIN6 + GPIO_PIN7 + GPIO_PIN8 + GPIO_PIN9 +
        GPIO_PIN10 + GPIO_PIN11 + GPIO_PIN12 + GPIO_PIN13 +
        GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsPeripheralModuleFunctionOutputPin(
        GPIO_PORT_PD,
        GPIO_PIN0 + GPIO_PIN1
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PD,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    // P10.0 to USB RST pin,
    // ...if enabled with J5
    GPIO_setAsOutputPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 + GPIO_PIN12 +
        GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsInputPin(
        GPIO_PORT_PE,
        GPIO_PIN8
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PE,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PJ,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PJ,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P6,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputHighOnPin(
        GPIO_PORT_P6,
        GPIO_PIN6
        );

    // USB RX Pin, Input with
    // ...pulled down Resistor

    GPIO_setAsInputPinWithPullDownResistor(
        GPIO_PORT_P5,
        GPIO_PIN7
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P5,
        GPIO_PIN7
        );
}

void clockInit()
{
    UCS_setExternalClockSource(
        32768,
        0);

    UCS_turnOnLFXT1(
        UCS_XT1_DRIVE_3,
        UCS_XCAP_3
        );

    UCS_initFLLSettle(
        16000,
        488
        );

    SFR_enableInterrupt(
        SFR_OSCILLATOR_FAULT_INTERRUPT
        );
}

void Delay(void)
{
    __delay_cycles(SYSTEM_CLOCK_SPEED * 4);
}

#ifdef __ICC430__
int16_t __low_level_init(void) {
    WDT_A_hold(WDT_A_BASE); // Stop WDT (Watch Dog Timer)
    return(1);
}

#endif

After this you build the project and Debug it and then Run it to see the magic !!

Posted in MSP-EXP430F5438, MSP-EXP430F5438a, MSP430F5438 | Tagged , , , , , , , | Leave a comment

Of Hearts and Swords

P.S The story follows the style of movies that show the present and keep on switching between past and present, following a nonlinear style of showing the events.

OF HEARTS AND SWORDS

It was the 31st night. He had never counted them before, and knew this was unsettling and could be his last battle. For the first time he doubted his prowess and felt helpless for his brothers. He had ordered his garrison to call it a day and prepare for the night. This was his 7th battle, battles that saw him rise through the ranks from an unknown soldier to the captain of a battalion of which only a score were left. He had been given the marching orders to obliterate the last of the rebellions to the state when the state itself was celebrating the arrival of the new member of royal blood. There were no signs of reinforcements even after a week of the boy being sent to the capital. He could only pray that the boy’s heart had not been gouged out, for this was the way of the “Vandals”. Betrayal from the state too could not be ruled out, as the state had ordered a similar assault the last two battles and the reinforcements arrived just when the men barely held the guard. It was as if a flock of sheep were tasked to raid the wolf’s lair. Living in the mountains and the woods in complete harmony with nature, the Vandals thrived. They were one of the last rebellions to the state. Their ways were very different from a conventional army. Proficient in guerrilla warfare, they proved to be the most ferocious and impenetrable. They used the trees, the earth, the fire and the wind as their weapons. Hiding in the shadows, they struck hard and fast before falling back into night. He chose not to fog his mind for his hands were responsible for the safety of his men.

Being lonely and not being loved is a punishment. It’s a punishment from the heavens for the sins that, no matter how hard you try, you cannot come back from. But then everyone deserves a piece of heaven, even the Satan had his time.
He had saved her purity a night as cold and dreary as his heart had become after the bloodshed of the third battle. When inquired where she was hurrying under the cover of the dark moonless night that had shone her bright to the lurking beasts, she trembled “To the priest, my father is very ill”. He accompanied her and it was in the dimly lit shack did he see her face for the first time and felt a beat in his dead heart. She was not “Venus” in human flesh but she was surely an angel. Those large sparkling eyes showed him everything that he had never seen before. The long brown tresses became more precious than gold. Her face though saddened, spoke of the homely and caring essence that she had inherited from her mother. She became someone he could live for. The cold claimed her ailing father after a month. He never let himself lax a bit in his part to help her nurse her father, for she was the only one. Her siblings and her mother were claimed by the same demon years back. Life would have become miserable if she had no one by her side after the demise of her father, for the monsters would have devoured her. He chose to stay with her and she got strength in his presence. But the wolves would not keep without biting. He saved her once more when she had gone to the river to fetch water. The debauched, blinded by their desires bared their fangs once more, this time in daylight. He had followed her, for he could not lose her, he cherished her yet could not tell her, for she was so bright and he was afraid of the revival of feelings in his once dead heart and his restless nights despite the closeness. He knew he loved her but was uncertain if she felt the same. This incident changed everything. The village came to know of what he did to them and never a man dared glance at what he himself was reluctant to gaze. The other day she declared her love for him and let herself get en-wreathed in his arms. Her tender, but not fragile embrace, liberated his soul from the anxious state he was in. The sea had found its shore. Life finally seemed to have taken a beautiful turn. She blossomed for him like a flower and he finally found a purpose in life. But fate took a turn soon afterwards. He was called again. He felt torn apart, a part of his heart wanted to stay in her warmth and the rest wanted to lift the sword, taste the glory and the pride marching with his brothers. It was the only way of life he had known. She kept herself from falling apart when he told her of the call. He promised he would return for her. She gave a tearful smile and tied a necklace around his neck. Her mother had given her the necklace to protect her from the numerous ways that life finds to cut short a beloved’s life.

He did return whenever he went, but he would lose a part of his soul every time he left her. Her radiance would revive him once again. This time was the longest he spent in her shade, stretching almost a year before the ominous call of the duty. She used to ask him to take her with him, he used give a soft smile, feel the contour of her face, caress her tresses and say “You are safe here, my love”. This was the longest night of his life. They were having a baby and he would not be there to witness the miracle of life. He told her how life suddenly had a meaning when he found her that treacherous night. How a dreadful, weary and monotonous life unfolded into a warm loving and caring paradise. How the chaos and clamour of that night gave way to a lifetime of joy. He said “In the profound abyss of life I laid naked till you liberated me of the crutches I had forged for myself. I had been waiting for you all these years, I knew I had to protect you, that you would be my freedom, that you would be my light. I fell in love with an angel”. They were cuddled together and he was caressing her. She shed a tear and said “I used to see the sun, not the sunshine, I heard the birds not their song, I felt the water not the rain. You changed that. You are the sunshine, you are the rain, you brought spring and erased all the pain”. Dark clouds prevailed the skies. The birds were mourning. An ominous silence prevailed. Before letting go, he gave her an embrace that told her of his agony. Finally he kissed the unborn and said “This is not a good place for cowards. Be strong, be brave my child”. Even nature was powerless at the treachery of men. With his sword and her warmth in his heart he went away.

He was cornered, no sign of help from the state and only a score of his army left. He had to choose between death by his own sword or being ripped apart into pieces by the fangs of a beast. He had but this night. He could turn around but then he would die by the sword of his state, for returning would mean defeat and defeat meant disgrace of the royalty and for a king who has not seen the truth of life, who achieved greatness because it was passed to him, who has not suffered, who has no compassion or empathy, who lives in the false glitter of riches, riches snatched from the poor, it’s intolerable, it’s death. He chose death by the beast.
What is it that gives us the strength to leave love behind, to sacrifice everything ? Is it the scars that never heal or is it the shame of the sins that burns the strings of love pulling us to our beloved or is it love itself that tells us we are not good enough, that there is a monster inside of us that refuses to be tamed. I do not know.
He decided to stay and let his men escape. He gathered the men and told them that there was no honour in fighting for a state that was indifferent to their needs, their safety and their pain. The men were definitely taken aback, but they never doubted him. He told them that they will have to dig a tunnel to the west. Of course the opening of the tunnel had to be made inconspicuous, that’s why he would have to stay behind. They had to dig the tunnel from the pit where they relieved themselves. The filth of the pit was transferred on ground, the men dug as hard as they could for they will be just below the Vandals when they come for them tomorrow morning. He closed the opening with planks of wood from wooden crates and barrels. “Crixus” requested him that he wanted to stay behind and help him, and when he didn’t agree he said “I would rather die beside you than be greeted by the nothingness of life”. This was enough for the captain for he had been there. They then put back the filth on the covered mouth and lined it with soil. A job meticulously done to give a first-hand impression of what they wanted the Vandals to know but didn’t want them to explore further. He had told them how they were to keep the supplies for as long as possible and how the digging had to be carried out 24 hours a day in shifts. He also gave them olive oil and salt to provide soot-less light. The digging had to be continued till they were sure that they were sufficiently far from the tribe and after that he had told them explicitly that they should not try to go back to their homes, instead they should keep on moving west to the mountains and live with the people there. He told them to infiltrate only after the dust had settled to extricate their families and his, to the mountains.

What is it that gives us the courage to embrace death with open arms? Is it the loneliness that we fear more or is it the realization that we got a chance to love and be loved?
With eyes wide open they stood with swords and spears in their hands waiting for the Vandals. Their wishes were granted soon as they saw a dark wave, a wave of metal and men. Metal that would soon pierce their hearts and men that would feast on them. They stood cornered, cornered by the walls they had erected themselves brick by brick, oblivious that they would be the ones trapped on the wrong side.

He saw light. He saw “Aurelia” holding their child. His daughter, her eyes like her mother. A silent, serene little goddess with the essence of her mother and strength and courage of her father. He was proud, very proud. He saw them sitting under the shade of the giant sequoia, his head resting on her lap. The sun shining through the gaps amongst the leaves emerged around the contours of her face and gave her an angelic appearance. She was sent to rescue him. He saw the three of them playing by the river. The enchanted earth beamed with joy wherever they tread. The wind spread their fragrance far and beyond. The buds blossomed by their touch. The dew drops danced to their rhythm. He was in paradise.

Crixus saw Sura. He saw a young himself, gazing from behind a tree at her sitting on the banks of the river. He saw himself looking at her in the church. He saw their eyes catching each other and noticed the stopping of time, stilling of his heart, that ecstasy and the fear that came with it which was too pressing to bear. He stood transfixed, unable to think or thank. He saw the good times they had. Then everything turned red. Sura lay in a pool of blood. He saw himself standing there paralyzed, oblivious to the world around them, not knowing what to do. He saw himself running from the truth. He regretted how life took her away from him. He saw his pain turning into anger and him into a soldier. He resented himself for trying to forget her. He resented himself for running away. He resented himself for not avenging her death. He condemned himself for living beyond his time.

Were they killed by the Vandals or experienced transcendence? Did they ascend to heaven or descend to hell, I do not know. But I can tell you that they will not be forgotten.

Posted in Short story | Tagged , , , , , , , | Leave a comment

Sensor Hub

Inspired by the Sensor Tag from TI i am planning to make a sensor hub of my own consisting of I2C based temperature sensors, ambient light sensor , Humidity sensor and a barometric altimeter sensor too.
Currently in the eagle schematic i am using the sensors described below –

Sensor Name IC Name Comments
Ambient light sensor OPT3001 Human eye response
Temperature Sensor TMP100 I2C Interface
Humidity sensor HDC1000 Integrated temperature sensor
Pressure/Altimeter sensor MPL3115A2 Integrated temperature sensor

There are headers for NRF24L01+ and ESP8266 too.
As of now i have put up my schematic and layout files(beta) on my GitHub repository. The codes will be added soon.

23/08/2015

The preliminary single layered board layout is almost over. I just need to do the DRC. The commit has been done on GitHub. Since this is just the prototype, it is very simplified and has lesser components and no consideration for power at all. After this i need to take a printout and see if the printer’s resolution is good enough. In about a weeks time i will start working on the codes and the design of double layered PCB for production purposes.

24/08/2015

The routing for the prototype is complete.

26/08/2015

Images –

sensor_hubbwpth2sensor_hubbwsmd2  sensor_hubpth1 sensor_hub2

Posted in Uncategorized | Leave a comment

C2000 Tutorial -1

For our first test we will use the “TempSensorConv” example from the “controlSUITE” that you will get from here. In its default state this example will get the temperature reading of the microcontroller chip (via ADCIN5) and convert it into degree Celsius and Kelvin. But to see the temperature reading is not very straight forward.

So first of all Build the project by clicking on  20150624T234825 and then click on the debug 20150624T234839button. After that click on20150625T003630 to download the program on your launchpad. Unfortunately CCS is not like Arduino IDE where you can open a serial monitor to view the values of your variables. Here you need to use serial emulators like “puTTY” or “Tera Term”. But that i will show you in my next post. Right now we will use the features that is provided by CCS itself. So for that you need to put the “degC” variable on watch after clicking on the “Expressions” tab on the right hand side and clicking on “Add New Expression” and then write degC variable to it.

20150625T000345

But the problem is that you will get the reading only once, so for getting continuous readings you will need to click on Continuous Refresh button.20150624T235121

Screenshot (19)
 

This is what it looks like. 

 

 

Screenshot (13)

 

 

 

Now the good part is that you can also visualize the graph of the variable degC. For that right click on degC and then click on Graph.

 

 

This is what you will get…

Screenshot (14) Screenshot (15)

The default sampling rate is 1Hz for CCS to refresh the samples, so change it to 100Hz to see rapidly changing values. you can blow on the Chip to decrease the temperature or keep it closer to the heat sink of the laptop to increase the temperature of the chip.

Screenshot (16) Screenshot (17) Screenshot (18)

Posted in C2000, Piccolo | Tagged , , , , | Leave a comment

Hacking the Rock Crawler – Part 3

AT the end -> A very trivial but important lesson – something that we all assume we know theoretically but might fail to implement practically !!.


This is what the 4-bit level shifterDSC02173  BSS328 module from Adafruit looks like –

 

 

 

  • My first step was to test the module , the connections were straight forward and the results were good.
  • After that i connected the pins from arduino to the level shifter like this –
Arduino Pin 4-bit Level Shifter Pin
3.3V LV
5V HV
GND GND
There are two GND pins on the level shifter and both are internally connected so connecting one is enough.
A5 B1
A4 B2
A3 B3
A2 B4

DSC02178

  • Then i connected the pins from the Level shifter to wires coming from the RC like this –
Level shifter Pin PCB wire
A1 White
A2 Blue
A3 Yellow
A4 Grey
  • Final looks –

Picture1

  • After that i uploaded the codes –

Transmitter node takes analog inputs from the joystick. A lower threshold and an upper threshold is defined. So if the reading is between these two values then we transmit “3” , if it is less then we transmit “1” and if it is higher then we transmit “4”. Similarly the transmitted integers for the joystick that controls turning are “4” , “5” and “6”.

The receiver receives these messages and correspondingly decides what to do. It also serves an additional purpose of range finding. As soon as the receiver stops receiving data it glows a RED led otherwise it glows a BLUE led.

All the codes are here .

The output on the serial monitor was perfect. In the resting state of joysticks it showed that there is no turning and no movement and it responded correspondingly as i moved the joysticks.Then i connected the receiver to the wires from the PCB and powered the RC and the receiver. But the RC did not respond after i turned the joystick to and fro !!. I was very disappointed. My first thought was that the level shifters were not working. So i started checking the voltages at the outputs of the level shifter and i got my answer… it read 1.9V as opposed to 3.3V !!. I disconnected the level shifter from the RC and checked it again but this time it read 3.3V !!. I was now confused as well as disappointed. I connected it back and repeated the process and again it read 1.9 V and after disconnecting it read 3.3V !!. I stared at the setup for a while then i thought lets connect the GND of PCB to the GND pin of the Level shifter that was left.

DSC02168 copy

 

After doing that as soon as i turned the joystick the RC worked like a charm !!.

 

 


LESSON LEARNT

Whenever you are connecting two or more circuits together into one big circuit, make sure that the Grounds are connected i.e DSC02181 copythe whole circuit MUST have a single Ground. In my case the level shifter and arduino had the same ground but the ground of PCB was different hence we were getting those strange readings. As soon as i connected the ground of the PCB to the Level shifter the whole circuit had on e ground and the RC started working.

Posted in Arduino, Hacking, nRF24L01+, Wireless | Tagged , , , , , , | 1 Comment

Setting up the transmitter and the receiver

So i am still waiting for the level shifters to come, meanwhile i wrote a code that would form the framework for the codes for the RC car so that i would not have to spend a lot of time in debugging.

I made a shield for the receiver node that would rest on the RC and a controller for the transmitter node using the joystick that i had hacked earlier. As of now we will not use the joystick , we will send some custom messages. Now when we are in room it is pretty easy to debug using serial monitor but for finding the maximum range and probably some other stuff we cannot possibly use serial monitor on laptop (we can but that would be tedious and overkill) . So i connected some LEDs as a visual indicator to indicate when we are receiving messages and when we have stopped receiving messages.

What i basicaDSC02020lly do is that i transmit some message from TX and the RX keeps on looking for them. If it receives the message then it glows a BLUE led and once it stops receiving data it glows a RED led. So as soon as the RED led on RX starts glowing we can come to know that we have reached the maximum range.

DSC02023

 

 

The backside of the shield.

 

 

DSC02183

 

 

This is what the transmitter looks like –

 

 

 

TX side code –

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
int msg[1] = {1};
RF24 radio(9, 10);
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};

void setup()
{
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.stopListening();
  radio.openWritingPipe(pipe[0]);
  radio.setRetries(15, 15);
}
void loop()
{
  if (radio.write(msg, sizeof(msg)))
  {
    msg[0] += 3;
    if (msg[0] >= 100)
    {
      msg[0] = 1;
    }
  }
}

Rx side code –

//red glows and blue stops glowing when no reception is there
//blue glows and red stops glowing when reception is proper
#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};
RF24 radio(9, 10);
int msg;
const int red = 6;
const int blue = 7;
void setup()
{
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.openReadingPipe(1, pipe[0]);
  radio.startListening();
  radio.setRetries(15, 15);
}
void loop()
{
  if ( radio.available() ) {
    radio.read( &msg, sizeof(msg) );
    //Serial.print("integer got is : ");
    //Serial.println(msg);
    digitalWrite(blue, HIGH);
    digitalWrite(red, LOW);
    delay(10);//this delay is very important as it prevents the red
    //led from glowing simultaneously with blue as you know that
    //transmissions from TX are not continuous,remember the datasheet.
    //also remember that there is no delay in the TX code.
  }
  else
  {
    //Serial.println("no radio");
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
  }
}

RESULTS

DSC02185 copyDSC02188 copy

Posted in Arduino, DIY, Hacking, nRF24L01+, Wireless | Tagged , , , , , , | Leave a comment

Hacking the Rock Crawler – Part 2

After soldering the wires this is what we get – DSC02005

DSC02005edNow we have to take care of a big issue –

The High logic level for arduino is 5V but the High logic for our chip-on-board is 3.3V, so if we directly connect the wires that we just soldered to arduino, chances are that we will fry the chip-on-board, something that we just cannot afford to do. (It is possible that the pins on chip-on-board are 5v tolerant, but due to lack of any literature we will avoid taking risks.) So how to tackle this problem ??

Now when we think about this then we might come up with these solutions –

  1. Use the analog pins instead of digital and in the analogWrite function use the integer 168 to get 3.3 volts.
  2. Voltage divider circuit.
  3. Use Level Shifter ICs.

Now the first solution is WRONG  and will most probably damage the chip-on-board.

The correct solution is using level shifter ICs or a voltage divider.

Now lets discuss why the first solution is wrong ?

We know that the analog pins in output mode give PWM signals. The thing with PWM signals is is that their average value comes out to be 3.3 V , they do not provide a steady DC output of 3.3 V. The duty cycle with 168 as the parameter in analogWrite function will be approximately 66% i.e for 66% of the time it is outputting 5V and the rest of the time it is outputting 0V so that the average comes 3.3V. But we must note here that it still outputs 5V for majority of time , and during the time it is outputting 5V it is capable of damaging the chip-on-board.

Hence we are left with using either Level Shifter ICs or making a voltage divider.

Whats the fun in making a voltage divider circuit 😛 ??

So lets focus on using the level shifter ICs. Now there are a lot of solutions when it comes to using the ICs. Some possible solutions are –

  1. 74125 (might be obsolete)
  2. 74245http://www.adafruit.com/datasheets/sn74lvc245a.pdf
  3. 74HC4050http://www.nxp.com/documents/data_sheet/74HC4050.pdf
  4. TXS010X series
  5. TXB010X series
  6. CD4050
  7. Field effect transistors with proper biasing

There are probably more solutions than what i have listed and  you can get a very comprehensive list from HERE .

I am using the BSS138 (from adafruit), so the next post would be about how to interface arduino , logic level converter and the RC pcb together.

Posted in Arduino, DIY, Hacking, nRF24L01+, Wireless | Tagged , , , , , , | Leave a comment