Using the GPIO on a tmote to make a LED blink


I know this might sound pretty silly, but since I couldn’t find anywhere else how to do it, and I had to spend quite a lot of time figuring it out myself, I decided to post it. So, if you need to interface a brighter LED on a tmote sky (or whatever needs a digital input), connect the ground of the LED to pin 9 of the 10-pin expansion header of the tmote, and the other cable to pin 3 of the 6-pin expansion header (which is GPIO port 2, refer to the tmote datasheet for more info). After that, you need to write a proper “driver” to set pin 2.3 of the msp430 (tmote’s CPU) to 1 or 0. You can use the following macros:


#define P23_OUT() P2DIR |= BV(3)
#define P23_IN() P2DIR &= ~BV(3)
#define P23_SEL() P2SEL &= ~BV(3)
#define P23_IS_1  (P2OUT & BV(3))
#define P23_WAIT_FOR_1() do{}while (!P23_IS_1)
#define P23_IS_0  (P2OUT & ~BV(3))
#define P23_WAIT_FOR_0() do{}while (!P23_IS_0)
#define P23_1() P2OUT |= BV(3)
#define P23_0() P2OUT &= ~BV(3)

For example, to make the led blink at intervals of 1 sec (this is contiki code, but apart from the timer it’s standard C):



	etimer_set(&mytimer, CLOCK_SECOND);
		printf("Changing 1\n");
		printf("It's one\n");
		printf("Changing 0\n");
		printf("It's zero\n");

11 Responses to “Using the GPIO on a tmote to make a LED blink”

  1. Manish Says:

    ahh.. how I miss working with the motes!

  2. Ettore Says:

    eh eh you’re welcome to come and play whenever you like 🙂 We miss working with you 🙂

  3. Thomas Says:

    Thanks for this entry. Can you provide information how to access the other ports too?

  4. Ettore Says:

    Well, you would need to have a look at the tmote datasheet, find out which pin your port is connected to and then modify the code above. Which port are you thinking about exactly?

  5. Mike Says:

    Thanks! This helped me figure out the digital I/O on the tmote. Do you have any resources for using DACs? I’ve been sorting through the MSP430 data sheets and attempting to set the control registers to use DACs and so far no luck.

  6. Mike Says:

    Hey… this is a follow up for anyone interested. I figured out how to use a DAC output. The main issue is that I didn’t set a voltage reference for the ADC at first. Here’s my sample code, I hope it helps!

    ADC12CTL0 |= (REF2_5V | REFON);
    DAC12_0CTL |= (DAC12IR | DAC12AMP_5 | DAC12ENC);
    DAC12_0DAT = 0x0FFF;

    The first two lines do all the necessary configuring for the DAC. The final line sets the 12-bit output value (between 0 and 4096). This is a linear map between 0v and your reference voltage (2.5v in this case).

  7. hector Says:

    Hey I need help..i`m new using the T-mote and I need to interface an enconder`s output to the digital input of the t-mote.

    I`m trying to do something with the information I found here but i haven`t find good results…I need to count the pulses of the encode`s outoput and then transmit it it`s that possible?

    please help me….

  8. Ettore Says:

    I would say you need to read the status of the pins in the same way… where do you need to transmit the output then?

  9. Han Says:


    I have a small question regarding activating any device through IRIS gateway.

    You are kindly requested to advice and direct us to the proper methods
    of connecting any type of actuator.

  10. André Says:


    I´m working with contiki and I don´t find any declaration of variables like REF2_5V,… Can someone help me. I need to interact with pin connector from TMote Sky (U2 and U28).


  11. alarm wall clock Says:

    alarm wall clock…

    […]Using the GPIO on a tmote to make a LED blink « Look here first![…]…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: