Programming Classes Monday: Sensor reading over TinyOS Wednesday: Message sending and receiving between TelosB motes Friday: Android programming ECE 455/555 Embedded System Design 1 Course Project Check-out your devices TelosB motes: you can check-out your second mote from the TA next week Smartphone: send me the type and quantity of phones you need, then check-out from the TA Customized devices: purchase online, get money back at the end of semester Start acting NOW! Next milestone Project midterm presentation & demo: 10/7 & 10/9 ECE 455 Embedded System Design 2 ECE 455/555 Embedded System Design TinyOS: Sensor Reading Wei Gao Fall 2015 3 Recall about TinyOS Component model An application consists of Application Component D wired components Component A Application = graph of components Components are wired through interfaces Wiring specified by configurations configuration Configuration can be hierarchical Component C Component B Component F Component E ECE 455/555 Embedded System Design configuration 4 Interfaces List of exposed events and commands Like ordinary C function declarations Interface Receive { event message_t * Receive(message_t * msg, void * payload, uint8_t len); command void * getPayload(message_t * msg, uint8_t * len); command uint8_t payloadLength(message_t * msg); } command needs to implemented by components providing the interface event needs to be handled by components using the interface ECE 455/555 Embedded System Design 5 The Surge Example ECE 455/555 Embedded System Design 6 Sensor Reading A sensor that reads from the internal voltage sensor, and displays them on LEDs. /opt/tinyos-2.x/apps/Sense ECE 455/555 Embedded System Design 7 SenseC Configuration configuration SenseAppC { } implementation { Components SenseC, MainC, LedsC, new TimerMilliC(); components new DemoSensorC() as Sensor; SenseC.Boot -> MainC; SenseC.Leds -> LedsC; SenseC.Timer -> TimerMilliC; SenseC.Read -> Sensor; } The application starts after mote is booted The application connects to the LEDs Get sensor readings periodically, controlled by a timer ECE 455/555 Embedded System Design 8 Sense Module module SenseC { uses { interface interface interface interface }} Boot; Leds; Timer<TMilli>; Read<uint16_t>; event void Boot.booted() { call Timer.startPeriodic(SAMPLING_FREQUENCY); } event void Timer.fired() { call Read.read(); } event void Read.readDone(error_t result, uint16_t data) { // call Leds.led0/1/2 on/off() } Start the timer, when time is up, read the data from sensor Toggle the LEDs according to the sensor readings ECE 455/555 Embedded System Design 9 Sense Module event void Read.readDone(error_t result, uint16_t data) Integer in numbers of mV { if (result == SUCCESS){ Blue LED on if the 3rd lowest bit of data is 1 if (data & 0x0004) call Leds.led2On(); else call Leds.led2Off(); if (data & 0x0002) Green LED on if the 2rd lowest bit of data is call Leds.led1On(); else call Leds.led1Off(); Red LED on if the lowest bit of data is 1 if (data & 0x0001) call Leds.led0On(); else call Leds.led0Off(); } } } 1 Note the method of checking bits here! ECE 455/555 Embedded System Design 10 Implementation of DemoSensorC generic configuration DemoSensorC() { provides interface Read<uint16_t>; } Implementation { components new VoltageC() as DemoSensor; Read = DemoSensor; } tos/platforms/telosb/DemoSensorC.nc generic configuration VoltageC() { provides interface Read<uint16_t>; } implementation { components new Msp430InternalVoltageC(); Read = Msp430InternalVoltageC.Read; } tos/platforms/telosb/VoltageC.nc tos/chips/msp430/sensors/Msp430InternalVoltageC.nc ECE 455/555 Embedded System Design 11 Reading from more sensors Internal temperature sensor of MSP430 chip tos/chips/msp430/sensors/Msp430InternalTemperatur eC.nc External temperature, humidity and light sensors Temperature: Sensirion SHT11 • tos/platforms/telosa/chips/sht11/SensirionSht11C.nc Humidity: Sensirion SHT11 • tos/platforms/telosa/chips/sht11/SensirionSht11C.nc Light: Hamamatsu S1087 • tos/platforms/telosa/chips/s1087/HamamatsuS1087ParC.nc Efficient display??? ECE 455/555 Embedded System Design 12 Lab 2 Announcement Lab 2 is due 10/7 (5:30pm Wednesday) Check out your second sensor from the TA 5% in final grade You will work on it on your own Need to let the TA check you off • Turn in printed program codes after check-off Sensor reading and message sending/receiving Need to program two motes • Everyone should check out two more motes from the TA Mote1 periodically reads light sensor, displays the readings on the LEDs, and sends it to the radio Mote2 receives the reading and displays it on the LEDs ECE 455/555 Embedded System Design 13