In this activity, you create a simple drawing game.Two wireless nodes communicate to a Processing application on your computer and cooperate with each other, allowing you to draw pictures.
If you get stuck, go to the Troubleshooting links at the end of the example.
2. Add the XBees to XCTU
Ensure that the XBee is seated firmly in the XBee USB adapter.
Plug the XBee USB adapter into your computer using the mini-USB cable provided.
Make sure you are in Configuration working mode.
Click Discover radio modules from the toolbar.
In the Discover radio devices dialog, select the serial port(s) in which you want to look for radio modules. If you do not know the serial ports where your modules are attached, select all ports. Click Next.
In the Set port parameters window, maintain the default values and click Finish.
As XCTU locates radio modules, they appear in the Discovering radio modules… dialog box. Once the discovery process has finished, click Add selected devices.
- At this point, you should see something like this in the Radio Modules section on the left:
The port number and MAC address do not necessarily have to be equal as shown in the picture.
3. Configure the XBees
One XBee will be connected to the computer, the other two will control the game.
Restore the default settings of all XBees with the Load default firmware settingsbutton at the top of the Radio Configuration section.
Use XCTU to configure the following parameters:
Param Computer XBee Remote XBee 1 Remote XBee 2 Effect CH C C C Defines the frequency to use to communicate. This must be the same for all radios on your network. ID 2015 2015 2015 Defines the network that a radio will attach to. This must be the same for all radios on your network. DH — 0 0 DH and DL combined form the destination address. This is where the notifications are sent when the button value changes. The address being configured here is known as a short address. A short address is assigned during configuration. An XBee also has a long address (SH and SL combined) which is assigned permanently when the unit is manufactured. DL — 1234 1234 MY 1234 1235 1236 Defines the XBee's short address. AP AP enabled  — — Enables API mode. D1 — ADC  ADC  Configures pin DIO1/AD1 as analog input in both remote XBees. This pin is connected to a potentiometer. IR — 64 64 Configures remote XBees to send IO samples every 100 ms (100 ms = 64 in hexadecimal).
— keep the default value.
Write the settings of all XBees with the Write radio settingsbutton at the top of the Radio Configuration section.
4. Connect the components
Create the following circuit with each of your XBee breadboard adapters.
Ensure that each wire is connected to the same column on the breadboard as the pin of the XBee breadboard adapter footprint. This will ensure that the signals to the XBee are correct.
Click to expand diagram
Push down firmly on each breadboard adapter board to ensure it is seated properly on the breadboard. Do not be afraid to use a little force.
- Insert the controller XBees into the XBee breadboard adapters. Push down firmly on each XBee to ensure it is seated properly on the breadboard adapter.
- Insert the final XBee into the XBee USB adapter.
Double check that the breadboard adapter and XBee are positioned in the correct location and oriented the same as the image below. Incorrect placement has the potential to result in damage to components.
Click to expand diagram
5. Put it all together
- Plug the XBee USB adapter into the computer where you will run the Processing application.
- Apply power using the 9V battery and battery clip.
- Download and extract the latest zip archive from the XBee/Arduino Compatible Coding Platform release page.
- Open the Processing application.
- From the File menu select Open.
- Browse to the
mechanical_sketching_toyfolder from the extracted archive, and select the
mechanical_sketching_toy.pdefile. Click Open.
Find the following section at the top of the file and modify it to include the XBee serial port and the 16-bit addresses you set on the remote XBees.How do I find the serial port of my module?
You can remove the XBee Grove Development Board from the USB port and see which port name disappears from your port list. The name that disappears is your XBee board.
Many people figure out which port is right via trial and error, but you can also use XCTU to find it:
- Open XCTU and discover the radio modules attached to your computer by clicking on the top-left corner.
- Select all ports to be scanned.
- Click Next and then Finish.
- Once the discovery process has finished, a new window notifies you how many devices have been found and their details. The serial port and the baud rate are shown in the Port label.
- Press Play to run the sketch.
6. Play the game
Turn the potentiometer on either board to move the "stylus" on screen.
- Click the computer's mouse to clear the screen.
7. Exercises for the reader
If you're ready to move beyond this exercise and extend the example, try the following:
- Instead of hard-coding which XBee controls the X-axis and which controls the Y-axis, randomly choose between the two.
- Modify the previous exercise so that more than two XBees can join the game; randomly pick two of those.
- When there are three or more XBees playing, at either a random or set interval, randomly choose again which two XBees control the stylus.
- When there are three or more XBees playing, give control of some gameplay element to those players who do not not control the stylus. For example, one player controls the "brush" size, another controls the color, and so forth.
If you are encountering problems, these suggestions may help:
For more information about the hardware and software you use in this activity, see: