Pages: [1]   Go Down
Author Topic: Connecting LilyPad Arduino to LilyPad Xbee  (Read 3541 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! I'm trying to have two circuits, each one with a LilyPad Arduino connected to a LilyPad Xbee, in order to have a wireless connection between the two circuits.

I'm powering the LilyPad Arduino and connecting the TX, RX, + and - pins between the LilyPad Arduino and the LilyPad Xbee. Both circuits are working well, but there aren't wireless communication. Anyone knows what I may be doing wrong?


Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did you program the xbee's correctly?
did you program the arduino correctly?

could we see the arduino code, and the xbee configuration?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First I had this code working using Arduino and Xbee Shield with Xbee, know I'm trying to make the code work with LilyPad Arduino and LilyPad Xbee, but I don't know if I need to do anything that I haven't done.

I'm working in Arduino 11 because de FrequencyTimer library doesn't work with recent versions of Arduino.

One Arduino has this code:

#include <FrequencyTimer2.h>

#define A { \
    { 1, 1, 1, 1},  \
    { 1, 1, 1, 1}, \
    { 1, 1, 1, 1}, \
    { 1, 1, 1, 1},  \
    }

#define B { \
    { 0, 0, 0, 0},  \
    { 0, 0, 0, 0}, \
    { 0, 0, 0, 0}, \
    { 0, 0, 0, 0},  \
}

#define C  { \
    { 1, 0, 0, 0},  \
    { 0, 1, 0, 0}, \
    { 0, 0, 1, 0}, \
    { 0, 0, 0, 1},  \
}

#define D { \
    { 1, 0, 0, 1},  \
    { 0, 1, 1, 0}, \
    { 0, 1, 1, 0}, \
    {1, 0, 0, 1},  \
}

#define E { \
    { 0, 0, 1, 0},  \
    { 0, 1, 0, 0}, \
    { 0, 1, 0, 0}, \
    { 0, 0, 1, 0},  \
}



byte col = 0;
byte leds[4][4];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[9]= {-1, 3, 4, 6, 7, 11, 12, 8, 9};

// col[xx] of leds = pin yy on led matrix
int cols[4] = {pins[5], pins[6], pins[7], pins[8]};

// row[xx] of leds = pin yy on led matrix
int rows[4] = {pins[4], pins[3], pins[2], pins[1]};



byte propria[3][4][4]={
  A,C,B
};

byte anima72[3][4][4]={
  D,E,B
};

int pattern = 0;
int frame = 0;


//

int incomingByte = 0; // vari‡vel para a serial data

int contador=0;

int relo=0;

void setup()
{
  Serial.begin(9600);
  
 for (int i = 1; i <= 8; i++) {
    pinMode(pins, OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 4; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 4; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

}


void loop()
{
   //LIGA‚ÌO
  if (Serial.available() > 0) { //caso exista info "em linha de espera" ler
    incomingByte = Serial.read();
    delay(100);
    Serial.print ('L');
    Serial.flush();
  }

 else{
  Serial.print ('L');//modo dormente
  }

  //AC‚ÌO

  if (incomingByte == 72 && contador<4){
  
     Serial.print ('L');
    setPattern(anima72[frame]);
    frame++;
    
    if(frame >= 3){
      frame=0;
      contador++;
    }

  }
  else{
     setPattern(propria[frame]);
    
    frame++;
    
    if(frame >= 3){
      frame=0;
    }
    
    relo++;
    if (relo>10){
      relo=0;
      contador=0;
    }
    
  }
  delay(2000);
}


//

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      leds[j] = 0;
    }
  }
}

void setPattern(byte p[4][4]) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      leds[j] = p[j];
    }
  }
}


// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 4) {
    col = 0;
  }
  for (int row = 0; row < 4; row++) {
    if (leds[col][3 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
  delayMicroseconds(900);  // Delay so that on times are longer than off time = brighter leds
}

And the other has this code:

#include <FrequencyTimer2.h>

#define A { \
    { 1, 1, 1, 1},  \
    { 1, 1, 1, 1}, \
    { 1, 1, 1, 1}, \
    { 1, 1, 1, 1},  \
    }

#define B { \
    { 0, 0, 0, 0},  \
    { 0, 0, 0, 0}, \
    { 0, 0, 0, 0}, \
    { 0, 0, 0, 0},  \
}

#define C  { \
    { 1, 0, 0, 0},  \
    { 0, 1, 0, 0}, \
    { 0, 0, 1, 0}, \
    { 0, 0, 0, 1},  \
}

#define D { \
    { 1, 0, 0, 1},  \
    { 0, 1, 1, 0}, \
    { 0, 1, 1, 0}, \
    {1, 0, 0, 1},  \
}

#define E { \
    { 0, 0, 1, 0},  \
    { 0, 1, 0, 0}, \
    { 0, 1, 0, 0}, \
    { 0, 0, 1, 0},  \
}

byte col = 0;
byte leds[4][4];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[9]= {-1, 11, 3, 6, 8, 9, 7, 4, 12};

// col[xx] of leds = pin yy on led matrix
int cols[4] = {pins[8], pins[7], pins[6], pins[5]};

// row[xx] of leds = pin yy on led matrix
int rows[4] = {pins[4], pins[3], pins[2], pins[1]};



byte propria[3][4][4]={
  D,E,B
};

byte anima76[3][4][4]={
  A,C,B
};

int pattern = 0;
int frame = 0;


//

int incomingByte = 0; // vari‡vel para a serial data

int contador=0;

int relo=0;

void setup()
{
  Serial.begin(9600);
  
 for (int i = 1; i <= 8; i++) {
    pinMode(pins, OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 4; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 4; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);
}


void loop()
{
    //LIGA‚ÌO
  if (Serial.available() > 0) { //caso exista info "em linha de espera" ler
    incomingByte = Serial.read();
    delay(100);
    Serial.print ('H');
    Serial.flush();
  }

 else{
  Serial.print ('H');//modo dormente
  }

  //AC‚ÌO

  if (incomingByte == 76 && contador<4){
  
     Serial.print ('H');
    setPattern(anima76[frame]);
    frame++;
    
    if(frame >= 3){
      frame=0;
      contador++;
    }

  }
  else{
     setPattern(propria[frame]);
    
    frame++;
    
    if(frame >= 3){
      frame=0;
    }
    
    relo++;
    if (relo>5){
      relo=0;
      contador=0;
    }
    
  }
  delay(2000);
}


//

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      leds[j] = 0;
    }
  }
}

void setPattern(byte p[4][4]) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      leds[j] = p[j];
    }
  }
}


// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 4) {
    col = 0;
  }
  for (int row = 0; row < 4; row++) {
    if (leds[col][3 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
  delayMicroseconds(900);  // Delay so that on times are longer than off time = brighter leds
}

The objective is that the two LED matrix have different animations and when they are near each other, the animations exchange from one matrix to the other.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The project is now working  smiley
It had a stupid mistake, I thought that the RX on the LilyPad Arduino should connect to the RX on the LilyPad Xbee and the TX to the TX, but that's not true, the RX connects to TX and the TX to the RX.

Thanks to everyone that have tried to help anyway.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you worked it out! Here's a collection of Common XBee Mistakes that I created to provide a checklist of possible fixes for radio unhappiness: http://www.faludi.com/projects/common-xbee-mistakes/

By the way, while generally you'll hook up TX to RX and vice versa, there are certain devices out there that label their pins differently, like the GM862, so always check the data sheet, or simply try swapping the connections if you're not sure.

--Rob
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. By the way, I've found the solution to my problem precisely on your list.
Logged

Toronto, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 92
plants and animals
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anyone know of any solid tutorials on working with the Lilypad Xbee?  I'm trying to get a project up and running, and I'm not sure if I'm doing things correctly.  I have some questions, perhaps someone could answer them?

In this project there is a performer who will be wearing the Lilypad.  There will be 6 buttons, each corresponding to a different video effect/treatment to a video running in Processing.  So, couple questions:

1) The Lilypad Arduino and the Lilypad Xbee board will be essentially next to each other in the costume.  I'll connect the buttons to pins on the LParduino, and then are the only connections between the two boards rx, tx, power and ground?  Are there any connections I am overlooking?

2) the Lilypad Xbee will communicate with an Arduino Duemilanove with Xbee shield connected to the computer.  This is where it receives the instances of button presses, and tells Processing what to do.  Does this Xbee need to be connected to an Arduino or can it be connected via Sparkfun's USB Explorer breakout board?  As I'm writing this, I'm thinking that's a bit of a silly question, since I need to be able to tell the Xbee what to do...  except that I'm thinking this Xbee should still be able to receive the data and send it via USB to the Arduino program that is running.  Is that correct?

I hope I'm clear with my questions!
Thanks in advance!

Logged

New Media, E-textiles, Wearable Technology:  www.erinlewis.ca

Twitter: @luxxnatura


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
are the only connections between the two boards rx, tx, power and ground?  Are there any connections I am overlooking?
Those are the only connections needed.

Quote
This is where it receives the instances of button presses
It receives whatever the Lilypad sent when a button was pressed. Pressing a button and sending data are not coupled on the Lilypad unless your code couples them.

Quote
Does this Xbee need to be connected to an Arduino or can it be connected via Sparkfun's USB Explorer breakout board?
The Explorer breakout board is sufficient. The XBee is receiving messages over the air and converting them to serial data, or receiving data from the serial port and broadcasting it. There is no processing, and, therefore no Arduino required.
Logged

Toronto, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 92
plants and animals
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect!
Thanks Paul!
Logged

New Media, E-textiles, Wearable Technology:  www.erinlewis.ca

Twitter: @luxxnatura


0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Hello!

I was hoping someone might be able to shed some light on a project I am working on.  The basic idea is this;
1) there is one performer, wearing a few sensors (flex, pressure, gyro, accel)
2) there are lilPad products involved (lpXbee, lpArduino)
3) the idea is that data received from the sensors will control/generate musical parameters within a software system.

I got the how to get data to the software....
but not how to get data to the point where the software can see/read it (UDP, OSC)

So, what I am wondering is....
1) Is 1 xBee enough?
(data from sensors on performer, sent wireless to computer nearby)
( as the one that sends? or do you need one that sends and one that receives?)

2) Is there a solid basic starter code (like blinking an LED) that I can use as a tester to configure my lpXbee?

3) correct order?
lilyPad liPower (3.5V) to lpArduino to lpXbee?
or power to xB then arduino?  

-the person above mentioned that she was working with a lpXbee *next to* a regular lilyPad..... is that necessary?
(reply later.... i see that the lpXB is a shield... not an arduino)

More info:
I also have the standard decimilinove and the nano.

I also have the liPower with the lp, and the lp arduino (and the xb w lp)

Thanks for the assistance in advance :smiley
`jenifer

« Last Edit: January 18, 2011, 10:41:39 am by jenifer » Logged

Toronto, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 92
plants and animals
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Jennifer,
I can answer a few of your questions, but not so much on the software side (you would have to elaborate on this).

1) you will need two Xbee radios, one which is connected to your computer via FTDI breakout board (one of these: http://www.sparkfun.com/products/9716) and a second which is used on the Lilypad Xbee board.  The one on the LP Xbee board transmits the data wirelessly to your computer.

2) You have to configure the Xbees before you can use them.  You have to set it so that one listens to the other.  A decent tutorial (including starter code) can be found here: http://www.ladyada.net/make/xbee/arduino.html

3) I apply power to the Xbee because it has a voltage regulator which outputs 3.3V, which I then use to power the Lilypad and any sensors.

I hope this helps some!
Logged

New Media, E-textiles, Wearable Technology:  www.erinlewis.ca

Twitter: @luxxnatura


0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for such clear answers.
I have a few follow-ups.

So, if I understand correctly:
the lilyPad arduino is connected to the FTDI which is connected to the computer via a USB a-to-b cable
AND
the XBee is on a separate lilyPad (being the lilyPad breakout board)

I am trying to go wireless (hence the XBee) so i am a bit confused on if the USB to computer connection is just for uploading the data, or if it always remain that way.  Ultimately I will be sewing the circuits and wearing them.....

A little context:
I am building a pair of gloves that I want to wear to perform.
I would like to have a wireless connection to my computer via the XBee
I am thinking I should strap on both of the lilyPadboards (the arduino and the xbee)... true?  

Thanks again for your effort   smiley-wink
`j
Logged

Toronto, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 92
plants and animals
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Lilypad Arduino is not connected to the computer, it will be part of your wearable setup.  I just realized that I posted the wrong Sparkfun link in my previous message (re: FTDI breakout board).  The only time you need the breakout board is when you are uploading code to your Lilypad Arduino.  When you are done, you disconnect it.

What you want is the Xbee Explorer: http://www.sparkfun.com/products/8687 . It is on this device that you will put one of your Xbee radios, and it will stay connected to your computer during your performance.  

So, you basically have two setups: one stationary (Xbee Explorer w/Xbee radio + computer) and the other wearable (Lilypad Arduino + Lilypad Xbee w/ Xbee radio + sensors/actuators + batteries).
Logged

New Media, E-textiles, Wearable Technology:  www.erinlewis.ca

Twitter: @luxxnatura


Pages: [1]   Go Up
Jump to: