Difference between revisions of "ECE497 Project: XBee"

From eLinux.org
Jump to: navigation, search
m (Sample)
m (Grading Template)
(15 intermediate revisions by 4 users not shown)
Line 5: Line 5:
  
 
== Grading Template ==
 
== Grading Template ==
 +
 
I'm using the following template to grade.  Each slot is 10 points.
 
I'm using the following template to grade.  Each slot is 10 points.
 
0 = Missing, 5=OK, 10=Wow!
 
0 = Missing, 5=OK, 10=Wow!
  
 
<pre style="color:red">
 
<pre style="color:red">
00 Executive Summary
+
08 Executive Summary
05 Installation Instructions  
+
09 Installation Instructions  
01 User Instructions
+
10 User Instructions (Nice details for each device.)
00 Highlights
+
08 Highlights
00 Theory of Operation
+
09 Theory of Operation
00 Work Breakdown
+
09 Work Breakdown
00 Future Work
+
09 Future Work
00 Conclusions
+
09 Conclusions
00 Demo
+
10 Demo
00 Late
+
10 On time
Comments: I'm looking forward to seeing this.
+
Comments: I wish you could have gotten two-way communication working.
  
Score:  06/100
+
Score:  91/100
 
</pre>
 
</pre>
  
 
== Executive Summary ==
 
== Executive Summary ==
  
The XBee project involves taking two series-one XBee modules and interfacing them with the various sensors that have been documented in our ECE497 group. Our goal is to create wiki pages which expand on the sensors to include sample wireless communication documentation and source code.
+
The XBee project involves taking two series-one XBee modules <span style="color:red">(Include a link to these)</span> and interfacing them with the various sensors that have been documented in our ECE497 group. Our goal was to create wiki sections which expand on the sensors to include sample wireless communication documentation and source code.
 
+
We have successfully connected to the XBee radios from the Bones and sent data using the /dev/ttyO file system. We have also successfully done wireless implementations of the force sensitive resistor, the magnetometer and the joystick alone a set of functions for expanding this to any sensor.
+
  
We were unable to get a working program with 2-way communication with 2 XBees each sending and receiving data because of synchronization problems. Addressing this would likely require the development of a simple communication to prevent deadlocks and to ensure the receiving program knows what the data is when it receives it.
+
We have successfully connected to the XBee radios from the Bones and sent data using the <code>/dev/ttyO</code> file system. We have also successfully done wireless implementations of the force sensitive resistor, the magnetometer, and the joystick alone a set of functions for expanding this to any sensor.
  
In conclusion, we're using XBee modules to communicate from one Bone to another. We have successfully communicated wirelessly with three sensors: the force sensitive resistor, magnetometer and joystick.
+
In conclusion, we're using XBee modules to communicate from one Bone to another. We have successfully communicated wirelessly with three sensors: the force sensitive resistor, magnetometer, and joystick. We hope that these instructions and code libraries are useful to hobbyists who wish to implement their own wireless solutions with the BeagleBone.
  
 
== General Installation Instructions ==
 
== General Installation Instructions ==
Line 65: Line 64:
 
Our git repo for this project is available here: [https://github.com/duganje/ECE497_XBEE.git https://github.com/duganje/ECE497_XBEE.git]. To begin, run  
 
Our git repo for this project is available here: [https://github.com/duganje/ECE497_XBEE.git https://github.com/duganje/ECE497_XBEE.git]. To begin, run  
 
  beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
 
  beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
to clone he repository. This contains three folders with examples of XBee implementation for specific sensors and <code>XBee.c</code>, which contains helper functions for using the XBee. You are now able to send data wirelessly using the <code>SendIntXbee()</code> and <code>ReceiveIntXbee()</code> functions. Repeat this procedure on a separate BeagleBone and use the same functions to receive and reply data.
+
to clone the repository. This contains three folders with examples of XBee implementation for specific sensors and <code>XBee.c</code>, which contains helper functions for using the XBee. You are now able to send data wirelessly using the <code>SendIntXbee()</code> and <code>ReceiveIntXbee()</code> functions after running <code>initializeXbee()</code>. Clone the repository on a separate BeagleBone and use the same functions to receive and reply data.
 
<!--
 
<!--
 
Give step by step instructions on how to install your project on the SPEd2 image.   
 
Give step by step instructions on how to install your project on the SPEd2 image.   
Line 76: Line 75:
  
 
== 0.5" Force Sensitive Resistor ==
 
== 0.5" Force Sensitive Resistor ==
 +
 
These instructions are for interfacing the [[SparkFun: 0.5" Force Sensitive Resistor|0.5" Force Sensitive Resistor]] with the XBee.
 
These instructions are for interfacing the [[SparkFun: 0.5" Force Sensitive Resistor|0.5" Force Sensitive Resistor]] with the XBee.
  
 
=== Required Items ===
 
=== Required Items ===
 +
 
*2 x [http://adafruit.com/products/513 BeagleBone]
 
*2 x [http://adafruit.com/products/513 BeagleBone]
 
*2 x [http://www.adafruit.com/products/128 XBee Module]
 
*2 x [http://www.adafruit.com/products/128 XBee Module]
 
*2 x [http://www.adafruit.com/products/126 XBee Adaptor Kit]
 
*2 x [http://www.adafruit.com/products/126 XBee Adaptor Kit]
 
*1 x [https://www.sparkfun.com/products/9375 0.5" Force Sensitive Resistor]
 
*1 x [https://www.sparkfun.com/products/9375 0.5" Force Sensitive Resistor]
 +
*1 x 27kΩ resistor
  
 
=== Hardware ===
 
=== Hardware ===
 +
 
First we will connect the force-sensitive resistor to the Bone (P9 header). A 27kΩ resistor is used to connect the 3.3V source (pin 3) from the Bone to one pin of the force-sensitive resistor. Then, the other pin of the force-sensitive resistor is connected to ground (pin 1). An analog pin (AIN) on the Bone connects to the node containing both resistors, and values can be read off of that AIN. AIN5 (pin 36) is being used to read values on the Bone.
 
First we will connect the force-sensitive resistor to the Bone (P9 header). A 27kΩ resistor is used to connect the 3.3V source (pin 3) from the Bone to one pin of the force-sensitive resistor. Then, the other pin of the force-sensitive resistor is connected to ground (pin 1). An analog pin (AIN) on the Bone connects to the node containing both resistors, and values can be read off of that AIN. AIN5 (pin 36) is being used to read values on the Bone.
  
Line 111: Line 114:
  
 
=== Software ===
 
=== Software ===
 +
 
We're going to start with these two pieces of code as a reference and combine them:
 
We're going to start with these two pieces of code as a reference and combine them:
 +
 
*[https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c Code to interface with the force sensitive resistor]
 
*[https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c Code to interface with the force sensitive resistor]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c Code to interface with the XBee module]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c Code to interface with the XBee module]
Line 120: Line 125:
  
 
==== Sending ====
 
==== Sending ====
Start with the [https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c resistor code] as a base and add the following include to the top of the file:
+
 
 +
Start with the [https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c resistor code] as a base and add the following include to the top of the file to add our XBee library (available [https://github.com/duganje/ECE497_XBEE here]):
  
 
  #include "XBee.h"
 
  #include "XBee.h"
Line 133: Line 139:
  
 
==== Receiving ====
 
==== Receiving ====
 +
 
Start with the [https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c XBee code] as a base and create a <code>main</code> function. First in <code>main</code>, add a call to <code>initializeXbee()</code> to setup the Bone to use the module.
 
Start with the [https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c XBee code] as a base and create a <code>main</code> function. First in <code>main</code>, add a call to <code>initializeXbee()</code> to setup the Bone to use the module.
  
Line 152: Line 159:
  
 
==== Sample ====
 
==== Sample ====
Based on the instructions above, I've created a sample set of programs. Using two Bones, the send program runs on one and the receive program runs on another. The "send" Bone includes an XBee module and the force sensitive resistor, [[ECE497_Project:_XBee#Hardware_2|hooked-up as described here]]. The second Bone includes the XBee module hooked-up in the same way with the addition of an LED connected to pin 12 (GPIO1_28) of the Bone. Connect the ground pin of the LED to the Bone's ground (pin 1) using a 220Ω resistor.
 
  
Running both programs emulated the original function of the [https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c force resistor sample code], the only difference being that the data is now sent wirelessly from one Bone to another.
+
===== Required Items =====
 +
 
 +
* LED
 +
* 220Ω resistor
 +
 
 +
===== Instructions =====
 +
 
 +
Based on the instructions above, I've created a sample set of programs. Using two Bones, the send program runs on one and the receive program runs on another. The "send" Bone includes an XBee module and the force sensitive resistor, [[ECE497 Project: XBee#Hardware 2|hooked-up as described here]]. The second Bone includes the XBee module hooked-up in the same way with the addition of an LED connected to pin 12 (GPIO1_28) of the Bone. Connect the ground pin of the LED to the Bone's ground (pin 1) using a 220Ω resistor.
 +
 
 +
Running both programs emulates the original function of the [https://github.com/shinnsm/ECE497/blob/master/MiniProject02/miniProj2.c force resistor sample code], the only difference being that the data is now sent wirelessly from one Bone to another.
  
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/ForceResistor/sendResistor.c Send Program]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/ForceResistor/sendResistor.c Send Program]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/ForceResistor/receiveResistor.c Receive Program]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/ForceResistor/receiveResistor.c Receive Program]
  
To easily use the program, clone [https://github.com/duganje/ECE497_XBEE.git our Git repository], cd into the ForceResistor directory, and then run the <code>make</code> command:
+
To easily run the programs, follow these steps (you can skip the first step if you have already clone the repository):
 +
beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
 +
beagle$ cd ECE497_XBEE
 +
beagle$ cd ForceResistor
 +
beagle$ make
  
make
+
This will create 2 executables: '''sendResistor''' and '''receiveResistor'''. Run the programs by running:
  
This will build both the <code>sendResistor</code> and <code>receiveResistor</code> programs to run on each BeagleBone. Copy each program to a Bone and run them at the same time with the XBee modules and LED connected as previously described. You will then be able to squeeze the force sensitive resistor and see the LED light up on the other BeagleBone. We've created a [[ECE497 Project: XBee#Force Sensitive Resistor YouTube Demo|YouTube demo]] of this program in action.
+
beagle$ ./sendResistor
 +
 
 +
on the Bone connected to the XBee and the force sensitive resistor and
 +
 
 +
beagle$ ./receiveResistor
 +
 
 +
on the Bone connected to the XBee and the LED.
 +
 
 +
You will then be able to squeeze the force sensitive resistor and see the LED light up on the other BeagleBone. We've created a [[ECE497 Project: XBee#Force Sensitive Resistor YouTube Demo|YouTube demo]] of this program in action.
  
 
== Wireless 2-Axis Thumb Joystick ==
 
== Wireless 2-Axis Thumb Joystick ==
 +
 
These instructions are for interfacing the [[Adafruit: 2-Axis Thumb Joystick|2-Axis Thumb Joystick]] with the XBee. This application could be useful in a wireless controller setting.  
 
These instructions are for interfacing the [[Adafruit: 2-Axis Thumb Joystick|2-Axis Thumb Joystick]] with the XBee. This application could be useful in a wireless controller setting.  
  
 
=== Required Items ===
 
=== Required Items ===
 +
 
*2 X [http://adafruit.com/products/513 BeagleBone]
 
*2 X [http://adafruit.com/products/513 BeagleBone]
 
*2 X [http://www.adafruit.com/products/128 XBee Module]
 
*2 X [http://www.adafruit.com/products/128 XBee Module]
Line 175: Line 204:
  
 
=== BeagleBone Wiring Instructions ===
 
=== BeagleBone Wiring Instructions ===
 +
 
On your first BeagleBone, wire pins 36 and 38 to your two analog inputs. Wire the Beagle's 1.8V VCC output, pin 32, to the VCC input of the Joystick. Finally, wire the select GPIO signal to the GPIO_7 pin or pin 42.
 
On your first BeagleBone, wire pins 36 and 38 to your two analog inputs. Wire the Beagle's 1.8V VCC output, pin 32, to the VCC input of the Joystick. Finally, wire the select GPIO signal to the GPIO_7 pin or pin 42.
  
Line 204: Line 234:
  
 
=== Usage Instructions ===
 
=== Usage Instructions ===
On both BeagleBones, clone this repository:
+
 
 +
On both BeagleBones, clone this repository: https://github.com/duganje/ECE497_XBEE.git
 +
Use the following to run the joystick code (you can skip the first step if you have already cloned the repository):
 +
 
 +
beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
 +
beagle$ cd ECE497_XBEE
 +
beagle$ cd 2AxisJoystick
 +
beagle$ make
 +
 
 +
This will create 2 executables: '''joystickSend''' and '''joystickReceive'''. Run the code by doing:
 +
 
 +
beagle$ ./joystickSend
 +
 
 +
on the Bone connected to the XBee and the joystick and:
 +
 
 +
beagle$ ./joystickReceive
 +
 
 +
on the Bone connected to just the XBee.
  
 
== Magnetometer ==
 
== Magnetometer ==
 +
 
These instructions are for interfacing the [[Sparkfun: HMC5883L Magnetometer|HMC5883L Magnetometer]] with the XBee.
 
These instructions are for interfacing the [[Sparkfun: HMC5883L Magnetometer|HMC5883L Magnetometer]] with the XBee.
  
 
=== Required Items ===
 
=== Required Items ===
 +
 
*2 x [http://adafruit.com/products/513 BeagleBone]
 
*2 x [http://adafruit.com/products/513 BeagleBone]
 
*2 x [http://www.adafruit.com/products/128 XBee Module]
 
*2 x [http://www.adafruit.com/products/128 XBee Module]
 
*2 x [http://www.adafruit.com/products/126 XBee Adaptor Kit]
 
*2 x [http://www.adafruit.com/products/126 XBee Adaptor Kit]
 
*1 x [https://www.sparkfun.com/products/10530? Magnetometer Breakout Board]
 
*1 x [https://www.sparkfun.com/products/10530? Magnetometer Breakout Board]
 +
*2 x 4.7kΩ resistor
  
 
===Hardware===
 
===Hardware===
 +
 
The XBee radios should be connected to both Beagles as shown in the table below.  
 
The XBee radios should be connected to both Beagles as shown in the table below.  
  
Line 240: Line 291:
  
 
===Software===
 
===Software===
 +
 
The goal is to have the two BeagleBones attached to XBee radios with the one connected to the Magnetometer taking data and transmitting this data to the other Bone which will print the measured data.
 
The goal is to have the two BeagleBones attached to XBee radios with the one connected to the Magnetometer taking data and transmitting this data to the other Bone which will print the measured data.
  
Line 249: Line 301:
  
 
====Sending====
 
====Sending====
 +
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/Magnetometer/sendMag.c Tranmitting Magnetometer Data Code]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/Magnetometer/sendMag.c Tranmitting Magnetometer Data Code]
  
The code uses  [https://github.com/MarkAYoder/BeagleBoard-exercises/tree/master/i2c I2C code] from [[EBC Exercise 12 I2C]] and helper functions from [https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c XBee.c].  
+
The code uses  [https://github.com/MarkAYoder/BeagleBoard-exercises/tree/master/i2c I2C code] from [[EBC Exercise 12 I2C]] and helper functions from [https://github.com/duganje/ECE497_XBEE/blob/master/XBee.c XBee.c].
The program uses  
+
 
 +
The program uses:
 +
 
 
  i2cget(i2cbus, address, daddress);
 
  i2cget(i2cbus, address, daddress);
 +
 
to get the data from the magnetometer and  
 
to get the data from the magnetometer and  
 +
 
  sendShortXbee(val);
 
  sendShortXbee(val);
 +
 
to send these values to the receiving XBee.
 
to send these values to the receiving XBee.
  
 
====Receiving====
 
====Receiving====
 +
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/Magnetometer/receiveMag.c Receiving Magnetometer Data Code]
 
*[https://github.com/duganje/ECE497_XBEE/blob/master/Magnetometer/receiveMag.c Receiving Magnetometer Data Code]
  
The receiving code uses  
+
The receiving code uses:
 +
 
 
  receiveShortXbee();
 
  receiveShortXbee();
 +
 
to read the values for each axis.
 
to read the values for each axis.
  
Line 270: Line 331:
  
 
===Running the Code===
 
===Running the Code===
use the following to run the magnetometer code (you can skip the first step if you have already clone the repository)
+
Use the following to run the magnetometer code (you can skip the first step if you have already clone the repository):
 +
 
 
  beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
 
  beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
  beagle$ cd ECE_497_XBEE
+
  beagle$ cd ECE497_XBEE
 
  beagle$ cd Magnetometer
 
  beagle$ cd Magnetometer
 
  beagle$ make
 
  beagle$ make
  
This will create 2 executables: '''receiveMag''' and '''sendMag'''. Run the code by doing
+
This will create 2 executables: '''receiveMag''' and '''sendMag'''. Run the code by doing:
 +
 
 
  beagle$ ./sendMag
 
  beagle$ ./sendMag
on the Bone connected to the XBee and the magnetometer and
+
 
 +
on the Bone connected to the XBee and the magnetometer and:
 +
 
 
  beagle$ ./receiveMag
 
  beagle$ ./receiveMag
on the Bone connected to just the XBee
+
 
 +
on the Bone connected to just the XBee.
  
 
== General Usage ==
 
== General Usage ==
 +
 
These instructions are a general how-to for using the XBee with any sensor.
 
These instructions are a general how-to for using the XBee with any sensor.
  
After cloning our repository to your favorite location, include the necessary header file, <code>XBee.h</code> (not created yet). In your <code>main.c</code> file or your program, first run: <pre>initializeXbee();</pre> which sets the pins we will need to communicate with the XBee using uart 2. Then in your main.c call: <pre>sendIntXbee(int yourInt);</pre> with <code>yourInt</code> being any data you would like to transmit. On your 2nd BeagleBone, call: <pre>receiveIntXbee();</pre> which will return the integer which was sent through <code>sendIntXbee(int yourInt)</code> on the 1st board.
+
After cloning our repository to your favorite location, include the necessary header file, <code>XBee.h</code>. In your <code>main.c</code> file or your program, first run: <pre>initializeXbee();</pre> which sets the pins we will need to communicate with the XBee using UART 2. Then in your <code>main.c</code> file, call: <pre>sendIntXbee(yourInt);</pre> with <code>yourInt</code> being any integer data you would like to transmit. On your 2nd BeagleBone, call: <pre>receiveIntXbee();</pre> which will return the integer which was sent through <code>sendIntXbee(int yourInt)</code> on the 1st board.
  
The send and receive functions can be easily modified to send any data type as shown in:
+
The send and receive functions can be easily modified to send any data type, as shown in <code>XBee.c</code> with the following functions:
  
<pre>sendShortXbee(short yourShort);</pre> <pre>receiveShortXbee();</pre>
+
<pre>sendShortXbee(short yourShort);</pre>
<!--
+
<pre>receiveShortXbee();</pre>
Once everything is installed, how do you use the program?  Give details here, so if you have a long user manual, link to it here.
+
-->
+
  
 
== Highlights ==
 
== Highlights ==
 +
 +
Our project is able to send and receive wireless data for a whole range of possible implementations. We've created YouTube demos for the three sensor implementations we've described so far:
  
 
=== Force Sensitive Resistor YouTube Demo ===
 
=== Force Sensitive Resistor YouTube Demo ===
 
{{#ev:youtube|Ds_BWsrvy1I}}
 
{{#ev:youtube|Ds_BWsrvy1I}}
 +
 +
=== 2-Axis Thumb Joystick YouTube Demo ===
 +
{{#ev:youtube|9t1MQGYNOt4}}
  
 
=== Magnetometer YouTube Demo ===
 
=== Magnetometer YouTube Demo ===
 
{{#ev:youtube|99bFqE54UHM}}
 
{{#ev:youtube|99bFqE54UHM}}
  
<!--
 
Here is where you brag about what your project can do.
 
 
Include a [http://www.youtube.com/ YouTube] demo.
 
-->
 
 
== Theory of Operation ==
 
== Theory of Operation ==
  
 
The main theory of operation is based on Linux's use of files. UART files on the Bone represent serial connections. With an XBee connected to the Bone's UART 2 as shown above, sent and received messages are written to <code>/dev/ttyO2</code> (the O is an uppercase O, not a zero). The BeagleBone's UARTs are accessed through <code>/dev/ttyO'''x'''</code>, where <code>'''x'''</code> is the UART number. Our code uses this and reads the file to receive a message and writes to the file to send a message. Any XBee's on the same network wil receive the message and we can do anything we want with it.
 
The main theory of operation is based on Linux's use of files. UART files on the Bone represent serial connections. With an XBee connected to the Bone's UART 2 as shown above, sent and received messages are written to <code>/dev/ttyO2</code> (the O is an uppercase O, not a zero). The BeagleBone's UARTs are accessed through <code>/dev/ttyO'''x'''</code>, where <code>'''x'''</code> is the UART number. Our code uses this and reads the file to receive a message and writes to the file to send a message. Any XBee's on the same network wil receive the message and we can do anything we want with it.
<!--
 
Give a high level overview of the structure of your software.  Are you using GStreamer?  Show a diagram of the pipeline.  Are you running multiple tasks?  Show what they do and how they interact.
 
-->
 
  
 
== Work Breakdown ==
 
== Work Breakdown ==
Line 323: Line 385:
 
*Thursday, 11/8 - Package language implemented between Bones. (done)
 
*Thursday, 11/8 - Package language implemented between Bones. (done)
 
*Sunday, 11/11 - YouTube demo uploaded. (done)
 
*Sunday, 11/11 - YouTube demo uploaded. (done)
*Monday, 11/12 - All documentation complete.
+
*Monday, 11/12 - All documentation complete. (done)
*Tuesday, 11/13 - Everything complete & all code ''makes''.
+
*Tuesday, 11/13 - Everything complete & all code ''makes''. (done)
  
 
=== Completed Work ===
 
=== Completed Work ===
Line 331: Line 393:
 
* Initial communication methods - Stephen Shinn
 
* Initial communication methods - Stephen Shinn
 
* Expanded communication methods - Josh Dugan
 
* Expanded communication methods - Josh Dugan
* Force Sensitive Resistor implementation - Stephen Shinn
+
* Initialization method - Josh Dugan
* Magnetometer implementation - Josh Dugan
+
* Force Sensitive Resistor implementation and demo - Stephen Shinn
* 2-Axis Thumb Joystick implementation - Matt Moravec
+
* Magnetometer implementation and demo - Josh Dugan
 +
* 2-Axis Thumb Joystick implementation and demo - Matt Moravec
  
=== To Do ===
 
 
* Update documentation - All
 
* Joystick demo - Matt
 
* Clone repo from scratch and test make
 
<!--
 
List the major tasks in your project and who did what.
 
 
Also list here what doesn't work yet and when you think it will be finished and who is finishing it.
 
-->
 
 
== Future Work ==
 
== Future Work ==
  
Line 357: Line 410:
 
In conclusion, we created an XBee wireless communication library for BeagleBone and adapted three sensors to use it. We've also documented general usage instructions for adapting XBee to use any type of sensor. We have not found a comprehensive source for how to use XBee modules with the BeagleBone, so our code and instructions are online with the intention that others use them as a reference.
 
In conclusion, we created an XBee wireless communication library for BeagleBone and adapted three sensors to use it. We've also documented general usage instructions for adapting XBee to use any type of sensor. We have not found a comprehensive source for how to use XBee modules with the BeagleBone, so our code and instructions are online with the intention that others use them as a reference.
  
Using the wireless modules is interesting, and the possibilities are endless. We've listed a few ideas above which could be done in the future. One interesting idea would be to create a practical XBee application that someone could actually use in their home or work life. With a few XBees around the house, one could have a small network for sending data and controlling Christmas lights or something with a sensor.
+
We were unable to get a working program with 2-way communication with 2 XBees each sending and receiving data because of synchronization problems. Addressing this would require the development of a communication protocol to prevent deadlocks and to ensure the receiving program knows what the data is when it receives it. This would be a logical next step in terms of future work for this project.
<!--
+
 
Give some concluding thoughts about the project. Suggest some future additions that could make it even more interesting.
+
Using the wireless modules is interesting, and there is a number of things you can do with them. We've listed a few ideas above which could be done in the future. One interesting idea would be to create a practical XBee application that someone could actually use in their home or work life. With a few XBees around the house, one could have a small network for sending data and using a sensor to control Christmas lights or something.
-->
+
 
 
{{YoderFoot}}
 
{{YoderFoot}}

Revision as of 21:55, 14 November 2012

thumb‎ Embedded Linux Class by Mark A. Yoder


Team members: Stephen Shinn, Matt Moravec, Josh Dugan.

Grading Template

I'm using the following template to grade. Each slot is 10 points. 0 = Missing, 5=OK, 10=Wow!

08 Executive Summary
09 Installation Instructions 
10 User Instructions (Nice details for each device.)
08 Highlights
09 Theory of Operation
09 Work Breakdown
09 Future Work
09 Conclusions
10 Demo
10 On time
Comments: I wish you could have gotten two-way communication working.

Score:  91/100

Executive Summary

The XBee project involves taking two series-one XBee modules (Include a link to these) and interfacing them with the various sensors that have been documented in our ECE497 group. Our goal was to create wiki sections which expand on the sensors to include sample wireless communication documentation and source code.

We have successfully connected to the XBee radios from the Bones and sent data using the /dev/ttyO file system. We have also successfully done wireless implementations of the force sensitive resistor, the magnetometer, and the joystick alone a set of functions for expanding this to any sensor.

In conclusion, we're using XBee modules to communicate from one Bone to another. We have successfully communicated wirelessly with three sensors: the force sensitive resistor, magnetometer, and joystick. We hope that these instructions and code libraries are useful to hobbyists who wish to implement their own wireless solutions with the BeagleBone.

General Installation Instructions

Hardware

The very first step is to solder your XBee module, see the instructions here. Once the module is assembled, you may wire-up the XBee module to the BeagleBone's serial ports. The table below describes how to hook up the module to UART2 on the Bone:

XBee Bone, P9 header
GND Ground, port 1
3V 3.3V, port 3
TX RX, port 22
RX TX, port 21

The image below shows the configuration:

XBee module connected to a BeagleBone.

Software

Our git repo for this project is available here: https://github.com/duganje/ECE497_XBEE.git. To begin, run

beagle$ git clone https://github.com/duganje/ECE497_XBEE.git

to clone the repository. This contains three folders with examples of XBee implementation for specific sensors and XBee.c, which contains helper functions for using the XBee. You are now able to send data wirelessly using the SendIntXbee() and ReceiveIntXbee() functions after running initializeXbee(). Clone the repository on a separate BeagleBone and use the same functions to receive and reply data.

0.5" Force Sensitive Resistor

These instructions are for interfacing the 0.5" Force Sensitive Resistor with the XBee.

Required Items

Hardware

First we will connect the force-sensitive resistor to the Bone (P9 header). A 27kΩ resistor is used to connect the 3.3V source (pin 3) from the Bone to one pin of the force-sensitive resistor. Then, the other pin of the force-sensitive resistor is connected to ground (pin 1). An analog pin (AIN) on the Bone connects to the node containing both resistors, and values can be read off of that AIN. AIN5 (pin 36) is being used to read values on the Bone.

Next we will connect the XBee module to the Bone. The table below describes the necessary wiring.

XBee Bone, P9 header
GND Ground, port 1
3V 3.3V, port 3
TX RX, port 22
RX TX, port 21

With everything wired-up, your connections should match the image below. Click on the image to view the full resolution.

Picture of connection

Software

We're going to start with these two pieces of code as a reference and combine them:

Running the code for the force sensitive resistor produces a value from 0 to 4096 depending on how much pressure is applied to the resistor. The harder the resistor is squeezed, the lower this value is. On line 46 of the force sensitive resistor code, analogValue is constantly updated and stores this number.

The instructions now fork depending on whether you're setting up the sending XBee code or the receiving XBee code. When you're done you will have two C programs, one running on each Bone.

Sending

Start with the resistor code as a base and add the following include to the top of the file to add our XBee library (available here):

#include "XBee.h"

Next, add a call to initializeXbee() in main of the resistor code before the while loop begins.

In the while loop after the value of analogValue is updated, add this line:

sendIntXbee(analogValue);

This will send the integer analog value to the receiving XBee. Now the number is constantly being sent in the while loop.

Receiving

Start with the XBee code as a base and create a main function. First in main, add a call to initializeXbee() to setup the Bone to use the module.

Next, add a while loop to main which continuously receives the integer analog value from the other Bone using the receiveIntXbee() function. Once the integer value is received, you're free to use that information for whatever purpose you wish. The example code below should give you an idea of how this is done:

void main(int argc, char **argv, char **envp) {
	// Initialize XBee
	initializeXbee();

	// Keep going
	while (1) {
	int analogValue = receiveIntXbee();

	// Do anything based on analog value
	if (analogValue < 1000)
		ButtonPressedFunction();
	}
}

Sample

Required Items
  • LED
  • 220Ω resistor
Instructions

Based on the instructions above, I've created a sample set of programs. Using two Bones, the send program runs on one and the receive program runs on another. The "send" Bone includes an XBee module and the force sensitive resistor, hooked-up as described here. The second Bone includes the XBee module hooked-up in the same way with the addition of an LED connected to pin 12 (GPIO1_28) of the Bone. Connect the ground pin of the LED to the Bone's ground (pin 1) using a 220Ω resistor.

Running both programs emulates the original function of the force resistor sample code, the only difference being that the data is now sent wirelessly from one Bone to another.

To easily run the programs, follow these steps (you can skip the first step if you have already clone the repository):

beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
beagle$ cd ECE497_XBEE
beagle$ cd ForceResistor
beagle$ make

This will create 2 executables: sendResistor and receiveResistor. Run the programs by running:

beagle$ ./sendResistor

on the Bone connected to the XBee and the force sensitive resistor and

beagle$ ./receiveResistor

on the Bone connected to the XBee and the LED.

You will then be able to squeeze the force sensitive resistor and see the LED light up on the other BeagleBone. We've created a YouTube demo of this program in action.

Wireless 2-Axis Thumb Joystick

These instructions are for interfacing the 2-Axis Thumb Joystick with the XBee. This application could be useful in a wireless controller setting.

Required Items

BeagleBone Wiring Instructions

On your first BeagleBone, wire pins 36 and 38 to your two analog inputs. Wire the Beagle's 1.8V VCC output, pin 32, to the VCC input of the Joystick. Finally, wire the select GPIO signal to the GPIO_7 pin or pin 42.

Wire the XBee as shown in the table below:

XBee Bone, P9 header
GND Ground, port 1
3V 3.3V, port 3
TX RX, port 22
RX TX, port 21

The pinout and visual implementation are shown below.

Bone P9 pinout.jpg XBee and Adafruit Joystick.jpg

On the second BeagleBone, wire the XBee exactly as the first XBee (as described in the table above).

Don't hook up any other hardware to the second XBee as it will be acting as an information hub.

Usage Instructions

On both BeagleBones, clone this repository: https://github.com/duganje/ECE497_XBEE.git Use the following to run the joystick code (you can skip the first step if you have already cloned the repository):

beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
beagle$ cd ECE497_XBEE
beagle$ cd 2AxisJoystick
beagle$ make

This will create 2 executables: joystickSend and joystickReceive. Run the code by doing:

beagle$ ./joystickSend

on the Bone connected to the XBee and the joystick and:

beagle$ ./joystickReceive

on the Bone connected to just the XBee.

Magnetometer

These instructions are for interfacing the HMC5883L Magnetometer with the XBee.

Required Items

Hardware

The XBee radios should be connected to both Beagles as shown in the table below.

XBee Bone, P9 header
GND Ground, port 1
3V 3.3V, port 3
TX RX, port 22
RX TX, port 21

The Magnetometer should be connected to one BeagleBone as described in the hardware section of the Magnetometer page. Ground and Vcc on the Magnetometer should be connected to pins 1 and 3 respectively on header P9 of the bone. SCL and SDA on the Magnetometer should be connected to pins 19 and 20 on P9 to use I2C bus 3. Two 4.7kΩ resistors should also be connected between SCL and Vcc and between SDA and Vcc. Below is a picture of the Beagle connected to the Magnetometer and the XBee.

Picture of connections

Software

The goal is to have the two BeagleBones attached to XBee radios with the one connected to the Magnetometer taking data and transmitting this data to the other Bone which will print the measured data.

I started with the code to collect data from the Magnetometer and the code to send data using the XBee radios. Here are the links to these two programs:

The code for the magnetometer uses I2C to read the values for the X, Y and Z-Axes and print these values to the terminal. The XBee code contains helper functions to transmit data wirelessly. I have written two programs: one to collect and transmit the magnetometer data and the other to receive and display this data.

Sending

The code uses I2C code from EBC Exercise 12 I2C and helper functions from XBee.c.

The program uses:

i2cget(i2cbus, address, daddress);

to get the data from the magnetometer and

sendShortXbee(val);

to send these values to the receiving XBee.

Receiving

The receiving code uses:

receiveShortXbee();

to read the values for each axis.

Because we do not have a way to synchronize the two XBees, the receiving program must be started first to ensure the data is receive in the correct order.

In the Highlights section, there is a video demo of the complete program.

Running the Code

Use the following to run the magnetometer code (you can skip the first step if you have already clone the repository):

beagle$ git clone https://github.com/duganje/ECE497_XBEE.git
beagle$ cd ECE497_XBEE
beagle$ cd Magnetometer
beagle$ make

This will create 2 executables: receiveMag and sendMag. Run the code by doing:

beagle$ ./sendMag

on the Bone connected to the XBee and the magnetometer and:

beagle$ ./receiveMag

on the Bone connected to just the XBee.

General Usage

These instructions are a general how-to for using the XBee with any sensor.

After cloning our repository to your favorite location, include the necessary header file, XBee.h. In your main.c file or your program, first run:
initializeXbee();
which sets the pins we will need to communicate with the XBee using UART 2. Then in your main.c file, call:
sendIntXbee(yourInt);
with yourInt being any integer data you would like to transmit. On your 2nd BeagleBone, call:
receiveIntXbee();
which will return the integer which was sent through sendIntXbee(int yourInt) on the 1st board.

The send and receive functions can be easily modified to send any data type, as shown in XBee.c with the following functions:

sendShortXbee(short yourShort);
receiveShortXbee();

Highlights

Our project is able to send and receive wireless data for a whole range of possible implementations. We've created YouTube demos for the three sensor implementations we've described so far:

Force Sensitive Resistor YouTube Demo

2-Axis Thumb Joystick YouTube Demo

Magnetometer YouTube Demo

Theory of Operation

The main theory of operation is based on Linux's use of files. UART files on the Bone represent serial connections. With an XBee connected to the Bone's UART 2 as shown above, sent and received messages are written to /dev/ttyO2 (the O is an uppercase O, not a zero). The BeagleBone's UARTs are accessed through /dev/ttyOx, where x is the UART number. Our code uses this and reads the file to receive a message and writes to the file to send a message. Any XBee's on the same network wil receive the message and we can do anything we want with it.

Work Breakdown

Milestones

  • Monday, 10/29 - XBee hardware received. (done)
  • Thursday, 11/1 - XBee Bones are connected and commands can be sent. (done)
  • Monday, 11/5 - Initial sensor implementation. (done)
  • Thursday, 11/8 - Package language implemented between Bones. (done)
  • Sunday, 11/11 - YouTube demo uploaded. (done)
  • Monday, 11/12 - All documentation complete. (done)
  • Tuesday, 11/13 - Everything complete & all code makes. (done)

Completed Work

  • Soldering XBee's - Matt Moravec
  • Initial communication methods - Stephen Shinn
  • Expanded communication methods - Josh Dugan
  • Initialization method - Josh Dugan
  • Force Sensitive Resistor implementation and demo - Stephen Shinn
  • Magnetometer implementation and demo - Josh Dugan
  • 2-Axis Thumb Joystick implementation and demo - Matt Moravec

Future Work

The following are some additional things that could be done with this project:

  • Create and document interfaces for more sensors
  • Back-and-forth 2-sensor communication
  • Create a practical application such as a wireless doorbell

Conclusions

In conclusion, we created an XBee wireless communication library for BeagleBone and adapted three sensors to use it. We've also documented general usage instructions for adapting XBee to use any type of sensor. We have not found a comprehensive source for how to use XBee modules with the BeagleBone, so our code and instructions are online with the intention that others use them as a reference.

We were unable to get a working program with 2-way communication with 2 XBees each sending and receiving data because of synchronization problems. Addressing this would require the development of a communication protocol to prevent deadlocks and to ensure the receiving program knows what the data is when it receives it. This would be a logical next step in terms of future work for this project.

Using the wireless modules is interesting, and there is a number of things you can do with them. We've listed a few ideas above which could be done in the future. One interesting idea would be to create a practical XBee application that someone could actually use in their home or work life. With a few XBees around the house, one could have a small network for sending data and using a sensor to control Christmas lights or something.




thumb‎ Embedded Linux Class by Mark A. Yoder