Hack a HEXBUG Spider for Serial Control with a TI Launchpad

HEXBUG Spider from Innovation First

 

I have written a lot about how easy it is to use the TI Launchpad and how the TI MSP430 is the perfect hacker/DIY'ers part.  The TI MSP430G2211 is part of TI's Value line of processors, the DI...

 

You can read more about the TI Launchpad here: http://buildsmartrobots.ning.com/group/ti-launchpad

 

You will also find other robot I have built using the TI Launchpad at www.buildsmartrobots.com.

 

Including Launchbot a sub $20.00 programmable robot.  Instruction on how to build Launchbot can be found here.

 

 

 

The HEXBUG Spider from Innovation First is a fun toy robot you can buy from RadioShack or Target for less than $25.00.  I wrote a blog covering the internals of the HEXBUG Spider here: http://buildsmartrobots.ning.com/profiles/blogs/build-a-30-00-multi... .

 

The HEXBUG Spider is controlled by a infra-red remote control.  The Spider can move forward, backward, and turn left, and right.  

 

The transmitter has its own microcontroller and power supply (two 1.5volt button cells).  There are four buttons each connected to a pin on the microcontroller.  When a button is pushed, the microcontroller pin is shorted to ground.  There are no external pullups.

 

With this project the TI Launchpad is connected to the four button signals on the transmitter.  The transmitters microcontroller generates the IR signal that actually controls the robot.

 

   Six connections between Launchpad and transmitter (forw,back,left,right,bat+,gnd)

 

Opening the transmitter can be done using just a flat screwdriver.  Simply pry the four plastic tabs (two on each side) using the flat screwdriver.  The top of the transmitter comes right off.  

 

The transmitter has convenient test pads at each signal making it easy to solder wires to.

 

You will also need to solder a wire to the ground pad in the upper left corner of the image above.  I also soldered a wire to the bat+ pad for a future project.  It is not needed for this project.

 

Connecting the TI Launchpad to the Transmitter

 

TX Forward = Launchpad P1.3

TX Backward = Launchpad P1.4

TX Left = Launchpad P1.7

TX Right = Launchpad P1.5

TX GND = Launchpad GND

 

 

 

 

 

This project is about controlling the HEXBUG Spider with a serial port.  I use the USB to serial adapter built into the TI Launchpad, and a software UART I wrote for the MSP430G2211 that does NOT require an external crystal.  The software UART is covered in detail here: http://e2e.ti.com/group/msp430launchpad/m/project/475433.aspx

 

The Spider is controlled using a simple serial protocol.  The first character received by the MSP430 after reset MUST be a 'o' at 2400baud (see this article for the reason why).  After the 'o' is received, the MSP430 will return a '>' at 2400baud.  Sending a 'f' moves the robot forward, a 'b' moves the robot back, a 'r' turns right, and a 'l' turns left. Sending a 's' stops the previous motion.

 

This is the first phase of my spider project.  The next phase is to make the Spider a line follower.  The transmitter with a MSP430 dead bugged on top, will be mounted on the head of the spider.  This will make the robot completely autonomous.  I am not sure how to add the line sensors yet.  I have some ideas, but I have not prototyped them yet.  Keep your eye on www.buildsmartrobots.com for updates to the project.

 

 

The code for the serial controlled HEXBUG Spyder is below:

 

//---------------------------------------------------------------------------
// TI Launchpad Serial SpiderBot Controller
// Written by Eric Gregori ( www.buildsmartrobots.com )
//
// Copyright (C) 2011 Eric Gregori
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see a href="http://www.gnu.org/licenses/.%3E">http://www.gnu.org/licenses/.>;
//
//---------------------------------------------------------------------------
#include "msp430g2211.h"

#define SPIDERIO (BIT3|BIT4|BIT5|BIT7)
#define LEFT BIT7
#define GREENLED BIT6
#define RIGHT BIT5
#define BACKWARD BIT4
#define FORWARD BIT3
#define SERIALIN BIT2
#define SERIALOUT BIT1
#define REDLED BIT0

#define REDLEDON P1OUT |= REDLED;
#define REDLEDOFF P1OUT &= ~REDLED;
#define GREENLEDON P1OUT |= GREENLED;
#define GREENLEDOFF P1OUT &= ~GREENLED;

#define SERIALHIGH P1OUT |= SERIALOUT;
#define SERIALLOW P1OUT &= ~SERIALOUT;

unsigned short BitTime;

void InitPins( void )
{
P1REN &= ~SPIDERIO; // Disable pullup
P1OUT &= ~SPIDERIO; // Set Low
P1DIR &= ~SPIDERIO; // Float Signals
}

void Stop( void )
{
P1DIR &= ~SPIDERIO; // Float Signals
}

void Forward( void )
{
Stop();
P1DIR |= FORWARD; // Pull FORWARD signal to ground
}

void Backward( void )
{
Stop();
P1DIR |= BACKWARD; // Pull BACKWARD signal to ground
}

void Right( void )
{
Stop();
P1DIR |= RIGHT; // Pull RIGHT signal to ground
}

void Left( void )
{
Stop();
P1DIR |= LEFT; // Pull LEFT signal to ground
}

void Delay( unsigned short in )
{
volatile unsigned short i;
for( i=1; i; ++i )
{
if( i == in )
break;
}
}

unsigned short MeasureLow( void )
{
volatile unsigned short i;
for( i=1; i; ++i )
{
if( P1IN & SERIALIN )
break;
}

return(i);
}


void SendChar( unsigned char data )
{
// Send Start Bit
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x01 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x02 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x04 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x08 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//------------------------------
if( data & 0x10 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x20 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x40 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------
if( data & 0x80 )
SERIALHIGH
else
SERIALLOW
Delay( BitTime );
//-----------------------------

// Stop bit
SERIALHIGH
Delay( BitTime );

// Stop bit
SERIALHIGH
Delay( BitTime );
}

unsigned char GetByte( void )
{
unsigned char data;
unsigned char bits;

data = 0;

// wait for start
while(P1IN & SERIALIN){};
Delay(BitTime/2);
if( P1IN & SERIALIN)
return(0xff);

for( bits=8; bits; --bits )
{
Delay(BitTime);
data = data >> 1;
if( P1IN & SERIALIN ) // bit 0
data |= 0x80;
}

Delay(BitTime);
return(data);
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

// Set P1.2 as input, P1.1 as TXout, P1.6 as LED
P1DIR = GREENLED|REDLED|SERIALOUT;
InitPins();

SERIALHIGH

// Initialize Clocks
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz

BitTime = 0;
while(1)
{
if( BitTime == 0 )
{
while(1) // Wait for 'o'
{
GREENLEDON
if( (P1IN & SERIALIN) == 0 )
{
BitTime = MeasureLow();
BitTime -= 3;

if( BitTime > 255 )
continue;

GREENLEDOFF
break;
}
}
}

SendChar( '>' );
switch( GetByte())
{
case 'f':
Forward();
break;

case 'b':
Backward();
break;

case 'r':
Right();
break;

case 'l':
Left();
break;

case 's':
Stop();
break;
}
} // while(1)
}


 

 

 

 

Views: 4826

Tags: UART, first, hacking, hexbug, innovation, launchpad, msp430, msp430G2211, serial, spider, More…ti

Comment

You need to be a member of buildsmartrobots to add comments!

EMGRobotics

© 2014   Created by eric gregori.

Badges  |  Report an Issue  |  Terms of Service