Advertisement
Guest User

Xbee and BTM-182 configured via Arduino

a guest
Mar 23rd, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 KB | None | 0 0
  1. /*
  2.  
  3. */
  4. #include <SoftwareSerial.h>
  5.  
  6. #include <ShiftRegLCD.h>
  7.  
  8. SoftwareSerial xbeeser(1, 0);
  9. SoftwareSerial btser(7, 8);
  10.  
  11. const byte enPin = 5;    // SR Clock from Arduino pin 11
  12. const byte dataPin  = 4;    // SR Data from Arduino pin 10
  13. const byte clockPin = 3;    // SR Clock from Arduino pin 11
  14.  
  15. ShiftRegLCD srlcd(dataPin, clockPin, enPin);
  16.  
  17. //want simple XBEE config
  18. #define XBEESLEEP 6  //Pin 12 for XBee sleep control, goes to pin 9 on xbee
  19.  
  20. void setup()
  21. {
  22.   int result;
  23.   char state=0, temp;
  24.   //xbee
  25.   pinMode (1,INPUT);
  26.   pinMode (0,OUTPUT);
  27.   pinMode(XBEESLEEP,OUTPUT); //6
  28.   //bt
  29.   pinMode (7,INPUT);
  30.   pinMode (8,OUTPUT);
  31.  
  32.   xbeeser.begin(19200);
  33.   btser.begin(19200);
  34.  
  35.   srlcd.clear();
  36.  
  37.   //setup xbee
  38.   digitalWrite(XBEESLEEP, LOW);
  39.   xbeeser.listen();
  40.   srlcd.print("XBee");
  41.   delay(1000);
  42.   xbeeser.print("+++"); // xbeeser.write(0x0D);
  43.   delay(1000);
  44.   while(state != 6)
  45.   {
  46.     if(state == 3)
  47.     {
  48.       state++;
  49.       xbeeser.print("ATCN");
  50.       xbeeser.write(0x0D);
  51.       delay(100);
  52.     }
  53.     if(xbeeser.available())
  54.     {
  55.        temp = xbeeser.read();
  56.        if(temp == 0x0D)
  57.        {
  58.          state++;
  59.          continue;
  60.        }
  61.        if(temp == 'O')
  62.          state++;
  63.        if(temp == 'K')
  64.          state++;
  65.        srlcd.print((char)temp);
  66.     }
  67.   }
  68.   digitalWrite(XBEESLEEP, HIGH);
  69.   //xbee done, now BT
  70.   btser.listen();
  71.   btser.write(0x0D);
  72.   delay(1000);
  73.   btser.print("ATA"); btser.write(0x0D);
  74.   delay(1000);
  75.   while(state != 3)
  76.   {
  77.     if(btser.available())
  78.     {
  79.        temp = btser.read();
  80.        if(temp == 0x0D || temp == 0x0A)
  81.        {
  82.          state++;
  83.          continue;
  84.        }
  85.        if(temp == 'O')
  86.          state++;
  87.        if(temp == 'K')
  88.          state++;
  89.        srlcd.print((char)temp);  
  90.     }
  91.   }
  92.   //free of loop :P
  93.   //delay(1000);
  94.   srlcd.clear();
  95.   // Print a message to the LCD.
  96.   srlcd.print("HELLO, WORLD!");
  97. }
  98.  
  99. void loop()
  100. {
  101.    //put it to sleep
  102.    //digitalWrite(XBEESLEEP, HIGH);
  103.    
  104.    //Serial.print("test");
  105.   //if read something from serial, output to soft serial, v
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement