Saturday, May 14, 2011

The WII Motion Plus Gyro







Now we return to the Quad Copter project picking up with the WII Motion Plus Gyro that will be used as a sensor. I picked one of these up from Amazon.Com for about 10.00 dollars and free shipping. It makes for an inexpensive 3-axis gyro that can be hacked for use in home-brewed electronics experiments. I have been researching the specifics of how to utilize this device. Most of the information I found indicated that the device can be easily polled by a microprocessor with an an I2C interface. The board inside the WII Motion Plus contains an I2C interface, 14 bit ADC and a 3-axis gyro. A lot in a cheap package. I will be getting into the technical aspects of the interface in a later post. This time I am simply going to describe the process of dismantling the Motion Plus to obtain the gyro. It was definitely designed so that it could not be easily unassembled. Two Y-bit screws on the back could not be removed with any of the tools that I have. I tried phillips and hex and square bits and then tried to drill the screws out. Even then the back would not come apart. I then tried to pry the shell apart, but found it was put together tightly and securely. As a result the outside shell was rendered useless by the time I got to the gyro. I feared that the circuitry would be damaged even though I was careful. In the end I managed to remove the gyro from the plastic case. Then I unsoldered the female pass-through port connector. This will allow me to make a cable with a female plug so that I can use the male connector that is attached to the gyro board. Later will begin experimenting with the hardware interface and making use of the data that the gyro provides.

The Capicitive Touch Booster Pack for the Launchpad



I took some time to play with the Capacitive Touch Booster Pack on the Launchpad. This kit from TI cost $ 4.30 during the initial 430 hours of release. I purchaed one because it looked cool. The booster pack is a shield-like board for the Launchpad that plugs into the headers. You must solder the male headers that came with the LP in order to connect a booster pack. The kit also comes with an 20 pin MSP430G2452 micro chip that is preloaded with the demo software. It was easy to hook up, although I could not find any where in the documentation that specified the orientation for the board. The demo provides a capacitive touch wheel surrounded by led's with a touch button in the middle. Very similar to the IPOD wheel interface. It also has a proximity sensor that wakes the board up when a hand is waved in front of it. The demo was impressive and worked right out of the box with no need to flash the microprocessor. TI provides an extensive library of sample code and a library of functions for the capacitive touch applications. Some day I may play with this some more and use the wheel in a hand held wireless remote for the quad.

Wireless Launchpad with the EZ430 RF2500T

Recently, I experimented with the LaunchPad and the EZ430 RF2500T. I plugged an EZ430 RF2500T configured as an access point to the USB port on my laptop. I plugged another EZ430 RF on the J4 connector of the Launchpad. This device was configured as an End Device. On the Launchpad I used the 2231 micro controller and loaded a demo application from TI that reports status of tempature readings (LO, IN or HI).

The purpose of this experiment was to validate that the EZ430 RF2500T can be used for wireless communication with the LaunchPad.

With this setup I was able to wirelessly transmit the tempature status from the LaunchPad to the laptop. Using Hyperterminal I was able to view the data transmitted by the EZ430 RF2500T.

You can find the code for the EZ430 RF2500T access point and end device by downloading TI's EKG-Based Heart-Rate Monitor Implementation on the LaunchPad Value Line Development Kit Using the
MSP430G2452 MCU application demo source
. The code for the wireless devices will work right out of the box without modification. I used IAR Kickstart to load the access point and end-device projects on a pair of the EZ430 RF2500T's. Since I did not have the hardware setup for the Heart Rate monitor I loaded the TI demo code shown here on the LaunchPad just so that I could get some data to transmit for the test.

//***********************************************************
// Lab7.c Software UART
//
// SFB 10/2010
//***********************************************************

#include

#define TXD BIT1 // TXD on P1.1
#define RXD BIT2 // RXD on P1.2
#define Bitime 13*1 // 0x0D

unsigned int TXByte;
unsigned char BitCnt;

unsigned int TxHI[]={0x48,0x49,0x0A,0x08,0x08};
unsigned int TxLO[]={0x4C,0x4F,0x0A,0x08,0x08};
unsigned int TxIN[]={0x49,0x4E,0x0A,0x08,0x08};

volatile long tempRaw;
volatile long tempSet = 0;
volatile int i;

void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void Transmit(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();

while(1)
{
_bis_SR_register(LPM3_bits + GIE); // turn on interrupts and LPM3

if (tempSet == 0)
{
tempSet = tempRaw; // Set reference temp
}
if (tempSet > tempRaw + 5) // test for lo
{
P1OUT = BIT6; // green LED on
P1OUT &= ~BIT0; // red LED off
for (i=0;i<5;i++)
{
TXByte = TxLO[i];
Transmit();
}
}
if (tempSet < tempRaw - 5) // test for hi
{
P1OUT = BIT0; // red LED on
P1OUT &= ~BIT6; // green LED off
for (i=0;i<5;i++)
{
TXByte = TxHI[i];
Transmit();
}
}
if (tempSet <= tempRaw + 2 & tempSet >= tempRaw - 2)
{ // test for in range
P1OUT &= ~(BIT0 + BIT6); // both LEDs off
for (i=0;i<5;i++)
{
TXByte = TxIN[i];
Transmit();
}
}
}
}

void ConfigWDT(void)
{
WDTCTL = WDT_ADLY_250; // <1 sec WDT interval
IE1 |= WDTIE; // Enable WDT interrupt
}

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 = 0; // MCLK = DCO = SMCLK
}

void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}

void ConfigPins(void)
{
P1SEL |= TXD + RXD; // P1.1 & 2 TA0, rest GPIO
P1DIR = ~(BIT3 + RXD); // P1.3 input, other outputs
P1OUT = 0; // clear output pins
P2SEL = ~(BIT6 + BIT7); // P2.6 and 7 GPIO
P2DIR |= BIT6 + BIT7; // P1.6 and 7 outputs
P2OUT = 0; // clear output pins

}

void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}

void ConfigTimerA2(void)
{
CCTL0 = OUT; // TXD Idle as Mark
TACTL = TASSEL_2 + MC_2 + ID_3; // SMCLK/8, continuos mode
}

// WDT interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void WDT(void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(500); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
_delay_cycles(100);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
tempRaw = ADC10MEM; // Read conversion value
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit
}

// Function Transmits Character from TXByte
void Transmit()
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
while (CCR0 != TAR) // Prevent async capture
CCR0 = TAR; // Current state of TA counter
CCR0 += Bitime; // Some time till first bit
TXByte |= 0x100; // Add mark stop bit to TXByte
TXByte = TXByte << 1; // Add space start bit
CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle
while ( CCTL0 & CCIE ); // Wait for TX completion
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
CCR0 += Bitime; // Add Offset to CCR0
if (CCTL0 & CCIS0) // TX on CCI0B?
{
if ( BitCnt == 0)
{
CCTL0 &= ~ CCIE ; // All bits TXed, disable interrupt
}

else
{
CCTL0 |= OUTMOD2; // TX Space
if (TXByte & 0x01)
CCTL0 &= ~ OUTMOD2; // TX Mark
TXByte = TXByte >> 1;
BitCnt --;
}
}
}

This experiment was a success. Some day I will try the EKG Heart rate demo if I can put together the hardware or obtain the demo board at a reasonable price.

Friday, May 6, 2011

Attaching an EZ430 RF target board to the Launch Pad

The Launch Pad development board provides unpopulated pads for adding a header so that a target board such as the EZ430 RF board can be attached to it. To connect one of the ez430 targets, connector J4 must be populated with a 0.050-in (1.27-mm) pitch male header, as shown in Figure 4, to connect the target boards. The part number for the header is Mill-Max 850-10-006-20-001000. I had a relatively hard time finding the header so I asked Mill Max for free samples and they graciously sent me a few. I would not normally ask for samples but in this case I could not find the header part. The manufacturer's will usually oblige requests if you are not greedy.


The header for J4 is very small and with the 0.05 in pitch it presented a challenge for my rusty soldering skills. One of the images shows the header part beside a ruler. I is a little over 1/2 an inch. The pads on J4 are close together on the Launch Pad. My hand shakes a lot more than it did when I was a youngster, but I was successful in soldering the connector to the Launch Pad. The target board was installed and all came up without a problem.



The EZ430 RF2500T target board is about 1 inch in length with an onboard chip antennae. In testing with my daughter we were able to maintain a connection outdoors for at least half a foot ball field distance. In my next post I hope to be able to share the results of experimenting with this setup to allow the two boards to talk to one another.







Two Launchpad SPI experiment


I began experimenting last night with the SPI module of the MSP430 mcu's on the launchpad. The experiment involved connecting two launchpad's together with a full-duplex SPI interface. One launchpad was configured as a master and the other as a slave. Full duplex communicationg between the two boards exists allowing both the master and the slave to send data simultaneously. When the switch on on either board is pressed the value on the io port is transmitted to the other device causing the led to light up. I soldered the male headers that came with the Launchpad board on to two of the kits so that I could get easy access to the processor pins. SPI is serial peripheral interface. You can find more about SPI at wikipedia. This is relatively easy to set up and play with. Nothing but four wires between the launchpads was required. The wiring schematic is shown below along with the code for the master and slave. The source code came from the TI code samples that were downloaded from their website. A couple of minor adjustments had to be made for the launch pad hardware to work primarily to use the push-button switch that is connected on P1.3. No pull up resisters were used in the experiment.

Though this is a simple experiment it provided an opportunity to learn how to use the Code Composer Studio tool to program the launchpads. Additionally, it helped to learn more about how to use the MSP430 SPI module. This is the beginning step in developing code to allow a launch pad to communicate with a EZ430 wire less RF target board that will be piggybacked on the lauchpad for wireless capability.

//******************************************************************************
// MSP430G2xx2 Demo - SPI full-Duplex 3-wire Slave
//
// Description: SPI Master communicates full-duplex with SPI Slave using
// 3-wire mode. The level on P1.3 is TX'ed and RX'ed to P1.0.
// Master will pulse slave reset for synch start.
// ACLK = n/a, MCLK = SMCLK = Default DCO
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include


void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x08; // P1.3 set, else reset-Modification for LP
P1REN = 0x08; // P1.3 pullup- modified for LP
P1DIR = 0x01; // P1.0 output, else input
USICTL0 = USIPE7 + USIPE6 + USIPE5 + USIOE; // Port, SPI slave
USICTL1 = USIIE; // Counter interrupt, flag remains set
USICTL0 &= ~USISWRST; // USI released for operation
USISRL = P1IN; // init-load data
USICNT = 8; // init-load counter

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
if (0x08 & USISRL) // Modified for Launch Pad
P1OUT = 0x01;
else
P1OUT &= ~0x01;
USISRL = P1IN;
USICNT = 8; // re-load counter
}

//******************************************************************************
// MSP430G2x21/G2x31 Demo - SPI full-Duplex 3-wire Master
//
// Description: SPI Master communicates full-duplex with SPI Slave using
// 3-wire mode. The level on P1.4 is TX'ed and RX'ed to P1.0.
// Master will pulse slave reset for synch start.
// ACLK = n/a, MCLK = SMCLK = Default DCO
// D. Dang
// Texas Instruments Inc.
// October 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include


void main(void)
{
volatile unsigned int i;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x08; // P1.3 set, else reset - modified for LP
P1REN = 0x08; // P1.3 pullup - modified for LP
P1DIR = 0x01; // P1.0 output, else input
USICTL0 = USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
USICTL1 = USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK
USICTL0 &= ~USISWRST; // USI released for operation
USISRL = P1IN; // init-load data

P1DIR = 0x08; // Reset Slave
P1DIR &= ~0x08;
for (i = 0xFFF; i > 0; i--); // Time for slave to ready
USICNT = 8; // init-load counter
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
if (0x08 & USISRL) // modified for Launch pad
P1OUT = 0x01;
else
P1OUT &= ~0x01;
USISRL = P1IN;
USICNT = 8; // re-load counter
}

Thursday, May 5, 2011

Launching the Embedded Enthusiast blog

Welcome to the Embedded Enthusiast, a blog dedicated to having fun with embedded electronics. I am an IT professional, with a degree in Electronics Technology. As a young teenager I dabbled in electronics building kits such as AM/FM radios, Electronic Light Show and playing with fiber optics experiments. My favorite magazines in those days were Radio Electronics and Popular Electronics. Radio Shack and Digikey were my favorite places to shop. I purchased a Timex Sinclar computer with 16K of memory and a cassette tape for storing programs. And there was some sort of magazine like SYNC or something that explained machine level programming on the tiny computer. I used to dream of Heath Kit projects like the robot on the front of the catalog with the extended arm on the head. I stopped dabbling with electronics after getting married and having kids. The advent of surface mounted components seemed to do in the hobbyist. Lately, I have become interested in embedded electronics. There are so many cool projects to play with and the price of the components and the ease of use is very attractive for the home enthusiast. That said I purchased 4 Texas Instruments Launch pads and three of the EZ430RF2500T wireless development kits. These devices are extremely cheap and open source with lots of sample code, resources and tools. The initial project I will be highlighting on this blog is a Mini-Quad copter using the Launchpad and an EZ430 RF for wireless remote control. Watch for posts that report the progress on the quad copter and provide some of the technical aspects that are learned along the way. If you find this blog entertaining or informative please be sure to drop me a line or comment. Embedded Enthusiast or Mad scientist. I am not sure which I am.