Upload
mevenwen-singollo
View
692
Download
8
Embed Size (px)
Citation preview
พ.อ.ปรชญา เฉลมวฒน, Ph.D.
พ.อ.รศ.สรตน เลศล า, Ph.D.
พ.อ.ศภชย ศรหอม
โรงเรยนนายรอยพระจลจอมเกลา
อ.เมอง จ.นครนายก
การพฒนาระบบเซนเซอรเนตเวรคเบ องตน (Work In Progress)
WUNCA24 2011: CRMA Sensor Network (Work-in-
Progress) 1
หวขอบรรยาย
กลาวน า – ระบบ Wireless Sensor Network (SL)
การออกแบบ CRMA Sensor Network
องคประกอบของ sensor network
Sensor Nodes
MCU ทใชในระบบ sensor network (SS)
ARM-based Linux Subnode
Portal/Display Servers
ขอพจารณาเกยวกบ Power Consumption
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 2
Preferred Audience Background
Internetworking, TCP/IP
C Programming
Windows 7 Experiences, Terminal, PuTTY
Digital Fundamentals
Electronics
Wiring, Soldering
Tools: cut, drill, glue
$$$
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 3
Wireless Sensor Network
ท าไมตองม Sensors?
Environment Data Temperature/Humidity
Wind Speed/Direction
Light, Object movement
Motion/Tilt
Sound, Image, Video
ประโยชนตอการศกษา patterns, time series data
ท าไมตอง Wireless?
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 4
Prof. Surat
CRMA Sensor Network
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 5
Conceptual Design
CRMA Sensor Network
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 6
Conceptual Design Intermediate Nodes
Sensor Nodes
Serial,
LAN,
Xbee, Bluetooth
Serial,
LAN,
Xbee, Bluetooth
Se
rial, I2
C, 1
-Wire
, SP
I
Sensor Nodes
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 7
Nodes Level Functions
Portal
Server
User level: display information
in graph, numbers; OS=Linux, Windows
Linux Sub-
nodes
Intermediate level: process data
from MCUs, reformat, backup,
recalculate; OS=Linux, Windows
MCUs Lowest level: collect
digital/analog data from various
sensors, perform basic
calculation, data logger; OS: MCU level
Microcontrollers
การสอสารกบ Sensors
RS232 – serial communication
LAN – TCP/IP stack
Xbee – serial over wireless
Bluetooth
Edge/GPRS modem
WiFi
Off-Line via SD data logger
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 8
MicroClient JrMx
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 9
www.norhtec.com http://www.norhtec.com/products/mcjrmx/index.html
• 1Ghz Xcore86 CPU (x586 CPU with
MMX compatible extensions)
• RAM 512 MB (1GB possible)
• 3 USB 2.0 ports
• RS232
• SATA Hard Disk option
• WIFI available $25.00
• 8 GB SD card slot
• THB 6,600
ตดตง Linux บน JrMX
เชนเดยวกบการตดตง Linux ทวไป ในกรณทม Hard Disk
ในกรณทใช SD card สามารถใชเครองมอ Universal USB
Installer (ท www.pendrivelinux.com) โดยตดตงแบบ
persistent
การท างานเชนเดยวกบไมโครคอมพวเตอรทวไป
ขอด เสยงเงยบ, กนไฟนอย, ทนอณภมไดสง, ราคาถก, มพอรต
ตางๆ ใหใชงานสมบรณ
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 10
Skipped
ARM-based Linux Subnode
แนะน า Mini2440/6410 บอรด Embedded
การตดตง Linux ลงในบอรด Mini6410
การสอสารระหวาง MCU กบ Linux
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 11
Mini2440/6410
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 12
FriendlyArm
Mini2440/6410
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 13
FriendlyArm
2440 6410
400 MHz Samsung S3C2440 ARM9
533 MHz Samsung S3C6410 ARM11
64 MB RAM 128 MB / 256 MB
128 MB / 256 MB / 1GB NAND
256 MB / 1GB NAND
SD-Card SD-Card/SDIO socket
RS232 RS232
THB 5,580.- THB 6,000.-
Mini2440/6410
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 14
FriendlyArm
Mini2440/6410
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 15
FriendlyArm
RS232 USB
DVD
USB Serial
Video J-Tag
Display
AC
Mini2440/6410
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 16
FriendlyArm
• Linux kernel 2.6
• QT (Xwindows) interface
• Touch screen
• Serial Port
• Video (on 6410)
• Audio
• USB
• SD card
ตดตง Linux บน 2440
1. ดาวนโหลดไฟล Image จากเวบไซต andahammer เลอกไฟลท
ตองการใหตรงกบ Board และจอภาพ
2. ตอสายเคเบล USB และ Serial (RS-232) เขาระหวางคอมพวเตอร
กบ Mini2440 ถาไมม serial ใหใช USB-Serial converter
(อาจตองลง driver ใหมากบแผนดวด)
3. รนโปรแกรม dwn (ใน “Windows Tools/dwn”)
4. ปรบสวทช S2 ใหเปน NOR
5. กดปม Reset
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 17
ตดตง Linux บน 2440
6. หนาจอของ DWN จะมเมนขน Serial, USB, Config โปรแกรมบนเครองควบคมผาน terminal ผานสาย serial และการน าไฟลไปไวท flash ของ Mini2440 นนใชการ upload/download ผานสาย USB
7. ท าพารตชน (หากตองการ)
8. ตดตง bootloader (supervivi)
9. ตดตง zImage (Linux kernel)
10. ตดตง FS
11. รบต
12. ปรบสวทช S2 กลบ
13. ปดเครองแลวเปดใหม เพอทดสอบ OS ทลงใหม ดรายละเอยดการบตผาน serial terminal
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 18
ตดตง Linux บน 6410
เตรยม OS บน SD card บนเครองคอมพวเตอร
1. ในทนใช SD ขนาด 4 GB
2. รน SD-Flasher ดวย Administrator, คลกขวาท SD-Flasher
(tools/SD-Flasher)
3. เลอกไฟล images/superboot-20100917.bin ใน Image File
to Fuse
4. คลกปม Scan จะม removable SD อยในชอง SD Drive(s)
5. สงเกตวาในคอลมน Available ตองเปน Yes ถาเปน No ใหกดปม
ReLayout แลวดวาส าเรจหรอไม (1 Succeeded)
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 19
ตดตง Linux บน 6410
เตรยม OS บน SD card บนเครองคอมพวเตอร (ตอ)
6. ถา ReLayout ไมส าเรจ ใหท าการ format SD ใหม (ลองทง Quick format และแบบปกต) จากนนใหท าการ Scan ใหมเพอดวา Available นนเปน Yes หรอไม
7. ถา Available เปน Yes ใหกดป ม Fuse กเปนอนเสรจการตดตง SuperBoot ลงบนแผน SD
8. เปด File Explorer แลวไปทไดรฟของ SD สรางไดเรกทอรชอ images
9. ส าเนาโฟลเดอร OS ทตองการ เชน Ubuntu, Linux, Android จาก images/ ของแผน DVD ไปไวทโฟลเดอร images บน SD
10. ส าเนาไฟล FriendlyARM.ini จากโฟลเดอร images ไปไวทโฟลเดอร images บน SD
11. แกไขไฟล FriendlyARM.ini แลวเลอก OS ทตองการ boot
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 20
ตดตง Linux บน 6410
เตรยม SD บนเครอง Mini6410
1. eject SD จากเครองคอมพวเตอร แลวน าไปใสในชอง SD
2. ปรบสวทช S2 ใหเปน SD แลวเปดเครอง - จะมเสยง beep หนงครง จากนน
ไฟ LED สเขยวจะกระพรบไปเรอย ถาการตดตงส าเรจ จะมเสยง beep beep
แตถาไมส าเรจ (อาจเกดจากความผดพลาดบางประการ เชน เลอกโมดลไม
ถกตอง) จะมเสยง beep ตดดบตลอดเวลา ใหปดสวทชเครองแลวทดลองใหม
3. ถาตดตงส าเรจ ปรบสวทช S2 ใหเปน NAND boot แลวเปดเครองใหม
4. สงเกตการรนของบอรดผาน Terminal, Putty หรอ DWN ทเชอมตอผาน
serial
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 21
ไฟล FriendlyARM.ini #This line cannot be removed. by FriendlyARM(www.arm9.net)
CheckOneButton=No #Action=install Action=run OS=Linux VerifyNandWrite=No StatusType = Beeper| LED ############# Linux ##### Linux-BootLoader = Linux/u-boot_nand-ram128.bin Linux-Kernel = Linux/zImage_A70 Linux-CommandLine = root=/dev/mtdblock2 rootfstype=yaffs2 init=/linuxrc console=ttySAC0,115200 Linux-RootFs-InstallImage = linux/rootfs_qtopia_qt4-s.img Linux-RootFs-RunImage = linux/rootfs_qtopia_qt4-s.ext3
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 22
ไฟล FriendlyARM.ini ################### WindowsCE6
################# WindowsCE6-Bootloader= WindowsCE6\NBOOT_A70-RAM128.nb0 WindowsCE6-BootLogo = WindowsCE6\bootlogo.bmp WindowsCE6-InstallImage = WindowsCE6\NK_A70-s.bin WindowsCE6-RunImage = WindowsCE6\NK_A70-s.bin ################### Android #################### Android-BootLoader = Android/u-boot_nand-ram128.bin #Android-Kernel = Android/azImage_a70 Android-Kernel = Android/azImage_n43 Android-CommandLine = root=ubi0:FriendlyARM-root ubi.mtd=2 rootfstype=ubifs init=/linuxrc console=ttySAC0,115200 Android-RootFs-InstallImage = Android/rootfs_android-s.ubi Android-RootFs-RunImage = Android/rootfs_android-s.ext3
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 23
ไฟล FriendlyARM.ini ################### Ubuntu
##################### #Ubuntu-BootLoader = Ubuntu/u-boot_nand-ram128.bin #Ubuntu-BootLoader = Ubuntu/u-boot_nand-ram256.bin Ubuntu-BootLoader = Ubuntu/u-boot_sd-ram256.bin #Ubuntu-Kernel = Ubuntu/uzImage_a70 Ubuntu-Kernel = Ubuntu/uzImage_n43 Ubuntu-CommandLine = root=ubi0:FriendlyARM-root ubi.mtd=2 rootfstype=ubifs init=/linuxrc console=ttySAC0,115200 Ubuntu-RootFs-InstallImage = Ubuntu/rootfs_ubuntu-s.ubi Ubuntu-RootFs-RunImage = Ubuntu/rootfs_ubuntu-s.ext3 ############### UserBin part ################# UserBin-Image=WindowsCE/NK.nb0 userBin-StartAddress=50100000
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 24
Arduino MCUs
Arduino MCU (Duemilanove, Mega, Nano)
การเชอมตอ sensor เขากบ MCU
DS18S20 Temperature sensor
SHT1x Temperature & Humidity sensor
Analog light sensor
Distance sensor
Wind Speed
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 25
Microcontrollers
Arduino MCUs
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 26
Duemilano
ve 2009
Uno Mega
atmega1280
Mega
atmega2560
Nano
168/328
uCon Atmega
168-328 328 1280 2560 168/328
Digital I/O 14 14 54 54 (14 PWM) 14
Analog Inputs
6 8 26 16 8
Flash/Bootload
16-32K/2K 32K/2K 128K/4K 256K/8K 32K/2K
SRAM 1K 2K 8K 8K 2K
EPROM 512-1K 1K 4K 4K 1K
Clock 16MHz 16MHz 16MHz 16MHz 16MHz
USB Yes Yes Yes Yes Mini
Cost $ $18.75 $25.00 $28.98 $44.00 17.99
THB 571.88 762.50 883.89 1,342.00 548.70
Arduino MCUs
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 27
Mega Duemilanove Nano
Duemilanove
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 28
Arduino MCUs
การโปรแกรม MCU เบ องตนดวย Arduino IDE (SS)
การแสดงผลผานจอ LCD LCD 1602, 1604
Nokia LCD
การสงขอมลผาน Serial
การสอสารขอมลของ MCU
การตดตง EtherShield
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 29
LCD 1602/1604
LiquidCrystal.h
จอ LCD (210 THB)
HD44780-based
Backlight
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 30
LCD 1602/1604
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 31
LCD Hello World!
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 32
LCD: Nokia 5110
จอเลก, ราคาถก, กนไฟนอย
6 บรรทด 82 จด
3.3 V
Backlight
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 33
NokiaLCD.h #include <OneWire.h> // for DS18S20
// For NOKIA LCD 5110
// The pins to use on the arduino
#define PIN_SCLK 3 // NKLCD-7 --> D3
#define PIN_SDIN 4 // NKLCD-6 --> D4
#define PIN_DC 5 // NKLCD-5 --> D5
#define PIN_RESET 6 // NKLCD-4 --> D6
#define PIN_SCE 7 // NKLCD-3 --> D7
// NKLCD-8 -->Backlight
// NKLCD-2 -->GND
// NKLCD-1 -->V3.3 !!!BE CAREFUL
#include "NokiaLCD.h" // This must be here!! do not move to top
#include "DS18S20.h"
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 34
Nokia.h ////////////// S E T U P /////////////////
void setup(void)
{
LcdInitialise();
LcdClear();
//For DS1820
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)
gotoXY(0,0); // ln=0
LcdString("CRMA SensNet");
// gotoXY(0,1); // ln=1
// LcdString("by pyavinci");
ds18s20_setup();
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 35
Nokia.h String tempStr;
char *tempC;
/////////////// L O O P ///////////////////////
void loop(void)
{
byte sensor;
// For multiple DS18S20 sensors
for (sensor=0;sensor<MAX_DS1820_SENSORS;sensor++)
{
tempStr = get_ds18s20_temp(sensor);
tempC = &tempStr[0];
// Now display it on the LCD Nokia5110
gotoXY(0,2+sensor);
LcdString(tempC);
}
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 36
การสงขอมลผาน Serial คอมพวเตอร COM1……COM?
Serial Port
USB-to-Serial Adapter
Hyperterm, PuTTY
Arduino serial via USB
Arduino Commands
Serial.begin(9600);
Serial.println(sensorValue, DEC);
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 37
การสอสารขอมล MCU
Serial
SPI
I2C
OneWire
UART
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 38
Universal asynchronous receiver/transmitter
Serial Peripheral Interface
Sensor Network Comm.
GPRS Mobile Network
Long Range Wi-Fi
X-Bee, Bluetooth
Serial Communication
1-Wire Network
I2C
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 39
About Xbee
brand name from Digi International
based on the 802.15.4-2003
over-the-air baud rates of 250kbps
point-to-point and point-to-multipoint
1mW Xbee
100mW XBee-PRO
Freq: 868, 900 MHz, 2.4GHz
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 40
Xbee Wireless Comm.
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 41
ทดสอบการเชอมตอกบ Xbee
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 42
X-CTU
ทดสอบอานขอมลจาก sensor
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 43
โปรแกรมทดสอบ Xbee
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
delay(500);
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 44
Ongoing Prototypes
Sensor – 1:
LAN, 2 x Temp, Humi,
Light, Range
Sensor – 2:
Temp/Humi x 2,
Xbee
Sensor – 3:
Anemometer, Serial
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 45
Sensor-1
Arduino Mega128
SHT1x: Temperature/Humidity
Light Sensor (analog)
Ultrasonic Ranging (2 analog)
DS18s20: Digital Temperature (OneWire)
LCD 1604
Weather-proof Case (not in this prototype)
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 46
Sensor-2
Duemilanove 2009 (328)
2 DHT11 (digital
humidity/temperature)
Xbee – wireless
LCD 1602
Custom indoor box
Custom Xbee/USB switch
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 47
Sensor-3
Duemilanove
Recycled rotary encoder
from old mouse
2 analog pins input
LCD Nokia
Custom box
Proprietary Wind Cups
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 48
Look Inside Each Sensor
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 49
Sensor-1: light, H/T x2, Range
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 50
LCD 1604
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 51
Light Sensor
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 52
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 53
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 54
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 55
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 56
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 57
Sensor-1: Code->setup
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 59
// LCD==================================== #define LCD_WIDTH 20 #define LCD_HEIGHT 4 #define LD4 11 #define LD5 10 #define LD6 9 #define LD7 8 #define LEN 12 // LCD Enable #define LRS 13 // LCD RS /*=================+======+ LCD 16x2 Mega 1 (Vss/Ground) GND 2 VCC +5V 3 Vo(contrast) VR 4 RS 13 5 R/W GND 6 Enable 12 Pin 11-14 (D4-D7) 11-8
*/
Sensor-1: Code->setup
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 60
static uint8_t mymac[6] = {
0x54,0x55,0x58,0x10,0x00,0x24};
static uint8_t myip[4] = {
192,168,1,15};
static char baseurl[]="http://192.168.1.15/";
// listen port for tcp/www (max range 1-254)
static uint16_t mywwwport =80;
static uint8_t buf[BUFFER_SIZE+1]; static char strbuf[STR_BUFFER_SIZE+1];
Sensor-1: Code->setup
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 61
////// O B J E C T S /////// LiquidCrystal lcd(LRS, LEN, LD4, LD5, LD6, LD7); EtherShield es=EtherShield(); OneWire ds(TEMP_PIN); // pin that DS18S20 attached to SHT1x sht1x(dataPin, clockPin); // Temp-Humid ///// GLOBAL VARIABLES int reliaCount=0; long prevMil=0; int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract; char tbuf[20]; byte addr[MAX_DS1820_SENSORS][8];
Sensor-1: Code->Ranging
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 62
////// FOR HC-SR04 Ultrasonic Ranging // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(USPING, OUTPUT); digitalWrite(USPING, LOW); delayMicroseconds(2); digitalWrite(USPING, HIGH); delayMicroseconds(10); digitalWrite(USPING, LOW); // The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(USPONG, INPUT); duration = pulseIn(USPONG, HIGH); // convert the time into a distance //inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration);
Sensor-1: Code->Ranging
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 63
cm = microsecondsToCentimeters(duration);
lcd.setCursor(0,2);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print("Distance(cm): ");
lcd.print(cm);
Sensor-1: Code->DS18S20
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 64
// LOOP FOR MULTIPLE DS18S20(s)
for (sensor=0;sensor<MAX_DS1820_SENSORS;sensor++)
{ if ( OneWire::crc8( addr[sensor], 7) != addr[sensor][7])
{ Serial.print("CRC is not valid");
return;
}
if ( addr[sensor][0] != 0x10)
{ Serial.println("Device is not a DS18S20 family device.");
return; }
Sensor-1: Code->DS18S20
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 65
ds.reset(); ds.select(addr[sensor]); ds.write(0x44,1); // start conversion, with parasite power on at the end delay(50); // maybe 750ms is enough, maybe not // Note(by PC) Originally set to 750 // But I found here 50 or less is OK // Due to delay from other processing // we might do a ds.depower() here, but the reset will take care of it. present = ds.reset(); ds.select(addr[sensor]); ds.write(0xBE); // Read Scratchpad for ( i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); } LowByte = data[0]; HighByte = data[1]; TReading = (HighByte << 8) + LowByte;
Sensor-1: Code->DS18S20
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 66
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{ TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (TReading*100/2);
Whole = Tc_100 / 100; // separate off the whole and
fractional portions
Fract = Tc_100 % 100;
sprintf(tbuf, "%d.%d",Whole, Fract < 10 ? 0 : Fract); } // EndFor loop for DS18S20
Sensor-1: Code->Light
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 67
lcd.print("T2 L ");
long ls=analogRead(0);
lcd.setCursor(3,1);
lcd.print(tbuf); // Temperature from DS18S20
lcd.setCursor(11,1); lcd.print(ls); // Light Sensor data
Sensor-1: Code->EN28J60
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 68
///////// TCP/IP PART plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); // plen will ne unequal to zero if there is a valid packet (without crc error) if(plen!=0){ // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address. if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){ es.ES_make_arp_answer_from_request(buf); return; }
……… CUT ……………
Sensor-1: Code->EN28J60
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 69
……… CUT ……………
SENDTCP:
es.ES_make_tcp_ack_from_any(buf); // send ack for
http get
es.ES_make_tcp_ack_with_data(buf,plen); // send
data
}
}
}
Sensor-2: Xbee, DHT11
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 70
DHT11
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 71
Box, Xbee
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 72
Switch for Upload
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 73
Sensor-2: Codesetup
#include <LiquidCrystal.h> #define LCD_Print(x,y,t) lcd.setCursor(x,y);lcd.print(t) // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); ……….. void printSerial(void); void printSerial2(void); #include <dht11.h> dht11 DHT11,DHT11B; #define DHT11PIN 6 #define DHT11BPIN 7
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 74
Sensor-2: Codesetup
void setup() { Serial.begin(9600); Serial.println("DHT11 TEST PROGRAM "); Serial.print("LIBRARY VERSION: "); Serial.println(DHT11LIB_VERSION); Serial.println(); pinMode(DHT11BPIN,INPUT); pinMode(DHT11PIN,INPUT); lcd.begin(16, 2); LCD_Print(0,1,"CRMA SenseNet"); }
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 75
Sensor-2: Codeloop
void loop() { Serial.println("\n"); int chk = DHT11.read(DHT11PIN); Serial.print("____Read sensor: 0 ->"); delay(1000); switch (chk) { case 0: { Serial.println("OK"); printSerial(); break; } case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; }
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 76
Sensor-2: Codeloop
chk = DHT11B.read(DHT11BPIN); // read another DHT11 Serial.println("\n"); Serial.print("____Read sensor: 1 ->"); delay(1000); switch (chk) { case 0: { Serial.println("OK"); printSerial2(); break; } case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; }
}
**** NOTE ****
• See sensor data sent via Xbee
• We didn’t do anything for Xbee (but don’t forget the jumper)
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 77
Sensor-3: Anemometer
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 78
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 79
Wind Cups
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 80
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 81
Nokia LCD Test
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 82
LCD, Arduino in box
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 83
Connected to Arduino
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 84
Calibration
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 85
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 86
Sensor-3: Code Setup
#define PIN_SCLK 3 // NKLCD-7 --> D3
#define PIN_SDIN 4 // NKLCD-6 --> D4
#define PIN_DC 5 // NKLCD-5 --> D5
#define PIN_RESET 6 // NKLCD-4 --> D6
#define PIN_SCE 7 // NKLCD-3 --> D7
// NKLCD-8 -->Backlight
// NKLCD-2 -->GND
// NKLCD-1 -->V3.3 !!!BE CAREFUL
#include "NokiaLCD.h" // This must be here!! do not move to top
// 6 lines (0 to 5)
// 83 H_dots (0 to 82)
//#include "DS18S20.h"
// Change pin number in this file accordingly
#define THRESHOLD 120
////////////// S E T U P /////////////////
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 87
Sensor-3: Code Setup
void setup(void)
{
LcdInitialise();
LcdClear();
//For DS1820
// digitalWrite(TEMP_PIN, LOW);
// pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)
gotoXY(0,0); // ln=0
LcdString("CRMA SensNet");
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 88
Sensor-3: Code Loop
String tempStr;
char tempC[16];
char *gstr=&tempC[0];
unsigned int a,b,ax=0,bx=0,adiv=0,bdiv=0,aprev,bprev;
unsigned long at=0,bt=0,ac=0,bc=0,tprev=0,t=0;
unsigned int astate=1, bstate=1;
float rpm;
/////////////// L O O P ///////////////////////
void loop(void)
{
int t;
a=analogRead(0);
b=analogRead(1);
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 89
Sensor-3: Code Loop
String tempStr;
char tempC[16];
char *gstr=&tempC[0];
unsigned int a,b,ax=0,bx=0,adiv=0,bdiv=0,aprev,bprev;
unsigned long at=0,bt=0,ac=0,bc=0,tprev=0,t=0;
unsigned int astate=1, bstate=1;
float rpm;
/////////////// L O O P ///////////////////////
void loop(void)
{
int t;
a=analogRead(0);
b=analogRead(1);
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 90
Sensor-3: Code Loop
gotoXY(0,2);
if(a>THRESHOLD) {
if (astate==0) {
LcdString(" 1 ");
ac++;
t=millis()-tprev;
rpm=(60000/(40*t));
sprintf(gstr,"RPM: %d.%d ",(int)rpm,(rpm-(int)rpm)*100);
gotoXY(0,4);
LcdString(gstr);
tprev=millis();
}
astate=1;
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 91
Sensor-3: Code Loop
gotoXY(0,2);
if(a>THRESHOLD) {
if (astate==0) {
LcdString(" 1 ");
ac++;
t=millis()-tprev;
rpm=(60000/(40*t));
sprintf(gstr,"RPM: %d.%d ",(int)rpm,(rpm-(int)rpm)*100);
gotoXY(0,4);
LcdString(gstr);
tprev=millis();
}
astate=1;
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 92
Sensor-3: Code Loop
else {
LcdString(" 0 ");
astate=0;
}
gotoXY(15,2);
sprintf(gstr," %d ",ac);
LcdString(gstr);
gotoXY(0,3);
if(b>THRESHOLD) {
if (bstate==0){
LcdString(" 1 ");
bc++;
}
bstate=1;
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 93
Sensor-3: Code Loop
else {
LcdString(" 0 ");
astate=0;
}
gotoXY(15,2);
sprintf(gstr," %d ",ac);
LcdString(gstr);
gotoXY(0,3);
if(b>THRESHOLD) {
if (bstate==0){
LcdString(" 1 ");
bc++;
}
bstate=1;
}
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 94
Sensor-3: Code Loop
else {
LcdString(" 0 ");
bstate=0;
}
gotoXY(15,3);
sprintf(gstr," %d ",bc);
LcdString(gstr);
}
/* for (sensor=0;sensor<MAX_DS1820_SENSORS;sensor++) {
tempStr = get_ds18s20_temp(sensor);
tempC = &tempStr[0];
// Now display it on the LCD Nokia5110
gotoXY(0,2+sensor);
LcdString(tempC);
} */
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 95
Sensor Nodes
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 96
Nodes Level Functions
Portal
Server
User level: display information
in graph, numbers; OS=Linux, Windows
Linux Sub-
nodes
Intermediate level: process data
from MCUs, reformat, backup,
recalculate; OS=Linux, Windows
MCUs Lowest level: collect
digital/analog data from various
sensors, perform basic
calculation, data logger; OS: MCU level
Microcontrollers
Portal Server
Alternative Displaying Methods:
Processing
MRTG
Google Chart – TimeSeriesGraph()
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 97
Processing IDE
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 98
Processing
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 99
www.processing.org
open source programming
language and environment for
people who want to create
images, animations, and
interactions.
Over 100 libraries
run online or as double-
clickable (apps)
Processing
ขอมลสงผาน serial ไปยง Processing
จากนนสงไปตอไปท pachube
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 100
www.processing.org
pachube
access anywhere environment data visualization service
a clearinghouse for sensor data
Ultimate data storage platform independent of sensor itself
A platform to access global sensor user generated content
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 101
www.pachube.com
MRTG
รนบนเวบเซอรฟเวอร
แสดงขอมลไดจากหลายแหลง
Time series, historical data สรปขอมลยอนหลง
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 102
Google Chart
Display live data
Rich tools
Free
Customizable
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 103
<html> <head> <script type='text/javascript' src='https://www.google.com/jsapi'></script> <script type='text/javascript'> google.load('visualization', '1', {'packages':['annotatedtimeline']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('date', 'Date'); data.addColumn('number', 'Sold Pencils'); data.addColumn('string', 'title1'); data.addColumn('string', 'text1'); data.addColumn('number', 'Sold Pens'); data.addColumn('string', 'title2'); data.addColumn('string', 'text2'); data.addRows([ [new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined], [new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined], [new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined], [new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'], [new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined], [new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined] ]); var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div')); chart.draw(data, {displayAnnotations: true}); } </script> </head> <body> // Note how you must specify the size of the container element
explicitly!
<div id='chart_div' style='width: 700px; height: 240px;'></div> </body> </html>
Google Chart Example HTML
Power Consideration
ขอพจารณาเกยวกบแหลงจายไฟ ใหกบ Sensors
Grid Power
Solar, Wind, Hybrid
Stand-alone Battery Pack
Others (waterfall, Hydrogen, etc.)
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 105
WUNCA24 2011: CRMA Sensor Network (Work-in-Progress) 106
ค ำถำม?? [email protected]
http://code.google.com/p/crma-
sensor-network-project-2011/