Jump to content

EZ430 Soft Switch (DIY Skylanders Portal)

Recommended Posts

Made a base similar to the Skylanders Portal, with some spray foam, coroplast, and Color Changing LEDs. This was added to a Totem Pole. Kid brother's school project.
Used an EZ430-F2013 as a simple Soft Switch, leds on 5 minute timer, to save the batteries from being drained.
Code (main.c):

#include "common.h"

EZ430 Soft Switch, 5 Minute Sleep Timer using Watchdog
LED is P1.0 D1 on EZ430
TRANS is P1.1 2n2222 Transistor Base
PB is P1.2 Pushbutton
P1.3-P1.7, P2.6, P2.7 free

bool switch_state = 0;

void cpu_init(void)
     WDTCTL = WDTPW + WDTHOLD;  // Stop WatchDog Timer
     BCSCTL1 = CALBC1_1MHZ;     // Set range to 1mhz Calibrated Range
     DCOCTL = CALDCO_1MHZ;      // Set DCO to 1mhz Calibrated DCO
                                // SMCLK = DCO = 1MHz
     P2SEL &= ~BIT6 & ~BIT7;	// Disable External Oscillator Pins
     P2DIR |= BIT6 | BIT7;	// Set as Output
     P2OUT &= ~BIT6 & ~BIT7;	// Set as Output Low

void out_init(void)
     P1SEL &= ~LED & ~TRANS;     // Set Pins as GPIO
     P1DIR |= LED | TRANS;       // Set Pins as Output
     P1OUT &= ~LED & ~TRANS;     // Set LED and TRANS Pins to Off

     // Used for Testing, not needed as will not be visible
//     P1OUT |= LED;               // Turn on EZ430 LED

void pushbutton_init(void)
     P1SEL &= ~PB;     // Set Button as GPIO
     P1DIR &= ~PB;     // Set Button as Input
     P1REN |= PB;      // Set Buttons Pull-Up/Pull-Down Mode
     P1OUT |= PB;      // Set Buttons Pull-Up
     P1IES |= PB;      // P1.2 Interrupt set for High to Low Transition (Active Low)
     P1IFG &= ~PB;     // P1.2 Interrupt Flag Cleared
     P1IE  |= PB;      // P1.2 Interrupt Enabled

// Port 1 interrupt service routine
#pragma vector = PORT1_VECTOR
__interrupt void Port_1_ISR(void)
     // Clear LPM & Disable Interrupts to Allow main() to handle commands before returning to sleep
     _BIC_SR_IRQ(LPM4_bits + GIE);

     // Check which button pressed
     if ( (P1IFG & PB) == 0x04) {
          if (switch_state == 0) switch_state = 1;
          else switch_state = 0;

     // Debounce
     // P1.2 IFG cleared
     P1IFG &= ~PB;

volatile int second_count = 0;
volatile int minute_count = 0;

void timeDog_on(void)
     WDTCTL = WDT_MDLY_32;	// WatchDog Interval (Clock Source / Interval) (SMCLK / 32)
				// 1MHz / 32 = 31.25kHz
				// 1 / ( Clock Source / Interval ) = Freq in Milliseconds
				// Happens 32 times per second! Duh! Every 32766 Clock Ticks. DUH!

     IE1 |= WDTIE;		// Enable WatchDog Interrupt, Still need to enable Global Interrupts

void timeDog_off(void)
     WDTCTL = WDTPW + WDTHOLD;     // Stop WatchDog Timer
     IE1 &= ~WDTIE;		          // Disable WatchDog Interrupt

     minute_count = 0;             // Reset Timer Count to 0
     second_count = 0;             // Reset Timer Count to 0

// WatchDog interrupt service routine
#pragma vector = WDT_VECTOR
__interrupt void WatchDog_ISR(void)
     second_count++;                 // 32 Interrupts per Second * 60 seconds = 1920 per minute
     if (second_count >= 1920) {
          second_count = 0;

     if (minute_count >= 5) {
          switch_state = 0;
//          __low_power_mode_off_on_exit();     // Exit LPM at Interrupt End
          _BIC_SR_IRQ(LPM4_bits + GIE);

void scripted_wait(void)
     // SW Delay (how many seconds??)
     volatile unsigned int hick;
     hick = 10000;
     do hick--;
     while (hick != 0);

int main(void)

     // Turn on Switch when first plugged in for 30 seconds
     minute_count = 4;
     second_count = 960;
     switch_state = 1;

     // Setup Complete, now check state, run function, then go to sleep with interrupts
     while (1) {
          if (switch_state == 0) {
               P1OUT &= ~TRANS;              // Switch Off
               timeDog_off();                // Disable Watchdog Interrupt
//               __low_power_mode_4();       // Sleep until Button Press
               __bis_SR_register(LPM4_bits + GIE);
	  else if (switch_state == 1) {
               P1OUT |= TRANS;               // Switch On
               timeDog_on();                 // Enable Watchdog Interrupt
//               __low_power_mode_0();       // Sleep with Timer
               __bis_SR_register(LPM0_bits + GIE);

Code (common.h):

#ifndef COMMON_H
#define COMMON_H 1

#include <msp430f2013.h>
#include <stdbool.h>

#ifndef TRUE
#define TRUE true
#ifndef FALSE
#define FALSE false
#ifndef BOOL
typedef bool BOOL;

#define LED     BIT0 // P1.0
#define TRANS   BIT1 // P1.1
#define PB      BIT2 // P1.2

void scripted_wait(void);


(not 100% complete, missing on board Reset pull-up, Decoupling Cap, and most of the EZ430 programming board stuff)
The lights were made using some Slow Color Changing LEDs from a USB . These have a microcontroller inside providing current control and pwm. No resistor needed, and have a wide input range. But 3V is not enough for full brightness and colors, so the entire EZ430-F2013 stick was used. This is for a few reasons:

  • Power. The LEDs need 4V + for brightness, while the msp430 needs 3.5V. The EZ430's USB input and regulator ensures I have both voltages.
  • Plug and Play. I can reprogram the stick without having to worry about the 0.05" pins or wiring, or a programmer.
  • Adaptability. Currently uses a 3x AA battery pack with a usb female connector, can easily be switched to a USB wall charger without any changes.
  • I have multiple EZ430s lying around.

After figuring out the electronics (A simple NPN transistor is used, while the base resistor is probably undersized as I did not actually measure the total LED current consumption, bad cde, bad.), the code took some testing. Using the Watchdog timer and LPM0 and LPM4, as well as a switch, the lights turn on for 30 seconds when first plugged into power. After turning off, it works as follows. LPM4 until the switch is pressed, then the lights turn on. Dropping into LPM0 as the Watchdog Timer uses the SMCLK, it counts to 5 minutes then turn off, or it can be turned off by pressing the switch again. No hardware debounce, just some for loop delays, it works fine as long as the switch isn't held in for long, otherwise it might turn off/on again.
The Totem was made using a PVC pipe, with plaster shaped on top. The Base was made using three things. The first is the coroplast (corrugated plastic, like cardboard. Same stuff street signs are made of). The one used was fairly opaque, a more transparent one would have been better. Once it was cut to size and holes drilled for the leds, the second part is some cardboard rolled around it. Once taped, the dirty part of the job was getting Expanding Spray Foam onto the sides. This was harder than it should have been since the can I used had a broken nozzle. Simply hold it from the inside, spray the foam on, rotate, spray some more, let it dry, rotate, spray some more, etc (a coat hanger worked great to hold it up between rotations). I pressed some of the air out once it started drying, be careful as spray foam is incredibly sticky, and at some points pulls, while at others it gets stringy. Finally done and hardened to touch, some of the less rocky parts were cut off with an exacto knife. It was then painted using some grey primer. No highlighting needed due to the texture and grooves creating shadows.
(Warning, some spray foams will melt/be eaten away by some spray paints. I used Great Stuff brand spray foam from Home Depot, and I forget the spray paint brand). Hint, there is multiple types. The beige one I used expands more (1" holes) while the pink one (fire/heat resistant) is stiffer and has less air pockets. If I had to do this again, I would use the pink for it all. This is a basic cosplay/halloween prop/decoration technique :D

Once done, everything was assembled. He has to get an A.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...