New easier xBee for Mac Lion (OS X 10.7) with Arduino

Well, I have finally got around to posting the new tutorial for xBee’s on a ALMIGHTY mac. This was tested on my mac running OS X 10.7 (Lion), with Arduino 1.0, Processing 1.5.1, and CoolTerm 1.4.1, and an Arduino duemilanove with a ATMEGA328P

So I have found an easier way to program up your xBee’s without having to use Windows (X-CTU) to set up the settings on the xBee modules, or use screen which is a terminal program for mac that has no GUI and has weird key combinations. It is a free program called CoolTerm. Now if you want to compare the two. CoolTerm like riding a bike, where screen is like riding a bike blindfolded down an EPIC hill with no brakes.

Now into the Tutorial.

You will need the following

  1. Mac computer
  2. CoolTerm installed (Click to download CoolTerm)
  3. Arduino Software installed
  4. An Arduino any type that you can connect a xBee to
  5. A xBee Shield to go with your Arduino
  6. 2 xBee’s modules
  7. xBee explorer usb interface
xBee Explorer

xBee Explorer

xBee Shield

xBee Shield

First thing we need to do is set up both the xBee modules so that they will talk to each other.

  1. Plug in a xBee module into the xBee explorer and hook it up to your mac via USB.
  2. Open up CoolTerm then hit the ‘Options’ button on the toolbar.
  3. Select the correct port for your xBee explorer will be something like ‘usbserial-XXXXXXXX’ (mine is usbserial-A600dJm8 each is different)
  4. If your device didn’t come up disconnect it, plug it back in and click ‘Re-Scan Serial Ports’.
  5. Hit the ‘Ok’ button as the rest of the setting set at default will work just fine.
  6. Hit the ‘Connect’ button on the toolbar and BOOM you’re talking to your xBee
  7. Ok now here is where we are going to change-up the settings on the xBee, if you pause for to long the xBee will exit configuartion mode, and you will have to do the next step again, so if it’s not doing what you want to try step ’8′ again
  8. Type ‘+++’ and Don’t press enter just wait and your xBee will reply with ‘OK’ that means its ready to take AT commands
  9. Now we need to change a few things to get them talking, After each command you should recieve ‘OK’ you will not see what you type.
  10. ATID (The PAN ID) lets change this to 2171 ‘ATID2171′ ENTER
  11. ATMY (The xBees address) lets change this to 1 ‘ATMY1′ ENTER, now when we set up the other xBee module this will have to be equal to this modules ATDL
  12. ATDL (The Destination) lets change this to 0 ‘ATDL0′ ENTER, now when we set up the other xBee module this will have to be equal to this modules ATMY
  13. The above to settings will have to be swapped for the next module so 0 talks to 1 and 1 talks to 0
  14. ATBD (The Baud rate) This is set to 3 by default which is 9600 and we will leave it at that.
  15. ATWR will write all the settings we just changed to the module ‘ATWR’ ENTER, if you omit this step when you unplug power to the module it will go back to the last stored settings
  16. Now we are finished for that module hit the ‘Disconnect’ button on the toolbar.
  17. Unplug the usb and change the xBee module over, you can place the xBee module we just finished with in the xBee shield as it is ready to go.
  18. Plug in the usb
  19. Program up this one just the same as the other module, remembering to change the ATMY to 0 and the ATDL to 1
Note the above settings can be changed to values of your choosing, I just liked those values at the time

That is both modules ready to rock and roll, you can leave the second module in the xBee explorer as we will be using it as it is.

Now that the modules are set up if you where to set up an Arduino sketch that has serial output in it, the serial output will go over the air to you xBee explorer module, and into your computer. Below is a basic sketch which will send an int value over the air to your computer and increment every half second. Also if the sketch wont upload check your xBee shield there is a little switch it needs to be set to DLine to upload the code and set to UART to send the serial text to the xBee

To view this happening, using CoolTerm connect to your xBee explorer as you did is steps 3 through 6. The output in CoolTerm should be counting up. If you have any problems add a comment down the bottom and I will see if I can help. It works for me now the code is a bit flaud as if you leave it going for long enough it will do some funny stuff as the int will run out of space when it passes 32676 it will start from -32768.

CoolTerm after the Arduino Sketch was running for a while

That is all I am going to do for now, I have a project set up which will do more. It will also be more useful than counting wirelessly, but that will come tomorrow.

 

Have fun and post and questions in the comments sections and I will see if I can help you out.

 

‘HughesY’

Category(s): Arduino, Mac, xBee

46 Responses to New easier xBee for Mac Lion (OS X 10.7) with Arduino

  1. Ask questions here, or give me some feedback so I can improve!

      Ricardo Barrera says:

      Thank you for your tutorial. I was having difficulty and did not know if the problem was with my Xbee’s or where? Your test and suggestions worked fine and I get the counter. But I am still stymied. I can get my arduino (a clone built into the robotshop rover xbee) to send data to my computer via a usb xbee thingamabob. But when I try to send something to arduino that should be sent back nada! Can anyone help?

      Obviously the IF statement is never executing or the LED would at least flash. What I can’t determine is why? This test “if(Serial.available() > 0); ” has been used by others. So at this point I have no way of knowing if the Xbee’s are communicating both ways.

      int i = 0;
      int k = 0;
      // Pin 13 has an LED connected on most Arduino boards.
      // give it a name:
      int led = 13;
      //int incomingByte = 0; // for incoming serial data
      char incomingByte;

      void setup()
      {
      Serial.begin(9600);

      // initialize the digital pin as an output.
      pinMode(led, OUTPUT);
      }

      void loop()
      {
      if (k == 0) {

      delay(100);
      Serial.println(“Hello World”Smilie: ;); // Just to show that the arduino/xbee are working
      delay(300);
      k = 1; // I set k to 1 so it won’t keep printing “Hello World”
      }

      delay(10);

      // send data only when you receive data:
      if (Serial.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial.read();
      delay(10);

      // flash LED for debugging purposes – Did I enter if statement?
      digitalWrite(led, HIGH);
      delay(300);
      digitalWrite(led, LOW);

      // say what you got:
      Serial.print(“I received: “Smilie: ;);
      //Serial.println(incomingByte, DEC);
      Serial.println(char(incomingByte));
      }
      }

  2. Great tutorial. Coolterm is SO much better than Terminal. It’s good to turn local echo on, that allows you to see your keystrokes. I have a problem – one of my Xbees returns an error message when I send ATMY1 (or any digit). ATDL and ATID work fine… any thoughts? Just a bad module?

  3. When I used a series 2 Xbee, I also received error messages for ATMY1. Ashley, were you using Series 1 or 2? Thanks!

  4. Hi, I came across your blog as I was in the process of setting up a pair of Xbees to work on an Arduino Fio and a sparkfun USB explorer. I suggest you take a peek at: MoltoSenso (http://www.moltosenso.com/client/fe/browser.php?pc=/client/fe/download.php) a free mac app developed by an italian company that offers the same functionality as X-CTU.

    Cheers,
    -Edgar

  5. I have used your tutorial precisely , however,
    the xbee shield has Power LED: ON , DIO5 LED = blinking , DIN LED Blinking but not receiving anything
    the ATMY and ATDL has same value switched in each, exactly same kit as urs, same ID and BD ,
    Still not receiving any idea?

    Oscar De Alba says:

    When I go to the ports I only have bluetooth-modem and bluetooth PDA-sync any idea on what should I do?

  6. Great tutorial, got my xbee modules working instantly. I have a question: How would i incorporate this into an Arduino sketch here is my current code i am working with (i would like to make the joystick wireless)
    /**
    * PanTiltControl
    *
    * Uses an analog joystick to control a servo pan/tilt mount. The prototype
    * used a joystick from Sparkfun and a pan/tilt assembly from Seeed Studio.
    * One axis of the joystick controls the pan, the other controls the tilt.
    */

    #include

    Servo horzServo; // Create a servo object for the pan (horizontal) servo
    Servo vertServo; // Create a servo object for the tilt (vertical) servo

    int horzPin = 0; // Analog input for the joystick horizontal axis
    int vertPin = 1; // Analog input for the joystick vertical axis
    int vertVal; // Value read from the vertical axis
    int horzVal; // Value read from the horizontal axis

    /**
    * Setup
    */
    void setup()
    {
    horzServo.attach(Smilie: 8); // Use pin 9 PWM output for horizontal servo
    vertServo.attach(9); // Use pin 10 PWM output for vertical servo
    }

    /**
    * Main program loop
    */
    void loop()
    {
    horzVal = analogRead(horzPin); // Read joystick horizontal position
    horzVal = map(horzVal, 0, 1023, 0, 179); // Scale reading to suit servo
    horzServo.write(horzVal); // Move servo to required position

    vertVal = analogRead(vertPin); // Read joystick vertical position
    vertVal = map(vertVal, 0, 1023, 0, 179); // Scale reading to suit servo
    vertServo.write(vertVal); // Move servo to required position

    delay(15); // Give the servos time to settle
    }

    • It depends, if you want your servos wireless to your joystick

      I would (never worked with servos before) have this in the servo loop
      //READ SERIAL INPUT HERE to horzVal // Read joystick horizontal position
      horzVal = map(horzVal, 0, 1023, 0, 179); // Scale reading to suit servo
      horzServo.write(horzVal); // Move servo to required position

      //READ SERIAL INPUT HERE to vertVal // Read joystick vertical position
      vertVal = map(vertVal, 0, 1023, 0, 179); // Scale reading to suit servo
      vertServo.write(vertVal); // Move servo to required position

      And on the joystick end send via

      Serial.write(analogRead(horzPin));
      Serial.write(analogRead(vertPin));

      The trick will be getting the joystick to always send the same amount of characters each time that way when you read on the servo side you get all the info for each axis
      Analog read gives a max 0 – 1023 doesn’t it? So every time send 4 characters over serial ie 0089 so you read 4 character to each axis every time

      That is how I dealt with sending information for a while controller for a RGB LED system, I always sent RRRGGGBBB so it waited for 9 character to come then read the first 3 into Red next into Green etc.

      • thank you for your reply; Yes plan was to have the joystick wireless, my xbee modules communicate well, i have had them sending basic serial data so i know they talk to each other……… my problem is i will have to upload two different sketches to two different Arduino’s? I have found a link to a similar project but instead it is the wireless tracked rover,

        http://www.instructables.com/id/DFRobotShop-Rover-wXbee/#step1

        I am going to try this tomorrow when i get my 4wd bot tomorrow, but as for the servos i am still stuck, i am pretty new to Arduino, i compile my codes by taking from here and there and joining pieces together that are relevant etc but i still fail to see the structure in its whole(at the moment, i learn each day), any further assistance would be greatly appreciated, a possible re code? im not sure where to begin to add the pieces you gave me, as i think i need to separate sketches one for an Arduino with the Joystick shield and the Xbee, and one fo an Arduino with the two servos and the second Xbee operating on 9600baud

        again thank you for your assistance

        • Yes you will need two arduinos running different code both with a xbee
          As far as the code its up to you how you write it I would step through how you want your code to run and write it down in plain English before writing any code.

          Think about what your gonna send serialy only the axis that changed? Ie v045 for vert to 45th servo position or for ease send both axis even if only one changed.. I would try to code it your self rather than coping others code you will learn so much more

  7. Hi again, I am leaving the servo control alone for a bit, until i get my Servo shield from sparkfun. I have a query now though, i have followed these steps to get my Xbee modules communicating and they do, but now when i type +++ when one Xbee is connected i get no response, i am puzzled….

    Regards,

  8. Hi, thanks for sharing this. Can one have two transmitters and one receiver? And if so, how do you set this up?

  9. Well, another question. I’m trying to use CoolTerm to set up my xbee, but it just can’t see the port. When I plug in my arduino, it sees it, but not the xbee. I’m using a series 1 chip antenna xbee. Any idea?

  10. Awesome tutorial – greatly appreciated. Thanks for putting forth the effort to help the rest of us – you rock.

    jordan kreidberg says:

    I am trying to use your protocol with Cool Term for connecting Xbee to a Macbook Pro running OSX 10.6.8. I got as far as step When I try to connect, I get a USB option , but not “USB serial…..”. If I type +++ I get an OK. Thereafter, I do not get “OK” for any further commands, that suggests that I may not be finding the Xbee to begin with.

    I have the Xbee connected to an Xbee adaptor from Robotshop, that is connected by USB to the Macbook Pro.
    http://www.robotshop.com/productinfo.aspx?pc=RB-Dfr-148%20

    Is this not a suitable adaptor? I would be grateful for any advice.

    thanks very much
    Jordan

    • If you are using arduino software 1+ you don’t get the drivers and more I don’t think download arduino software version 23 install the ftdi drivers that come in the image and that should allow your computer to see the xbee device

      • Even with the driver installed, I have a similar problem to Jordan’s. When I type +++ I get no response at all.
        Do you know what might be the problem ?

        I also discovered that you need to turn ‘local echo” ON in the termimal section in Cool term’s options if you want to see what you type.

        OSx 10.6.8
        Arduino 1.0.1
        Xbee series1
        Xbee explorer USB by sparkfun

  11. Hello, great tutorial, thanks!

    However, I did exactly everything that was described, I used the same ATMY and ATDL, but nothing appears on Coolterm.

    It might be the Xbees that don’t function well, or the shield between the arduino and the Xbee. How do I know if the Arduino+Shield+Xbee are correctly set up? All that I can see is a red led blinking.

    Thanks a lot!

  12. I’m more than happy to discover this website. I need to to thank you for ones time for this particularly wonderful read!! I definitely loved every part of it and i also have you book-marked to see new information on your blog. I wanted to share with you that, I bookmarked New easier xBee for Mac Lion (OS X 10.7) with Arduino | Ashley Hughes Arduino at Pinterest so my coworkers can read it as well. Could I also reveal a tip. Acquiring brilliant video marketing can be highly tricky. I find it most beneficial to speak with a a San Diego Probate Attorneys. Our staff of San Diego Bankruptcy Attorney are right here to assist with all your legal necessities.

  13. Great tutorial. This helped me big time. Thanks alot!

  14. If you are still having problems figuring this out, here is a great video that explains it all. Do lessons 1 and 2. Granted, in the video he uses X-CTU, but now that you know how to use the commands and coolterm as taught above, just combine the two tutorials:

  15. Hello my friend! I want to say that this article is awesome, great
    written and come with almost all important infos. I’d like to peer more posts like this .

  16. Hello there, There’s no doubt that your website could be having browser compatibility issues. When I take a look at your blog in Safari, it looks fine however, when opening in I.E., it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, great site!

    • As for IE it has major issues with any type of site that uses CSS2 & HTML 5 and I will no modify this site to suit it as its behind the times and well is a terrible browser.

  17. This post will assist the internet visitors for building up new blog or even a blog
    from start to end.

  18. Hi everyone!
    Premising despite your valuable advice I never had succes using the AT mode to setup my modules, I’m looking for help to get out of troubles due to my lack of experience.
    My goal is to turn on and off some leds, driving them via switches and bluetooth connection.
    I use two Bluetooth Bee Standalone by Seeedstudio and two Grove Xbee carriers.
    At the moment (after setting up basic parameters via “\r\n+” command in a sketch) I can drive my system with the following sketch for the master bee:

    // SENDER ******************************************************

    #include //Software Serial Port
    #define RxD 2 // these ’2′ & ’3′ are fixed by the hardware
    #define TxD 3

    SoftwareSerial blueToothSerial(RxD,TxD);
    const int buttonPin1 = 5;
    const int buttonPin2 = 6;

    int buttonState1 = 0;
    int buttonState2 = 0;

    char s1;
    char s2;

    // setup *******************************************************

    void setup()
    {
    Serial.begin(19200);
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);

    pinMode(buttonPin1, INPUT);
    pinMode(buttonPin2, INPUT);

    setupBlueToothConnection();
    }

    // connection **************************************************

    void setupBlueToothConnection()
    {
    blueToothSerial.begin(38400);
    delay(1000);
    blueToothSerial.print(“\r\n+CONN=0,13,EF,0,8,F9\r\n”Smilie: ;);
    }

    // logic *******************************************************

    void loop()
    {
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);

    if (buttonState1 == HIGH) {
    s1=(‘a’Smilie: ;);
    }

    else {
    s1=(‘b’Smilie: ;);
    }

    if (buttonState2 == HIGH) {
    s2=(‘c’Smilie: ;);
    }

    else {
    s2=(‘d’Smilie: ;);
    }

    // data ********************************************************

    blueToothSerial.write(s1);
    delay(10);
    blueToothSerial.write(s2);
    delay(10);
    }

    and the slave bee:

    // RECEIVER ****************************************************

    #include //Software Serial Port
    #define RxD 2 // these ’2′ & ’3′ are fixed by the hardware
    #define TxD 3

    SoftwareSerial blueToothSerial(RxD,TxD);
    int led1 = 5;
    int led2 = 6;

    // setup *******************************************************

    void setup()
    {
    Serial.begin(19200);
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
    pinMode(led1,OUTPUT);
    pinMode(led2,OUTPUT);
    setupBlueToothConnection();
    }

    // connection **************************************************

    void setupBlueToothConnection()
    {
    blueToothSerial.begin(38400);
    delay(1000);
    blueToothSerial.print(“\r\n+CONN=0,13,EF,0,A,B7\r\n”Smilie: ;);
    }

    // logic *******************************************************

    void loop()
    {
    char blueToothData = (char)blueToothSerial.read();

    if (blueToothData == ‘a’Smilie: ;) {
    digitalWrite(led1, HIGH);
    }

    if (blueToothData == ‘b’Smilie: ;) {
    digitalWrite(led1, LOW);
    }

    if (blueToothData == ‘c’Smilie: ;) {
    digitalWrite(led2, HIGH);
    }

    if (blueToothData == ‘d’Smilie: ;) {
    digitalWrite(led2, LOW);
    }
    }

    I know, it’s quite rough, but it works…
    Indeed, everything works fine except the fact I have to program the master without these lines:

    // data ********************************************************

    blueToothSerial.write(s1);
    delay(10);
    blueToothSerial.write(s2);
    delay(10);

    After resetting, so the modules go pairing fine, I finally upload the complete sketch with the lines above.
    This procedure is needed every time I turn off any of the Xbee carriers.

    Any idea to solve this problem or any suggestion to improve the sketch or the entire system?
    Thanks in advance Smilie: ;)

  19. Fantastic instructions; the best I found on the Internet; helped me get my XBEEs up and running, many thanks!

  20. Excellent blog you have here.. It’s difficult to find good quality writing like yours these days.
    I really appreciate individuals like you! Take care!!

  21. Hello
    and thanks so much for your page , i think its one of the only talking about this config with osx that isnt a complete disaster..
    so thanks

    i seem to be getting a similar problem to jordan ” ”

    i get the initial ok

    but nothing with any of the commands after other than the flashing tx led on the explorer with every keystroke.

    im trying to config 2 xbee pro s2B to use with an explorer , fio and firmata , a system i have had working flawlessly in the past with s1 xbee’s but just wanted to use the pro s2b to get a better range.

    any ideas suggestions would be greatly appreciated.

    thanks again

    Josh

  22. this is the quote that was missing

    “I am trying to use your protocol with Cool Term for connecting Xbee to a Macbook Pro running OSX 10.6.8. I got as far as step When I try to connect, I get a USB option , but not “USB serial…..”. If I type +++ I get an OK”

    i do get the serial connection though , cool term is defiantly connecting

    just no OK after any of the commands other than +++

  23. THANK YOU so much! Works perfect!

  24. Hmm is anyone else experiencing problems with the pictures on this blog loading?
    I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

    Here is my web-site :: Free Mac Pro

  25. Hi I’m new to all this a compete novice,

    I have followed the tutorial but can only get to step 6 it says connected but when i type I’m not getting any response message from the bluetooth xbee.

    Please help

    Ryan

4 Responses in other blogs/articles

  1. [...] ITP Xbee Basic Page Artist Collective working extensively with Xbees (Has good references overall) ashleyhughesarduino Site (Very good explanation on CoolTerm [...]

  2. [...] and version. Second, we have to program them so that they listen to each other. I found a pretty nice blog that will help you setting up the two xBee modules (if you are working on a mac) via a tool called [...]

  3. [...] And for the Xbees: http://www.hughesy.net/wp/arduino/new-easier-xbee-for-mac-lion-os-x-10-7-with-arduino/ [...]

Leave a Reply

Your email address will not be published. Required fields are marked *


6 + seven =

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">