Go Down

Topic: Using LilyPad Arduino USB with LilyPad Xbee Shield (Read 2349 times) previous topic - next topic

willielenk

Hi,

I am trying to use a LilyPad Arduino USB to send wireless data via Xbee. Basically I am trying to sample an analog voltage on the Arduino LilyPad USB, send that data wirelessly via Xbee to an Arduino Uno, and print that data to the Serial Monitor where the Arduino Uno is plugged in. I have the LilyPad Arduino USB, a LilyPad Xbee sheild, and an Xbee (S1) at my transmitting end. On my receiving end I have another Xbee (S1), an Arduino Uno + shield: (https://www.sparkfun.com/products/retired/9976)

I have successfully got this working using Software Serial with an Arduino Uno + Xbee Shield at the transmitting end, telling me I have correctly set up my Xbee network. But for my project, the compactness of the LilyPad boards is crucial at the transmitting end. When I swap the Uno / shield for the LilyPad/ LilyPad shield, nothing gets transmitted. Of course I am running the same code on both the Uno and the LilyPad USB. Here is my transmitting code:

Code: [Select]
#include<SoftwareSerial.h>
#define rxPin 2
#define txPin 3

SoftwareSerial myPort(rxPin, txPin);   //rx = 2, tx = 3

void setup() {
 
   myPort.begin(9600);
   Serial.begin(9600);
   pinMode (A2, INPUT);     //sample voltage at pin A2

}

void loop(){

  float voltage = 0;
  voltage = analogRead(A2);
  voltage = voltage * (5.00 / 1023.00);    //convert analog read to voltage value
 
  myPort.print(voltage);                   //print the value to software serial

  delay(1000);
     
}


I hooked up pin 2 on the LilyPad USB (acting as the RX pin) to the TX pin on the LilyPad Xbee shield, and pin 3 on the LilyPad USB to the RX pin on the Xbee shield. Of course when this didn't work I tried switching these because the convention is confusing, but that didn't work either. On the receiving end, I am using the Uno Xbee Shield in D-line mode and reading from the software serial port. Again I have succesfully transmitted using two Arduino Unos and their Xbee shields, and I haven't changed anything on my receiving end, so I feel like I must be missing something on my transmitting end using the LilyPad boards.

Suggestions and/or advice are much appreciated!!


willielenk

I solved my own problem so I'll explain my error here in case anyone else runs into the same problem:

I was not completely forthcoming with my code and my configuration. The device that I was sampling the analog voltage from was actually an I2C device. What I didn't show you in my code was that I had initialized the wire library to add this device as an I2C slave. It turns out that on the Arduino LilyPad USB, the SDA and SCL pins are on digital pins 2 and 3, which is the same place I tried to set up my software serial port. Moving the software serial port to digital pins 9 and 10 cleared this problem right up!

marilialb

Hi, thanks for sharing this information. As I understood correctly in Lilypad USB pin 9 is RX and pin 10 is TX right? I would have no idea how to start if wasn't for you. Do  you mind showing your final code, I'm still confused how to use the wire library. 

Go Up