xbee not Receiving info

Xbee projects like the adapter, xbee tutorials, tweetawatt/wattcher, etc. purchased at Adafruit

Moderators: adafruit_support_bill, adafruit

xbee not Receiving info

Postby yeyeee01 » Tue Aug 24, 2010 8:11 am

hello there, i had another topic here where xbees were not doing anything but now i have fixed some issues but i still have problems.
So, i have 2 xbees with the adafruit shield. One is connected to an arduino Mega with will be the receiver side; the other one is connecgted to an arduino nano wich will be the transmitter side. When i send a program to the arduinos the Red led on the oposite xbee lights up. Example: i load a program into the transmitter side and the red led on the receiver side lights up for about 5 seconds then it shuts off and the green led stays flashing. The problem is that there is nothing comming into the serial screen or into the arduino. I have gone through the tutorial here several times and i know that my baud rates are fine. Reseting the Xbees or the ardino does not make any difference. Any suggestions??
PS: when im go through the steps in the tutorial the xbees time out a couple of times.
yeyeee01
 
Posts: 11
Joined: Tue Aug 03, 2010 8:06 am

Re: xbee not Receiving info

Postby adafruit_support_bill » Tue Aug 24, 2010 8:22 am

If the red light is going on, the radios are working OK. That also implies that the serial connection to the XBee on the transmitter side is functional.

So the problem is that data on the receiver side is not getting from the XBee to the Mega?

Can you post your code and a photo of how you have the XBee/Mega wired?
User avatar
adafruit_support_bill
 
Posts: 16027
Joined: Sat Feb 07, 2009 9:11 am

Re: xbee not Receiving info

Postby yeyeee01 » Tue Aug 24, 2010 9:43 am

ok so here is the code that i tried. This is a little more involved but i also tried sending a simple string or an integer with the Serial.read() and Serial.write() commands and i still dont see anything on the receiving side.
Code for Sender
Code: Select all
//int inByte = 0;      // incoming serial byte

// Serial Variables
const int packetLength = 4;
byte packet[(packetLength - 1)];
int checksum;

// Light Button Variables
const int lightsbuttonPin = 2; // the number of the pushbutton pin
int lightsbuttonState = 0;         // variable for reading the pushbutton status

// Servo Motor Joystick Variable
const int joyH = 4;      // Joystick Horizontal Axis, Analog, Pin 4
const int joyV = 5;      // Joystick vertical Axis, Analog, Pin 5

// Servo Motor Variables
int servoValH;         // Variable to read the input value from the analog joystick
int servoValV;         // Variable to read the input value from the analog joystick

// Motor Joystick Pin Variable
int forwardreversepotPin = 0;
int motorSpeedControlandDir;
int forwardreversepotValue=0;

void setup() {
  Serial.begin(9600);      // Inizialize Serial
 
   // initialize the pushbutton pin as an input:
   pinMode(lightsbuttonPin, INPUT);
}

void loop(){
   // Read Light Button State
   lightsbuttonState = digitalRead(lightsbuttonPin);

   // Read the Horizontal joystick value  (value between 0 and 1023)
   servoValH = analogRead(joyH);
   servoValH = map(servoValH, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)
   
   // Read the Vertical joystick value  (value between 0 and 1023)
   servoValV = analogRead(joyV);
   servoValV = map(servoValV, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)
   
   // Read the  Rear Motor Joystick value
   motorSpeedControlandDir = analogRead(forwardreversepotPin)/4; // scale it to 0-FF
   analogWrite(4,forwardreversepotValue);
   
   // Send Light Button State value
   createPacket(0x00, lightsbuttonState);
   sendSerialData(packet);

   
   // Send Horizontal Joystick value
   createPacket(0x01, servoValH);
   sendSerialData(packet);

   // Send Vertical Joystick value
   createPacket(0x02, servoValV);
   sendSerialData(packet);
   
   // Send Motor Speed & Direction Joystick value
   createPacket(0x03, motorSpeedControlandDir);
   sendSerialData(packet);

   // Read Serial Data In, if it is available
   //if(Serial.available() > 0){
   //inByte = Serial.read();    // get incoming byte

   //  Serial.println(inByte);
   //}
     
   delay(100);      // Delay loop
}

// Create Packet Data
void createPacket(byte cmd, byte data){
   packet[0] = 0x7E;
   packet[1] = cmd;
   packet[2] = data;
   
   // Create Checksum Value, (cmd + data) = 0xFF - (cmd + data)
   checksum = cmd + data;
   checksum = 0xFF - checksum;
   checksum = 0xFF & checksum;
 
   packet[(packetLength - 1)] = checksum;
 
   return;
}

// Send Packet Serially
void sendSerialData(byte thePacket[3]){
   Serial.print(thePacket[0], BYTE);
   Serial.print(thePacket[1], BYTE);
   Serial.print(thePacket[2], BYTE);
   Serial.print(thePacket[3], BYTE);
 
   return;
}



Code for Receiver
Code: Select all
#include <Servo.h>

// Serial Variables
int inByte = 0;         // incoming serial byte

int serialData[5];
int arrayCount = 0;
int checksum;

// Servo Motor Pin Variables
const int servo1 = 7
;   // first servo, PWM, Pin 3
const int servo2 = 2;   // second servo, PWM, Pin 2

// Servo Motor Variables
int servoValH;      // variable to read the value from the analog pin
int servoValV;      // variable to read the value from the analog pin 

// Servo Motor Object Variables
Servo myservo1;      // create servo object to control a servo
Servo myservo2;      // create servo object to control a servo

// Motor Speed & Direction Pin Variables
int Motpin = 12;
int Joystickpin = 0;
int Relay = 52;

void setup() {
   // Attach the Servo to the Object
   myservo1.attach(servo1);   // attaches the servo
   myservo2.attach(servo2);   // attaches the servo

   // Set up Pin for Motor Direction
   pinMode(Relay, OUTPUT);
   
   // Inizialize Serial
   Serial.begin(9600);
}

void loop(){
   // Read Serial Data In, if it is available
   if(Serial.available() > 0){
      inByte = Serial.read();      // get incoming byte

      // Load Serial data into a packet until 4 bytes is reached.
      // Verify the the beginning of the packet with 0x7E
      if(inByte == 0x7E || arrayCount > 0 && arrayCount < 4){
         serialData[arrayCount] = inByte;   // Receive Data From Serial Port
         arrayCount++;                  // Increment the Array Counter
      }

      // Verify Checksum if a packet is received
      if(arrayCount == 4){
         arrayCount = 0;                           // Reset Data Packet Counter
         checksum = serialData[1] + serialData[2];      // Add Bytes 1 & 2 for checksum
         checksum = 0xFF - checksum;                  // Subtract checksum from 0xFF
         checksum = 0xFF & checksum;

         if(checksum == serialData[3]){ // Checksum is good
      Serial.print("good");      
                    switch(serialData[1]){
               case 0x00:   // LED
                  //serialData[2];
            
   break;
               case 0x01:   // Servo H
                  moveServoH(serialData[2]);
               break;
               case 0x02:   // Servo V
                  moveServoV(serialData[2]);
               break;
                                        case 0x03:   // Servo V
                  rearMotorControl(serialData[2]);
               break;
            }
         }
         else{   // Checksum Failed
            Serial.println("Bad Packet");
         }
      }   

   }
 
   //delay(15);          // waits for the servo to get there
}

void moveServoH(int servoValH){
   // Horizontal Servo
   myservo2.write(servoValH);      // sets the servo position according to the scaled value
 
   return;
}

void moveServoV(int servoValV){
   // Vertical Servo
   myservo1.write(servoValV);      // sets the servo position according to the scaled value
 
   return;
}

void rearMotorControl(int motorSpeedDir){
   int PWMval;

   if(motorSpeedDir >= 125){
      PWMval = (1.6538 * motorSpeedDir) - 166.7;
      analogWrite(Motpin, PWMval);
      digitalWrite(Relay, LOW);
                Serial.println("RELAY OFF");
   }
   else if(motorSpeedDir < 125){
      PWMval = 1.6538 * (255 - motorSpeedDir) - 166.7;
      analogWrite(Motpin, PWMval);
      digitalWrite(Relay, HIGH);
                Serial.println("RELAY ON");
   }
}

As far a pictures i dont have any, but i have them connected with wires comming out of the adafruit shield the folowing way. RX-to-Arduino Rx, Tx-to-arduino Tx, 5V-to-Arduino 5V out and Gnd-to-arduino Gnd. (same configuration on both arduinos)
Ps: Do you have an idea of a more simple code for me to at least test them?
yeyeee01
 
Posts: 11
Joined: Tue Aug 03, 2010 8:06 am


Return to XBee products from Adafruit

Who is online

Users browsing this forum: No registered users and 0 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]