SlideShare uma empresa Scribd logo
1 de 106
Baixar para ler offline
การพัฒนาระบบเซนเซอร์เน็ตเวิร์คเบืองต้น
                                       ้
                          (Work In Progress)
                          พ.อ.ปรัชญา เฉลิมวัฒน์, Ph.D.
                           พ.อ.รศ.สุรตน์ เลิศล้ า, Ph.D.
                                      ั
                                 พ.อ.ศุภชัย ศรีหอม
                          โรงเรียนนายร้อยพระจุลจอมเกล้า
                                 อ.เมือง จ.นครนายก

    WUNCA24 2011: CRMA Sensor Network (Work-in-
1   Progress)
หัวข้อบรรยาย
     กล่าวนา – ระบบ Wireless Sensor Network (SL)
     การออกแบบ CRMA Sensor Network
     องค์ประกอบของ sensor network
     Sensor Nodes
     MCU ที่ใช้ในระบบ sensor network (SS)
     ARM-based Linux Subnode
     Portal/Display Servers
     ข้อพิจารณาเกียวกับ Power Consumption
                   ่


2   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Preferred Audience Background
     Internetworking, TCP/IP
     C Programming
     Windows 7 Experiences, Terminal, PuTTY
     Digital Fundamentals
     Electronics
     Wiring, Soldering
     Tools: cut, drill, glue
     $$$


3   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Prof. Surat
    Wireless Sensor Network
     ทาไมต้องมี Sensors? 
      Environment Data
       Temperature/Humidity
       Wind Speed/Direction
       Light, Object movement
       Motion/Tilt
       Sound, Image, Video
     ประโยชน์ต่อการศึกษา patterns, time
      series data
     ทาไมต้อง Wireless?

4   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
CRMA Sensor Network
                          Conceptual Design




5   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
CRMA Sensor Network
                                     Conceptual Design
            Sensor Nodes
                                                Intermediate
                                                Nodes
                                    Serial,
                                    LAN,
                                    Xbee,
                                    Bluetooth
        Serial, I2C, 1-Wire, SPI




                                   Serial,
                                   LAN,
                                   Xbee,
                                   Bluetooth




6   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor Nodes
    Nodes Level               Functions

    Portal                    User level: display information
                              in graph, numbers; OS=Linux,
    Server                    Windows

    Linux Sub-                Intermediate level: process data
                              from MCUs, reformat, backup,
    nodes                     recalculate; OS=Linux,
                              Windows

    MCUs                      Lowest level: collect
    Microcontrollers          digital/analog data from various
                              sensors, perform basic
                              calculation, data logger; OS:
                              MCU level

7   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
การสือสารกับ Sensors
         ่
     RS232 – serial communication
     LAN – TCP/IP stack
     Xbee – serial over wireless
     Bluetooth
     Edge/GPRS modem
     WiFi
     Off-Line via SD data logger




8   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
MicroClient JrMx
                                                           • 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




      www.norhtec.com
    http://www.norhtec.com/products/mcjrmx/index.html

9   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง Linux บน JrMX                                   Skipped


      เช่นเดียวกับการติดตั้ง Linux ทัวไป ในกรณีที่มี Hard Disk
                                      ่
      ในกรณีที่ใช้ SD card สามารถใช้เครื่องมือ Universal USB
       Installer (ที่ www.pendrivelinux.com) โดยติดตั้งแบบ
       persistent
      การทางานเช่นเดียวกับไมโครคอมพิวเตอร์ทวไป
                                            ั่
      ข้อดี  เสียงเงียบ, กินไฟน้อย, ทนอุณภูมิได้สูง, ราคาถูก, มีพอร์ต
        ต่างๆ ให้ใช้งานสมบูรณ์




10   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ARM-based Linux Subnode
          แนะนา Mini2440/6410 บอร์ด Embedded
          การติดตั้ง Linux ลงในบอร์ด Mini6410
          การสือสารระหว่าง MCU กับ Linux
                ่




11   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
FriendlyArm
     Mini2440/6410




12   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
FriendlyArm
     Mini2440/6410
       2440                                    6410
       400 MHz Samsung                         533 MHz Samsung
       S3C2440 ARM9                            S3C6410 ARM11

       64 MB RAM                               128 MB / 256 MB

       128 MB / 256 MB / 1GB                   256 MB / 1GB NAND
       NAND
       SD-Card                                 SD-Card/SDIO socket
       RS232                                   RS232
       THB 5,580.-                             THB 6,000.-



13   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
FriendlyArm
     Mini2440/6410




14   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
FriendlyArm
     Mini2440/6410
                                                   USB
       RS232
                                                                DVD
                                Video J-Tag
                                                            Display
              AC
                                                               USB
                                                               Serial


15   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
FriendlyArm
     Mini2440/6410
                                                            • Linux kernel 2.6
                                                            • QT (Xwindows) interface
                                                            • Touch screen
                                                            • Serial Port
                                                            • Video (on 6410)
                                                            • Audio
                                                            • USB
                                                            • SD card




16   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง 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


17   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง 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
18   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง 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)

19   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง 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

20   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ติดตั้ง 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


21   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ไฟล์ 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

22   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ไฟล์ FriendlyARM.ini
     ################### WindowsCE6
      #################
      WindowsCE6-Bootloader= WindowsCE6NBOOT_A70-RAM128.nb0
      WindowsCE6-BootLogo = WindowsCE6bootlogo.bmp
      WindowsCE6-InstallImage = WindowsCE6NK_A70-s.bin
      WindowsCE6-RunImage = WindowsCE6NK_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

23   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ไฟล์ 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

24   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Microcontrollers
     Arduino MCUs
          Arduino MCU (Duemilanove, Mega, Nano)
          การเชื่อมต่อ sensor เข้ากับ MCU
            DS18S20 Temperature sensor
            SHT1x Temperature & Humidity sensor
            Analog light sensor
            Distance sensor
            Wind Speed




25   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Arduino MCUs
                    Duemilano          Uno         Mega         Mega        Nano
                     ve 2009                    atmega1280   atmega2560    168/328
           uCon 168-328           328         1280           2560          168/328
         Atmega
       Digital I/O 14             14          54             54 (14 PWM)   14

          Analog 6                8           26             16            8
           Inputs
     Flash/Bootlo 16-32K/2K       32K/2K      128K/4K        256K/8K       32K/2K
              ad
           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

26   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Arduino MCUs
                Mega                          Duemilanove   Nano




27   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Duemilanove




28   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Arduino MCUs
          การโปรแกรม MCU เบื้ องต้นด้วย Arduino IDE (SS)
          การแสดงผลผ่านจอ LCD
             LCD 1602, 1604
             Nokia LCD

          การส่งข้อมูลผ่าน Serial
          การสือสารข้อมูลของ MCU
                ่
          การติดตั้ง EtherShield




29   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD 1602/1604
      LiquidCrystal.h
      จอ LCD (210 THB)
      HD44780-based
      Backlight




30   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD 1602/1604




31   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD Hello World!




32   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD: Nokia 5110
      จอเล็ก, ราคาถูก, กินไฟน้อย
      6 บรรทัด 82 จุด
      3.3 V
      Backlight




33   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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"


34   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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();
     }


35   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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);
         }
     }


36   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
การส่งข้อมูลผ่าน Serial
      คอมพิวเตอร์ COM1……COM?
          Serial Port
          USB-to-Serial Adapter
          Hyperterm, PuTTY
      Arduino serial via USB
      Arduino Commands
          Serial.begin(9600);
          Serial.println(sensorValue, DEC);



37   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
การสือสารข้อมูล MCU
                                    ่
      Serial
       SPI
      Serial Peripheral Interface
      I2C
      OneWire
      UART
         Universal asynchronous receiver/transmitter




38   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor Network Comm.
          GPRS Mobile Network
          Long Range Wi-Fi
          X-Bee, Bluetooth
          Serial Communication
          1-Wire Network
          I2C




39   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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

40   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Xbee Wireless Comm.




41   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
X-CTU
     ทดสอบการเชื่อมต่อกับ Xbee




42   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
ทดสอบอ่านข้อมูลจาก sensor




43   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
โปรแกรมทดสอบ Xbee
     void setup() {
       Serial.begin(9600);
     }

     void loop() {
       int sensorValue = analogRead(A0);
       Serial.println(sensorValue, DEC);
       delay(500);
     }
44   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Ongoing Prototypes
      Sensor – 1:
        LAN, 2 x Temp, Humi,
            Light, Range
      Sensor – 2:
        Temp/Humi x 2,
            Xbee
      Sensor – 3:
        Anemometer, Serial



45   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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)




46   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2
      Duemilanove 2009 (328)
      2 DHT11 (digital
       humidity/temperature)
      Xbee – wireless
      LCD 1602
      Custom indoor box
      Custom Xbee/USB switch




47   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-3
      Duemilanove
      Recycled rotary encoder
       from old mouse
      2 analog pins input
      LCD Nokia
      Custom box
      Proprietary Wind Cups




48   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Look Inside
       Each Sensor


49   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: light, H/T x2, Range




50    WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD 1604




51   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Light Sensor




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   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->setup
     // 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
        */


59   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->setup
        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];


60   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->setup
      ////// 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];

61   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->Ranging
        ////// 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);


62   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->Ranging
        cm = microsecondsToCentimeters(duration);
        lcd.setCursor(0,2);
        lcd.print(" ");
        lcd.setCursor(0,2);
        lcd.print("Distance(cm): ");
        lcd.print(cm);




63   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->DS18S20
     // 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;
        }


64   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->DS18S20
     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;


65   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->DS18S20
     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

66   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->Light
         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




67   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->EN28J60
     ///////// 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 ……………

68   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-1: Code->EN28J60
     ……… 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
           }
         }
       }


69   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2: Xbee, DHT11




70   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
DHT11




71   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Box, Xbee




72   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Switch for Upload




73   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2: Codesetup
      #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



74   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2: Codesetup
     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");
       }


75   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2: Codeloop
     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;
       }



76   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-2: Codeloop
         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)


77   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor-3: Anemometer




78   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
79   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Wind Cups




80   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
81   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Nokia LCD Test




82   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
LCD, Arduino in box




83   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Connected to Arduino




84   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Calibration




85   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
86   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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 /////////////////


87   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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");
     }

88   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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);

89   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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);

90   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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;
      }

91   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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;
      }

92   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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;
      }




93   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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;
      }




94   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
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);
        } */


95   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Sensor Nodes
     Nodes Level               Functions

     Portal                    User level: display information
                               in graph, numbers; OS=Linux,
     Server                    Windows

     Linux Sub-                Intermediate level: process data
                               from MCUs, reformat, backup,
     nodes                     recalculate; OS=Linux,
                               Windows

     MCUs                      Lowest level: collect
     Microcontrollers          digital/analog data from various
                               sensors, perform basic
                               calculation, data logger; OS:
                               MCU level

96   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Portal Server
     Alternative Displaying Methods:
        Processing
        MRTG
        Google Chart –
             TimeSeriesGraph()




97   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Processing IDE




98   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Processing
     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)




99   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Processing
      www.processing.org




       ข้อมูลส่งผ่าน serial ไปยัง Processing
       จากนั้นส่งไปต่อไปที่ pachube


100   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
pachube
      www.pachube.com
                                            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
101   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
MRTG
                                        รันบนเว็บเซอร์ฟเวอร์
                                        แสดงข้อมูลได้จากหลายแหล่ง
                                        Time series, historical data
                                           สรุปข้ อมูลย้ อนหลัง




102   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Google Chart



       Display live data
       Rich tools
       Free
       Customizable


103   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
Google         <html>
                 <head>


Chart               <script type='text/javascript'
               src='https://www.google.com/jsapi'></script>
                <script type='text/javascript'>
                  google.load('visualization', '1', {'packages':['annotatedtimeline']});
                      google.setOnLoadCallback(drawChart);
Example HTML          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>
Power Consideration
       ข้อพิจารณาเกียวกับแหล่งจ่ ายไฟ ให้กบ Sensors
                     ่                     ั
       Grid Power
       Solar, Wind, Hybrid
       Stand-alone Battery Pack
       Others (waterfall, Hydrogen, etc.)




105   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
คำถำม??
                                    surat@crma.ac.th
                                    prachya@crma.ac.th
                                    pyavinci@gmail.com
                                    http://code.google.com/p/crma-
                                    sensor-network-project-2011/



106   WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)

Mais conteúdo relacionado

Destaque

ตกลงราคา Manual e-GP
ตกลงราคา Manual e-GPตกลงราคา Manual e-GP
ตกลงราคา Manual e-GPMevenwen Singollo
 
1.ความรู้เบื้องต้นเกี่ยวกับinternet1
1.ความรู้เบื้องต้นเกี่ยวกับinternet11.ความรู้เบื้องต้นเกี่ยวกับinternet1
1.ความรู้เบื้องต้นเกี่ยวกับinternet1Mevenwen Singollo
 
Boligrafo solo
Boligrafo soloBoligrafo solo
Boligrafo soloRicarHuevo
 
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4Mevenwen Singollo
 

Destaque (10)

ตกลงราคา Manual e-GP
ตกลงราคา Manual e-GPตกลงราคา Manual e-GP
ตกลงราคา Manual e-GP
 
1.ความรู้เบื้องต้นเกี่ยวกับinternet1
1.ความรู้เบื้องต้นเกี่ยวกับinternet11.ความรู้เบื้องต้นเกี่ยวกับinternet1
1.ความรู้เบื้องต้นเกี่ยวกับinternet1
 
C chap1
C chap1C chap1
C chap1
 
Boligrafo solo
Boligrafo soloBoligrafo solo
Boligrafo solo
 
Dreamweaver
DreamweaverDreamweaver
Dreamweaver
 
C chap2
C chap2C chap2
C chap2
 
Information
InformationInformation
Information
 
Computer network & internet
Computer network & internetComputer network & internet
Computer network & internet
 
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4
แนวข้อสอบบรรจุครูผู้ช่วย วิชาเอกคอมพิวเตอร์ ชุดที่ 4
 
Migraine
MigraineMigraine
Migraine
 

Semelhante a 009 crma sensor-network-wip

เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์prakaipet
 
51-307 Unit 1
51-307 Unit 151-307 Unit 1
51-307 Unit 1Naret Su
 
Tu153 บทที่ 8 2/2560
Tu153 บทที่ 8 2/2560Tu153 บทที่ 8 2/2560
Tu153 บทที่ 8 2/2560Kasidit Chanchio
 
1. ________________ Surveillance Solution.pdf
1. ________________ Surveillance Solution.pdf1. ________________ Surveillance Solution.pdf
1. ________________ Surveillance Solution.pdfPawachMetharattanara
 
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้น
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้นสไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้น
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้นit4learner
 
เมนบอร์ดและPortต่างๆ
เมนบอร์ดและPortต่างๆเมนบอร์ดและPortต่างๆ
เมนบอร์ดและPortต่างๆJen D
 
การสื่อสาร อ.พรทิพย์
การสื่อสาร อ.พรทิพย์การสื่อสาร อ.พรทิพย์
การสื่อสาร อ.พรทิพย์Namfon Phenpit
 
ระบบเครือข่ายtot
ระบบเครือข่ายtotระบบเครือข่ายtot
ระบบเครือข่ายtotnoii pinyo
 

Semelhante a 009 crma sensor-network-wip (20)

01 ipst microbox
01 ipst microbox01 ipst microbox
01 ipst microbox
 
เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์
 
51-307 Unit 1
51-307 Unit 151-307 Unit 1
51-307 Unit 1
 
Solution Case Study Geo.ppt
Solution Case Study Geo.pptSolution Case Study Geo.ppt
Solution Case Study Geo.ppt
 
Computer System for CIO
Computer System for CIOComputer System for CIO
Computer System for CIO
 
Solution Case Study.ppt
Solution Case Study.pptSolution Case Study.ppt
Solution Case Study.ppt
 
Tu153 บทที่ 8 2/2560
Tu153 บทที่ 8 2/2560Tu153 บทที่ 8 2/2560
Tu153 บทที่ 8 2/2560
 
Product Detail
Product DetailProduct Detail
Product Detail
 
1. ________________ Surveillance Solution.pdf
1. ________________ Surveillance Solution.pdf1. ________________ Surveillance Solution.pdf
1. ________________ Surveillance Solution.pdf
 
TOR ICT66_20230313.pdf
TOR ICT66_20230313.pdfTOR ICT66_20230313.pdf
TOR ICT66_20230313.pdf
 
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้น
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้นสไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้น
สไลด์ บทที่ 1 คอมพิวเตอร์เบื้องต้น
 
Intro1
Intro1Intro1
Intro1
 
Present trainee
Present traineePresent trainee
Present trainee
 
เมนบอร์ดและPortต่างๆ
เมนบอร์ดและPortต่างๆเมนบอร์ดและPortต่างๆ
เมนบอร์ดและPortต่างๆ
 
Slide 9 april_2011_pdf
Slide 9 april_2011_pdfSlide 9 april_2011_pdf
Slide 9 april_2011_pdf
 
Computer network
Computer networkComputer network
Computer network
 
การสื่อสาร อ.พรทิพย์
การสื่อสาร อ.พรทิพย์การสื่อสาร อ.พรทิพย์
การสื่อสาร อ.พรทิพย์
 
ระบบเครือข่ายtot
ระบบเครือข่ายtotระบบเครือข่ายtot
ระบบเครือข่ายtot
 
เครือข่ายคอมพิวเตอร์
เครือข่ายคอมพิวเตอร์เครือข่ายคอมพิวเตอร์
เครือข่ายคอมพิวเตอร์
 
Ch6 multimedia
Ch6 multimediaCh6 multimedia
Ch6 multimedia
 

009 crma sensor-network-wip

  • 1. การพัฒนาระบบเซนเซอร์เน็ตเวิร์คเบืองต้น ้ (Work In Progress) พ.อ.ปรัชญา เฉลิมวัฒน์, Ph.D. พ.อ.รศ.สุรตน์ เลิศล้ า, Ph.D. ั พ.อ.ศุภชัย ศรีหอม โรงเรียนนายร้อยพระจุลจอมเกล้า อ.เมือง จ.นครนายก WUNCA24 2011: CRMA Sensor Network (Work-in- 1 Progress)
  • 2. หัวข้อบรรยาย  กล่าวนา – ระบบ Wireless Sensor Network (SL)  การออกแบบ CRMA Sensor Network  องค์ประกอบของ sensor network  Sensor Nodes  MCU ที่ใช้ในระบบ sensor network (SS)  ARM-based Linux Subnode  Portal/Display Servers  ข้อพิจารณาเกียวกับ Power Consumption ่ 2 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 3. Preferred Audience Background  Internetworking, TCP/IP  C Programming  Windows 7 Experiences, Terminal, PuTTY  Digital Fundamentals  Electronics  Wiring, Soldering  Tools: cut, drill, glue  $$$ 3 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 4. Prof. Surat Wireless Sensor Network  ทาไมต้องมี Sensors?  Environment Data  Temperature/Humidity  Wind Speed/Direction  Light, Object movement  Motion/Tilt  Sound, Image, Video  ประโยชน์ต่อการศึกษา patterns, time series data  ทาไมต้อง Wireless? 4 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 5. CRMA Sensor Network Conceptual Design 5 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 6. CRMA Sensor Network Conceptual Design Sensor Nodes Intermediate Nodes Serial, LAN, Xbee, Bluetooth Serial, I2C, 1-Wire, SPI Serial, LAN, Xbee, Bluetooth 6 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 7. Sensor Nodes Nodes Level Functions Portal User level: display information in graph, numbers; OS=Linux, Server Windows Linux Sub- Intermediate level: process data from MCUs, reformat, backup, nodes recalculate; OS=Linux, Windows MCUs Lowest level: collect Microcontrollers digital/analog data from various sensors, perform basic calculation, data logger; OS: MCU level 7 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 8. การสือสารกับ Sensors ่  RS232 – serial communication  LAN – TCP/IP stack  Xbee – serial over wireless  Bluetooth  Edge/GPRS modem  WiFi  Off-Line via SD data logger 8 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 9. MicroClient JrMx • 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 www.norhtec.com http://www.norhtec.com/products/mcjrmx/index.html 9 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 10. ติดตั้ง Linux บน JrMX Skipped  เช่นเดียวกับการติดตั้ง Linux ทัวไป ในกรณีที่มี Hard Disk ่  ในกรณีที่ใช้ SD card สามารถใช้เครื่องมือ Universal USB Installer (ที่ www.pendrivelinux.com) โดยติดตั้งแบบ persistent  การทางานเช่นเดียวกับไมโครคอมพิวเตอร์ทวไป ั่  ข้อดี  เสียงเงียบ, กินไฟน้อย, ทนอุณภูมิได้สูง, ราคาถูก, มีพอร์ต ต่างๆ ให้ใช้งานสมบูรณ์ 10 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 11. ARM-based Linux Subnode  แนะนา Mini2440/6410 บอร์ด Embedded  การติดตั้ง Linux ลงในบอร์ด Mini6410  การสือสารระหว่าง MCU กับ Linux ่ 11 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 12. FriendlyArm Mini2440/6410 12 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 13. FriendlyArm Mini2440/6410 2440 6410 400 MHz Samsung 533 MHz Samsung S3C2440 ARM9 S3C6410 ARM11 64 MB RAM 128 MB / 256 MB 128 MB / 256 MB / 1GB 256 MB / 1GB NAND NAND SD-Card SD-Card/SDIO socket RS232 RS232 THB 5,580.- THB 6,000.- 13 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 14. FriendlyArm Mini2440/6410 14 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 15. FriendlyArm Mini2440/6410 USB RS232 DVD Video J-Tag Display AC USB Serial 15 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 16. FriendlyArm Mini2440/6410 • Linux kernel 2.6 • QT (Xwindows) interface • Touch screen • Serial Port • Video (on 6410) • Audio • USB • SD card 16 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 17. ติดตั้ง 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 17 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 18. ติดตั้ง 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 18 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 19. ติดตั้ง 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) 19 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 20. ติดตั้ง 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 20 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 21. ติดตั้ง 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 21 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 22. ไฟล์ 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 22 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 23. ไฟล์ FriendlyARM.ini ################### WindowsCE6 ################# WindowsCE6-Bootloader= WindowsCE6NBOOT_A70-RAM128.nb0 WindowsCE6-BootLogo = WindowsCE6bootlogo.bmp WindowsCE6-InstallImage = WindowsCE6NK_A70-s.bin WindowsCE6-RunImage = WindowsCE6NK_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 23 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 24. ไฟล์ 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 24 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 25. Microcontrollers Arduino MCUs  Arduino MCU (Duemilanove, Mega, Nano)  การเชื่อมต่อ sensor เข้ากับ MCU  DS18S20 Temperature sensor  SHT1x Temperature & Humidity sensor  Analog light sensor  Distance sensor  Wind Speed 25 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 26. Arduino MCUs Duemilano Uno Mega Mega Nano ve 2009 atmega1280 atmega2560 168/328 uCon 168-328 328 1280 2560 168/328 Atmega Digital I/O 14 14 54 54 (14 PWM) 14 Analog 6 8 26 16 8 Inputs Flash/Bootlo 16-32K/2K 32K/2K 128K/4K 256K/8K 32K/2K ad 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 26 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 27. Arduino MCUs Mega Duemilanove Nano 27 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 28. Duemilanove 28 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 29. Arduino MCUs  การโปรแกรม MCU เบื้ องต้นด้วย Arduino IDE (SS)  การแสดงผลผ่านจอ LCD  LCD 1602, 1604  Nokia LCD  การส่งข้อมูลผ่าน Serial  การสือสารข้อมูลของ MCU ่  การติดตั้ง EtherShield 29 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 30. LCD 1602/1604  LiquidCrystal.h  จอ LCD (210 THB)  HD44780-based  Backlight 30 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 31. LCD 1602/1604 31 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 32. LCD Hello World! 32 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 33. LCD: Nokia 5110  จอเล็ก, ราคาถูก, กินไฟน้อย  6 บรรทัด 82 จุด  3.3 V  Backlight 33 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 34. 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" 34 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 35. 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(); } 35 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 36. 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); } } 36 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 37. การส่งข้อมูลผ่าน Serial  คอมพิวเตอร์ COM1……COM?  Serial Port  USB-to-Serial Adapter  Hyperterm, PuTTY  Arduino serial via USB  Arduino Commands  Serial.begin(9600);  Serial.println(sensorValue, DEC); 37 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 38. การสือสารข้อมูล MCU ่  Serial SPI  Serial Peripheral Interface  I2C  OneWire  UART Universal asynchronous receiver/transmitter 38 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 39. Sensor Network Comm.  GPRS Mobile Network  Long Range Wi-Fi  X-Bee, Bluetooth  Serial Communication  1-Wire Network  I2C 39 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 40. 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 40 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 41. Xbee Wireless Comm. 41 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 42. X-CTU ทดสอบการเชื่อมต่อกับ Xbee 42 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 43. ทดสอบอ่านข้อมูลจาก sensor 43 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 44. โปรแกรมทดสอบ Xbee void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue, DEC); delay(500); } 44 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 45. Ongoing Prototypes  Sensor – 1:  LAN, 2 x Temp, Humi, Light, Range  Sensor – 2:  Temp/Humi x 2, Xbee  Sensor – 3:  Anemometer, Serial 45 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 46. 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) 46 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 47. Sensor-2  Duemilanove 2009 (328)  2 DHT11 (digital humidity/temperature)  Xbee – wireless  LCD 1602  Custom indoor box  Custom Xbee/USB switch 47 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 48. Sensor-3  Duemilanove  Recycled rotary encoder from old mouse  2 analog pins input  LCD Nokia  Custom box  Proprietary Wind Cups 48 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 49. Look Inside Each Sensor 49 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 50. Sensor-1: light, H/T x2, Range 50 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 51. LCD 1604 51 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 52. Light Sensor 52 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 53. 53 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 54. 54 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 55. 55 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 56. 56 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 57. 57 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 58.
  • 59. Sensor-1: Code->setup // 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 */ 59 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 60. Sensor-1: Code->setup 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]; 60 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 61. Sensor-1: Code->setup ////// 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]; 61 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 62. Sensor-1: Code->Ranging ////// 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); 62 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 63. Sensor-1: Code->Ranging cm = microsecondsToCentimeters(duration); lcd.setCursor(0,2); lcd.print(" "); lcd.setCursor(0,2); lcd.print("Distance(cm): "); lcd.print(cm); 63 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 64. Sensor-1: Code->DS18S20 // 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; } 64 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 65. Sensor-1: Code->DS18S20 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; 65 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 66. Sensor-1: Code->DS18S20 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 66 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 67. Sensor-1: Code->Light 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 67 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 68. Sensor-1: Code->EN28J60 ///////// 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 …………… 68 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 69. Sensor-1: Code->EN28J60 ……… 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 } } } 69 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 70. Sensor-2: Xbee, DHT11 70 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 71. DHT11 71 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 72. Box, Xbee 72 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 73. Switch for Upload 73 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 74. Sensor-2: Codesetup  #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 74 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 75. Sensor-2: Codesetup 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"); } 75 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 76. Sensor-2: Codeloop 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; } 76 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 77. Sensor-2: Codeloop 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) 77 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 78. Sensor-3: Anemometer 78 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 79. 79 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 80. Wind Cups 80 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 81. 81 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 82. Nokia LCD Test 82 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 83. LCD, Arduino in box 83 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 84. Connected to Arduino 84 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 85. Calibration 85 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 86. 86 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 87. 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 ///////////////// 87 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 88. 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"); } 88 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); 89 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 90. 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); 90 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; } 91 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 92. 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; } 92 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; } 93 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 94. 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; } 94 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 95. 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); } */ 95 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 96. Sensor Nodes Nodes Level Functions Portal User level: display information in graph, numbers; OS=Linux, Server Windows Linux Sub- Intermediate level: process data from MCUs, reformat, backup, nodes recalculate; OS=Linux, Windows MCUs Lowest level: collect Microcontrollers digital/analog data from various sensors, perform basic calculation, data logger; OS: MCU level 96 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 97. Portal Server Alternative Displaying Methods:  Processing  MRTG  Google Chart –  TimeSeriesGraph() 97 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 98. Processing IDE 98 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 99. Processing 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) 99 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 100. Processing www.processing.org  ข้อมูลส่งผ่าน serial ไปยัง Processing  จากนั้นส่งไปต่อไปที่ pachube 100 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 101. pachube www.pachube.com  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 101 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 102. MRTG  รันบนเว็บเซอร์ฟเวอร์  แสดงข้อมูลได้จากหลายแหล่ง  Time series, historical data สรุปข้ อมูลย้ อนหลัง 102 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 103. Google Chart  Display live data  Rich tools  Free  Customizable 103 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 104. Google <html> <head> Chart <script type='text/javascript' src='https://www.google.com/jsapi'></script> <script type='text/javascript'> google.load('visualization', '1', {'packages':['annotatedtimeline']}); google.setOnLoadCallback(drawChart); Example HTML 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>
  • 105. Power Consideration  ข้อพิจารณาเกียวกับแหล่งจ่ ายไฟ ให้กบ Sensors ่ ั  Grid Power  Solar, Wind, Hybrid  Stand-alone Battery Pack  Others (waterfall, Hydrogen, etc.) 105 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)
  • 106. คำถำม?? surat@crma.ac.th prachya@crma.ac.th pyavinci@gmail.com http://code.google.com/p/crma- sensor-network-project-2011/ 106 WUNCA24 2011: CRMA Sensor Network (Work-in-Progress)