Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:examples:communication:zigbee [2012/04/10 13:54] – created illoen:examples:communication:zigbee [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-<note important>On preparation</note> 
  
 ====== ZigBee ====== ====== ZigBee ======
Line 7: Line 6:
 ===== Theory ===== ===== Theory =====
  
-[{{  ::examples:communication:xbee.jpg?220|XBee moodul.}}]+[{{  ::examples:communication:xbee.jpg?220|XBee module.}}]
  
-ZigBee is a specification for a suite of high level communication protocols using small, low-power digital radios based on an IEEE 802 standard for personal area networks. It'designed for devices which require simple wireless networking and don't need high data transfer rate. Does devices might be for example information displays, home- and industrial automatic systems. The selforganise network from ZigBee the power demand compared with different Bluetooth application is quit efficientmodules goes quickly form sleep to awake, the awake time is minimized. ZigBee works radio band at 2.4 GHz.  +ZigBee is a specification for high level communication protocols using small, low-power digital radios based on an IEEE 802.15.4-2003 standard for personal area networks. ZigBee is designed for devices which require simple wireless networking and don't need high data transfer rate. These devices might be for example sensor network, information displays, home- and industrial automatic systems, etcMain benefit compared with Bluetooth is lower power demandquick respond from sleep to awake and cost. ZigBee works in most cases at 2.4 GHz radio band frequency with data transmission rates from 20 to 900 kb/s. ZigBee protocol supports different types of network like star, tree and generic mesh. Network nodes can have different roles like coordinator, router or end device
  
-===== In practice =====+Based on ZigBee wireless modules direct connection between two devices or more complicated network can be set up. In figure below a sensor network transferring measurement to user interface is illustrated.
  
-Homelab's communication board has a place for connecting ZigBee's module called "Xbee". Communication between it and the controller takes place using controller's UART interface. The device's mode is changed with the command "+++" to AT mode, further configuration is done with standard AT command. If communication between two modules has been established, then is returned to data transfer.+===== Practice =====
  
-Näiteprogramm otsib esmalt ümbruskonnast teisi ZigBee seadmeid ja vastav abifunktsioon kuvab nende aadresside nimekirja ekraanilGlobaalsel 0000FFFF aadressil on eriomadussinna saates saavad andmed kätte kõik võrgus kättesaadavad moodulidNäites luuakse ühendus ühe soovitud mooduligamisjärel saab nuppe vajutades vastastikku muuta moodulite LED-ide olekut.+Robotic HomeLab Communication board has a connector for wireless modules, including ZigBee module XBee from MaxtreamCommunication between module and the controller is realized over  UART interface. At first device is set to API mode by sending command "+++". Further configuration is done with standard AT command found on device manual. When communication between two modules has been establisheddevice will be returned to transfer mode. 
 + 
 +Example code above is searching surroundings for other Zigbee devices and found device addresses devices are displayed on Homelab User Interface module LCD display. Global address 0000FFFF has a special meaning - info sent to this address is received by all available devices. In the example codeafter searching other devices one is connected and devices start to sending a button pressing event to each other by showing the result on the other device LED.
  
 <code c> <code c>
Line 23: Line 24:
 #include <homelab/pin.h> #include <homelab/pin.h>
  
-//Lisame ZigBee mooduli toe+//Adding ZigBee module support
 #include <homelab/module/zigbee.h> #include <homelab/module/zigbee.h>
  
-// USART liidese määramine+// Determination of the USART interface
 usart port = USART(1); usart port = USART(1);
  
-// LEDid ja nupud määrata+// LED and button pin setup
 pin leds[3] = { PIN(C, 5), PIN(C, 4), PIN(C, 3) }; pin leds[3] = { PIN(C, 5), PIN(C, 4), PIN(C, 3) };
 pin buttons[3] = { PIN(C, 0), PIN(C, 1), PIN(C, 2) }; pin buttons[3] = { PIN(C, 0), PIN(C, 1), PIN(C, 2) };
  
-// ZigBee moodulite max arv võrgus + broadcast aadress + 1+// Max numbers of ZigBee modules in network + broadcast address +1
 #define ZIGBEE_MAX_NODES 4 #define ZIGBEE_MAX_NODES 4
  
 int8_t wait_button(uint16_t ms); int8_t wait_button(uint16_t ms);
  
-// Teiste leitavate zigbee moodulite aadresside massiiv+// Address array of other Zigbee modules found in network
 zigbee_node_t nodelist[ZIGBEE_MAX_NODES]; zigbee_node_t nodelist[ZIGBEE_MAX_NODES];
  
Line 44: Line 45:
 int main(void) int main(void)
 { {
-    uint8_t adr = 0; //ühendatava mooduli jrk. nimekirjas+    uint8_t adr = 0; //Acquired module order list
   
-    // seadista LEDide ja nuppude I/O pordid+    // LED and buttons I/O ports configuration
     for (int i=0; i<3; i++)     for (int i=0; i<3; i++)
     {     {
Line 53: Line 54:
     }     }
  
-    // USART liidese seadistamine ZigBee side jaoks+    // Configuration of USART interface for communication whit ZigBee module
     usart_init_async(port,     usart_init_async(port,
                      USART_DATABITS_8,                      USART_DATABITS_8,
Line 60: Line 61:
                      USART_BAUDRATE_ASYNC(9600));                      USART_BAUDRATE_ASYNC(9600));
  
-    // LCD ekraani algseadistamine+    // LCD display initalization
     lcd_gfx_init();     lcd_gfx_init();
  
-    // Ekraani puhastamine+    // Clear LCD
     lcd_gfx_clear();     lcd_gfx_clear();
  
-    // Taustavalgustuse tööle lülitamine+    // Turning back light ON
     lcd_gfx_backlight(true);     lcd_gfx_backlight(true);
  
-    //Oota kuni teisi ZigBee mooduleid otsitakse läbiümbrusest+    //Wait until other ZigBee modules are searched from area near by
     lcd_gfx_clear();     lcd_gfx_clear();
     lcd_gfx_goto_char_xy(0, 0);     lcd_gfx_goto_char_xy(0, 0);
Line 75: Line 76:
  
     lcd_gfx_goto_char_xy(0, 1);     lcd_gfx_goto_char_xy(0, 1);
-    lcd_gfx_write_string("Otsin...");+    lcd_gfx_write_string("Searching...");
  
-    // Otsib ümbrusest teisiZigBee mooduleid +    // Searching other ZigBee modules 
-    // täidab nodelist massiivi leitud moodulite infoga.+    // fills nodelist array with found modules info
     zigbee_find_nodes(port, nodelist, ZIGBEE_MAX_NODES);     zigbee_find_nodes(port, nodelist, ZIGBEE_MAX_NODES);
  
     //lcd_gfx_clear();     //lcd_gfx_clear();
     lcd_gfx_goto_char_xy(0, 1);     lcd_gfx_goto_char_xy(0, 1);
-    lcd_gfx_write_string("Leitud:  ");+    lcd_gfx_write_string("Found:  ");
  
-    // Kuvab ekraanil leitud moodulite nimekirja +    // Displays the list of found modules on LCD 
-    // (mis reale kirjutabkust võtab adrmitu tk max)+    // (on what line to writewhere takes addr.how many max)
     zigbee_lcd_show_nodes(2, nodelist, ZIGBEE_MAX_NODES);      zigbee_lcd_show_nodes(2, nodelist, ZIGBEE_MAX_NODES);
     hw_delay_ms(3000);     hw_delay_ms(3000);
     lcd_gfx_clear();     lcd_gfx_clear();
   
-    // Kuvab ekraanil ühendamise teate+    // Displaying connecting on LCD
     lcd_gfx_goto_char_xy(0, 0);     lcd_gfx_goto_char_xy(0, 0);
-    lcd_gfx_write_string("Yhendan...");+    lcd_gfx_write_string("Connecting...");
     lcd_gfx_goto_char_xy(0, 1);     lcd_gfx_goto_char_xy(0, 1);
-    //kuvab ainult aadressi tagumise osa (tähemärki)+    //Displays only last digit form the address
     lcd_gfx_write_string((nodelist + adr)->address64l);     lcd_gfx_write_string((nodelist + adr)->address64l);
   
-    // Seadista ZigBee saatma infot valitud ZigBee nodele+    // Confederate ZigBee to send info for chosen ZigBee module's node
-    // antud juhul esimesele [0] +    // in this case to first [0] 
-    // (mis porti kasutabkust võtab adr)+    // (What port is usingwhere takes the address)
     zigbee_set_destination(port, &nodelist[adr]);     zigbee_set_destination(port, &nodelist[adr]);
  
-    // Joonistab ekraanile infot+    // Displays info on LCD
     lcd_gfx_goto_char_xy(0, 0);     lcd_gfx_goto_char_xy(0, 0);
     lcd_gfx_write_string("  ZigBee demo");     lcd_gfx_write_string("  ZigBee demo");
  
     lcd_gfx_goto_char_xy(0, 1);     lcd_gfx_goto_char_xy(0, 1);
-    lcd_gfx_write_string("Nupp1: LED1");+    lcd_gfx_write_string("Button1: LED1");
  
     lcd_gfx_goto_char_xy(0, 2);     lcd_gfx_goto_char_xy(0, 2);
-    lcd_gfx_write_string("Nupp2: LED2");+    lcd_gfx_write_string("Button2: LED2");
  
-    // Hoia meeles eelmist nuppu selleks, et vältida olukorda, +    // Save the state of previous button to avoid multiple button pushes at once
-    // kus nuppu all hoides tuleb sada nupuvajutusi järjest+    // At first is -1 ie none of the buttons is pushed.
-    // Algatuseks olgu see -1 ehk ükski nupp pole all.+
     int8_t previousButton = -1;     int8_t previousButton = -1;
  
-    // Lõputu tsükkel moodulite andmetevahetuse näitamiseks+    // Endles-loop for communicating between modules
     while (true)     while (true)
     {     {
-        int8_t button; //muutuja nupuvajutuse registreerimiseks +        int8_t button; //variable for saving button pushes   
- +        // wait millisecond for button
-        // Oota nuppu millisekund+
         button = wait_button(1);         button = wait_button(1);
  
-        // Kui eelmises tsüklis oli nupp üleval ja nüüd on all+        // if in last cycle button wasn't pressed but now is 
         if (previousButton == -1 && button != -1)         if (previousButton == -1 && button != -1)
         {         {
-            // teisenda nupu indeks liites täht +            // Convert button's index by adding 
-     // ja saada teisele moodulile +     // and sent it to other modules 
-            // A täht on esimene nupp, B täht teine nupp jne+            // A is for first button, B for second and so on
             usart_send_char(port, 'A' + button);             usart_send_char(port, 'A' + button);
         }         }
  
-        // Loe USART'st+        // read from USART
         if (usart_has_data(port))         if (usart_has_data(port))
         {         {
-            // loe bait, teisenda leds massiivi indeksiks +            // Read bait, convert to leds array index 
-     //ja muuda väljundit.+     //and change the output.
             pin_toggle(leds[usart_read_char(port) - 'A']);             pin_toggle(leds[usart_read_char(port) - 'A']);
         }         }
  
-        // Jäta meelde mis nupp oli hetkel alla vajutatud+        // remember what button was pressed
         previousButton = button;         previousButton = button;
     }     }
 } }
  
-// Ootab nupu vajutust ms millisekundit+// Wait for button to be pressed for ms milliseconds
-//Kui tuleb nupu vajutus, tagastab vastava nupu järjekorra numbri+//If button is pressed returns the queue number of the button
 int8_t wait_button(uint16_t ms) int8_t wait_button(uint16_t ms)
 { {
-    // Vaikimisi -1 tähendabet ükski nupp pole vajutatud.+    // By default -1 meansthat no button is pressed.
     int8_t button_nr = -1;     int8_t button_nr = -1;
     uint16_t counter = 0;     uint16_t counter = 0;
     do     do
     {     {
-        // vaata kas mõni nupp on all+        // check if one of the buttons is pressed
         for (uint8_t i=0; i<3; i++)         for (uint8_t i=0; i<3; i++)
         {         {
Line 167: Line 166:
         }         }
  
-        // oota millisekund+        // wait for millisecond
         hw_delay_ms(1);         hw_delay_ms(1);
  
-        // suurenda millisekundi loendurit+        // increase millisecond counter
         counter++;         counter++;
     } while (button_nr == -1 && (counter < ms));     } while (button_nr == -1 && (counter < ms));
  
     return button_nr;     return button_nr;
-} 
-</code> 
- 
- 
-==== TH Suvekool ==== 
- 
-<code c> 
-#include <homelab/usart.h> 
-#include <homelab/delay.h> 
-#include <homelab/pin.h> 
-  
-//Lisame ZigBee mooduli toe 
-#include <homelab/module/zigbee.h> 
-  
-// USART liidese määramine ZigBee jaoks 
-usart port = USART(1); 
-  
-// LEDid ja nupud määrata 
-pin leds[3] = { PIN(C, 5), PIN(C, 4), PIN(C, 3) }; 
-pin buttons[3] = { PIN(C, 2), PIN(C, 1), PIN(C, 0) }; 
-  
-// Teiste leitavate zigbee moodulite aadresside massiiv 
-zigbee_node_t nodelist[6]; // 1 + broadcast aadress + varu(1) 
-  
-  
-int main(void) 
-{ 
-     int8_t button = -1; //muutuja nupuvajutuse registreerimiseks 
-  
-    // seadista LEDide ja nuppude I/O pordid 
-    for (int i=0; i<3; i++) 
-    { 
-        pin_setup_output(leds[i]); 
-        pin_setup_input(buttons[i]); 
-    } 
-  
-    // USART liidese seadistamine ZigBee side jaoks 
-    usart_init_async(port, 
-                     USART_DATABITS_8, 
-                     USART_STOPBITS_ONE, 
-                     USART_PARITY_NONE, 
-                     USART_BAUDRATE_ASYNC(9600)); 
-  
-  
-    // Otsib ümbrusest teisiZigBee mooduleid 
-    // täidab nodelist massiivi leitud moodulite aadressidega 
-    pin_set(leds[0]);      
- 
-    zigbee_find_nodes(port, nodelist, 6); //millist USART-it kasutab, kuhu salvestab aadressid, mitu mahub võrku 
-    // võtab aega 
-    pin_set(leds[1]); 
-    // Seadista ZigBee saatma infot valitud ZigBee nodele, 
-    // (mis porti kasutab, kust võtab adr) 
-    zigbee_set_destination(port, &nodelist[0]); //esimesega ühenda 
-    //zigbee_set_destination(port, 0xFFFFFFFFFFFFFFFFFF); //esimesega ühenda 
- 
- //Kustuta LED-id -> ühendus olemas 
- pin_set(leds[2]); 
-  
-    // Lõputu tsükkel moodulite andmetevahetuse näitamiseks 
-    while (true) 
-    { 
- // vaata kas mõni nupp on alla vajutatud 
-        for (uint8_t i=0; i<3; i++) if (!pin_get_value(buttons[i])) button = i; 
-  
-        // kui nuppu on vajutatud 
-        if (button != -1) 
-        { 
-////////////////////   SISU  //////////////////////// 
-        } 
-    } 
 } }
 </code> </code>
en/examples/communication/zigbee.1334066048.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0