Sunday, July 1, 2012

GIO Input and Output of TelosB

This program can be used as a reference for the usage of General Input Output pin(GIO) of TelosB. Here i a have used the GIO output of TelosB to connect a buzzer and trigger it in every 2 seconds, making it on and off.

General input/output pin details of TelosB is given below.

GIO No.
TeloB Pin out
MSP430 processor Pin out
Note
GIO-0
10 (10 pin connector)
20
Have to short R16 in TelosB
GIO-1
7 (10 pin connector)
21
Have to short R14 in TelosB
GIO-2
3 (6 pin connector)
23

GIO-3
4 (6 pin connector)
26


In my program i have used GIO3 and hence i have connected the positive of buzzer to 4th pin of 6 pin expansion connector and negative to Gnd of TelosB.


This is the configuration for the application.
configuration BuzzerAppC {
}

implementation{
   components BuzzerC, MainC;
   components HplMsp430GeneralIOC;
   components BusyWaitMicroC;
   components new TimerMilliC() as Timer;
   components LedsC;

   BuzzerC.Boot -> MainC.Boot;
   //BuzzerC.indication2 -> HplMsp430GeneralIOC.Port23; For input
   BuzzerC.indication3 -> HplMsp430GeneralIOC.Port26; 
   BuzzerC.Timer -> Timer;
   BuzzerC.delay -> BusyWaitMicroC;
   BuzzerC.Leds -> LedsC;
}

This is the module for the application.
module BuzzerC{
   uses interface Boot;
   uses interface HplMsp430GeneralIO as indication3;
   uses interface BusyWait as delay;
   uses interface Timer as Timer;
   uses interface Leds;
}

implementation{
  uint16_t value;
  uint16_t i;
  event void Boot.booted() {
    call Timer.startPeriodic(2000);
  }
  event void Timer.fired() {
    call Leds.led0Toggle();
    call indication3.makeOutput();
    call indication3.set();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
    call indication3.clr();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
  }  
}

10 comments:

  1. uses interface Timer should be Timer and uses interace BusyWait should be BusyWait, yes?

    ReplyDelete
    Replies
    1. Comment deleted the important part. (It deletes anything inside "<", which I will hereby imply with "[")

      uses interface Timer should be Timer[TMilli] and uses interface BusyWait should be BusyWait[TMicro, uint16_t], yes?

      Delete
  2. Ya you are right. Thanks for the correction.

    ReplyDelete
  3. Where did you get the General input/output pin details of TelosB? I cannot find it in the datasheet.

    ReplyDelete
  4. Hello Prasanth P,

    I have written the following code to interface an ir sensor- TSOP-OBSD single with the telosb mote. The IR sensor gives a digital low on obstacle detection and high otherwise. Can the you tell if the code is correct or is there any logical or syntax error in it.

    MODULE-

    module irsensorC{
    uses {
    interface Boot;
    interface Leds;
    interface Timer as PirReadTimer;
    interface GeneralIO as PirInput;
    }
    }

    implementation{
    uint16_t pirValues = 0;

    void report_problem() { call Leds.led0Toggle(); }

    event void Boot.booted(){
    call PirInput.makeInput();
    call PirReadTimer.startPeriodic(100);
    }

    event void PirReadTimer.fired() {
    if (call PirInput.get()){
    call Leds.led2Toggle();
    }

    else{
    pirValues++;
    call Leds.led1Toggle();}
    }
    }

    CONFIGURATION-

    configuration irsensorAppC{

    }
    implementation{

    components MainC,LedsC;
    components irsensorC as ir;
    components new TimerMilliC() as PirReadTimer;
    components new Msp430GpioC() as PirInput;
    components HplMsp430GeneralIOC as GeneralIOC;

    ir.Boot -> MainC;
    ir.Leds -> LedsC;
    ir.PirReadTimer -> PirReadTimer;
    ir.PirInput -> PirInput;
    PirInput -> GeneralIOC.Port21;


    }

    ReplyDelete
  5. Problem is I am not getting the output on the hardware-

    As you can see i have used two led in the code to show the output . Led 2 glows when the input at pin 3/4 (changed the code to get input at Port 26) is low and led1 glows when the input at the pin is high.Immediately after the program is burned on the mote the timer is fired for 1000ms and led 2 glows because we have not yet connected the output wire of the sensor with the pin so logically input at pin 3 is low and so output is correct. As soon as the output wire of the sensor is connected to the pin led1 glows because we have not put any obstacle in front of the sensor. Error starts at this point with both the led glowing in sequence after every 1000ms irrespective of putting any object in front of the sensor.

    ReplyDelete
  6. Hello Sir

    I am new to telosb and I have tried your code. I dont know whats wrong but I get the following errors at compilation:
    mkdir -p build/telosb
    compiling BuzzerApp to a telosb binary

    WARNING: Minimum recommended msp430-gcc version for this TinyOS release is 4.6.3!!!

    ncc -o build/telosb/main.exe -Os -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DDEFINED_TOS_AM_GROUP=0x22 -DIDENT_APPNAME=\"BuzzerApp\" -DIDENT_USERNAME=\"tomski\" -DIDENT_HOSTNAME=\"freedom\" -DIDENT_USERHASH=0x711c7d71L -DIDENT_TIMESTAMP=0x551ab188L -DIDENT_UIDHASH=0x2526d909L BuzzerApp.nc -lm
    In file included from BuzzerApp.nc:5:
    In component `BuzzerC':
    BuzzerC.nc:4: too few arguments to interface `delay'
    In file included from BuzzerApp.nc:5:
    BuzzerC.nc:5: too few arguments to interface `Timer'
    In file included from BuzzerApp.nc:5:
    BuzzerC.nc: In function `Timer.fired':
    BuzzerC.nc:20: incompatible type for argument 1 of `delay.wait'
    BuzzerC.nc:24: incompatible type for argument 1 of `delay.wait'
    make: *** [exe0] Error 1

    Could you please help me?
    I just want to have my buzzer ringing, then I will code more :-)
    Many thanks in asdvance for your help

    ReplyDelete
    Replies
    1. fixed, everything works fine now! you can delete my previous post^^

      Delete
  7. Hi. Do you have a post where you do serial communication between TelosB and another microcontroller (say Tiva Launchpad) through TelosB? Or could you do a post on HplMSP430Uart interface?

    ReplyDelete