After installing the X-CTU software and the VCP drivers for FTDI on the computer(in order to configurate the XBees), we set the PAN ID to "ABCD" and configured one as Coordinator, one as Router and set the Destination Adresses to one another so they could communicate. We tested the connection and it didn't work at first because probably there was another PAN with the same ID, so we changed it to "BBBB" (amazingly no one thought about that).
After that, we tried several possible applications with another group, managed to send a multi-hop message, but in the end we changed the idea to creating a wireless mini-piano.
Thus,we connected one XBee the computer and the other one to the Arduino as shown in the schematic below, added a buzzer on PIN 12 and coded the application.
What the application does is send characters from the keyboard of the computer through the USB serial connection to the Xbee, which in turn forwards the data to the Xbee connected to the Arduino, and the Arduino plays different sounds based on the characters it receives. The Arduino also gives feedback to the Xbee so we can see what the Arduino received in the serial connection on the computer.
We coded 2 octaves on the characters QWERTYUIOP{}| and `1234567890-=, "q" is middle C, "w" is C#, "e" is D and so on.
After that, we tried several possible applications with another group, managed to send a multi-hop message, but in the end we changed the idea to creating a wireless mini-piano.
Thus,we connected one XBee the computer and the other one to the Arduino as shown in the schematic below, added a buzzer on PIN 12 and coded the application.
What the application does is send characters from the keyboard of the computer through the USB serial connection to the Xbee, which in turn forwards the data to the Xbee connected to the Arduino, and the Arduino plays different sounds based on the characters it receives. The Arduino also gives feedback to the Xbee so we can see what the Arduino received in the serial connection on the computer.
We coded 2 octaves on the characters QWERTYUIOP{}| and `1234567890-=, "q" is middle C, "w" is C#, "e" is D and so on.
Video:
Software required:
- X-CTU software: http://ftp1.digi.com/support/utilities/40003026_A.exe
- VCP drivers for FTDI: http://www.ftdichip.com/Drivers/CDM/CDM%20v2.10.00%20WHQL%20Certified.exe
Materials used:
- 2 Digi XBee.
- 2 XBee Explorer.
- 1 Type-A USB to mini-USB cables.
- 1 Computer
- 1 Arduino Uno
- 1 Breadboard(not required)
- 1 Buzzer(Piezoelectric)
Schematics
Code
/*
WSN LAB 2. Zigbee & Arduino
*/
int speakerPin = 12;
//lower octave
int tones[] = {261, 277, 294, 311, 330, 349,
370, 392, 415, 440, 466, 494};
// mid
C C# D D#
E F F#
G G# A A#
B
//higher octave
int tones2[] = {523, 554, 587, 622, 659, 698,
740, 784, 831, 880, 932, 988, 1047};
//
C C# D D#
E F F#
G G# A A#
B C
char
incomingByte; // a variable to read incoming serial data into
void setup() {
Serial.begin(9600); //begin the serial communication with
the XBEE
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial
buffer:
incomingByte =
Serial.read();
Serial.print("Sending feedback to Zigbee:");
Serial.println(incomingByte);
// play a different note depending on
the
// value received from XBee:
switch (incomingByte) {
case 'Q':
case 'q':
tone(speakerPin,
tones[0]);
delay(100);
break;
case 'W':
case 'w':
tone(speakerPin,
tones[1]);
delay(100);
break;
case 'e':
case 'E':
tone(speakerPin,
tones[2]);
delay(100);
break;
case 'r':
case 'R':
tone(speakerPin,
tones[3]);
delay(100);
break;
case 't':
case 'T':
tone(speakerPin,
tones[4]);
delay(100);
break;
case 'y':
case 'Y':
tone(speakerPin,
tones[5]);
delay(100);
break;
case 'u':
case 'U':
tone(speakerPin,
tones[6]);
delay(100);
break;
case 'i':
case 'I':
tone(speakerPin,
tones[7]);
delay(100);
break;
case 'o':
case 'O':
tone(speakerPin,
tones[8]);
delay(100);
break;
case 'p':
case 'P':
tone(speakerPin,
tones[9]);
delay(100);
break;
case '[':
case '{':
tone(speakerPin,
tones[10]);
delay(100);
break;
case ']':
case '}':
tone(speakerPin,
tones[11]);
delay(100);
break;
case '`':
case '~':
tone(speakerPin,
tones2[0]);
delay(100);
break;
case '1':
case '!':
tone(speakerPin,
tones2[1]);
delay(100);
break;
case '2':
case '@':
tone(speakerPin,
tones2[2]);
delay(100);
break;
case '3':
case '#':
tone(speakerPin,
tones2[3]);
delay(100);
break;
case '4':
case '$':
tone(speakerPin,
tones2[4]);
delay(100);
break;
case '5':
case '%':
tone(speakerPin,
tones2[5]);
delay(100);
break;
case '6':
case '^':
tone(speakerPin,
tones2[6]);
delay(100);
break;
case '7':
case '&':
tone(speakerPin,
tones2[7]);
delay(100);
break;
case '8':
case '*':
tone(speakerPin,
tones2[8]);
delay(100);
break;
case '9':
case '(':
tone(speakerPin,
tones2[9]);
delay(100);
break;
case '0':
case ')':
tone(speakerPin,
tones2[10]);
delay(100);
break;
case '-':
case '_':
tone(speakerPin,
tones2[11]);
delay(100);
break;
case '=':
case '+':
tone(speakerPin,
tones2[12]);
delay(100);
break;
}
}
//stop the buzzer as soon as it's done processing the
serial buffer
if (!(Serial.available() > 0)) noTone(speakerPin);
}

No comments:
Post a Comment