180 likes | 191 Views
This project involves reading data from a light sensor (photodiode) connected to Atmega128, displaying it on an oscilloscope using ZigbeX, and transmitting it to a PC via UART. The system includes components such as CDS, ADC, and UARTComm for data transmission. The Oscilloscope Lab setup uses various modules like TimerC, LedsC, DemoSensorC, and UARTComm for configuring and implementing the system. The Java application helps in configuring the system, and the project can be executed by following the specified steps in Cygwin and AVR Studio.
E N D
Light Sense Lab. Read data from light(photo diode) sensor, display using oscilloscope.
ZigbeXPhoto Diode • Photo diode CDS • named CDS is connected to INT0 &ADC0 on Atmega 128(8bit CPU) • CDS inputs resistance value varying on light strength • Output to ADC0 • Light Sensor Component • Photo component
Photo component • ADCC component • Photo component needs to uses upper level component ADCC.
Read Light strength • Ex. // upper level comp event ADC.dataReady(uint16_t data) { //data -> measured data … } // upper level comp. xxx_function() { call ADC.getData() … } Photo component
Oscilloscope Lab • Oscilloscope program • Oscilloscope program delivers data from mote to PC via “com” port • Oscilloscope Location • c:\Programfiles\UCB\cygwin\opt\tinyos‐1.x\contrib\zigbex\ Osilloscope • Oscilloscope.nc,OscilloscopeM.nc, &OscopeMsg.h .
Oscilloscope.nc • Oscilloscope.nc • Osilloscope components • UART Comm – connecting to PC • DemoSensorC- Get the light data • TimerC &LedsC configuration Oscilloscope { } implementation { components Main, OscilloscopeM, TimerC, LedsC, DemoSensorC as Sensor, UARTComm as Comm; Main.StdControl ‐> OscilloscopeM; Main.StdControl ‐> TimerC; OscilloscopeM.Timer ‐> TimerC.Timer[unique("Timer")]; OscilloscopeM.Leds ‐> LedsC; OscilloscopeM.ADC ‐> Sensor; … }
Serial Comm. • UARTComm component • UARTComm provides ReceiveMsg interface and SendMsg interface.
OscilloscopeM.nc • OscilloscopeM.nc (1) includes OscopeMsg; module OscilloscopeM { provides interface StdControl; uses { … // interfaces } } implementation { … // variables command result_t StdControl.init() { … // initialization return SUCCESS; }
OscilloscopeM.nc • OscilloscopeM.nc (2) command result_t StdControl.start() { call SensorControl.start(); call Timer.start(TIMER_REPEAT, 125); call CommControl.start(); return SUCCESS; } command result_t StdControl.stop() { … return SUCCESS; } event result_t Timer.fired() { return call ADC.getData(); }
OscilloscopeM.nc • OscilloscopeM.nc (3) async event result_t ADC.dataReady (uint16_t data) { struct OscopeMsg *pack; atomic { pack = (struct OscopeMsg *) msg[currentMsg].data; pack‐>data[packetReadingNumber++] = data; readingNumber++; dbg(DBG_USR1, "data_event\n"); if (packetReadingNumber == BUFFER_SIZE) { post dataTask(); } } if (data > 0x0300) call Leds.redOn(); else call Leds.redOff(); return SUCCESS; }
OscilloscopeM.nc • OscilloscopeM.nc (4) task void dataTask(){ struct OscopeMsg *pack; atomic { pack = (struct OscopeMsg *)msg[currentMsg].data; packetReadingNumber = 0; pack‐>lastSampleNumber = readingNumber; } pack‐>channel = 1; pack‐>sourceMoteID = TOS_LOCAL_ADDRESS; if (call DataMsg.send(TOS_UART_ADDR, sizeof(struct OscopeMsg), &msg[currentMsg])) { atomic { currentMsg ^= 0x1; } call Leds.yellowToggle(); } } event result_t DataMsg.sendDone (TOS_MsgPtr sent, result_t success) { return SUCCESS; }
Oscilloscope lab. 1 • Starts cygwin. Move to folder as follows • make zigbex cd /opt/tinyos‐1.x/contrib/zigbex cd Oscilloscope
Oscilloscope lab. 2 • ZigbeX Download • Run AVR studio at Windows • Tolol->auto connect-> browse main.hex located at • c:\Programfiles\UCB\cygwin\opt\tinyos‐1.x\contrib\zigbex\Oscilloscope\ build\ zigbex
Oscilloscope lab. 3 • Java application • When it is configured correctly, • Move to/opt/tinyos‐1.x/tools/javain Cygwin • Type as follows export MOTECOM=serial@COM1:57600 cd /opt/tinyos‐1.x/tools/java java net.tinyos.oscope.oscilloscope
Oscilloscope result • Result