Sending via Xbee [Solved]

Hey

I am a total noob to arduino but i have to send data samplet with an arduino leonardo to my pc.

The Arduino leonardo is connected (Rx/Tx) to an xbee Series 2.
This should send the incomming data to my second xbee Series 2. So i could read it.

The xbees are connected to each other but i can`t get any signal by programming arduino...

Is there a samplecode for this, so i can see if the connection between leonardo and xbee does work?

Thanks for your help

There is so much missing from you post that it is hard to know where to begin.

You appear to have an XBee connected to the PC. I don't suppose that you are using duct tape, but there is nothing that explains just how the XBee is connected.

You appear to have an XBee connected to the Arduino. I don't suppose that you are using duct tape, but there is nothing that explains just how the XBee is connected.

You seem to think that the XBees can communicate, but there in nothing that explains how they are configured, so there is no basis for assuming that they can indeed communicate.

You seem to have some code on the Arduino, but you didn't share it. You'd be voted out of Mr. Roger's neighborhood.

i am sorry for that lack of information.

The first xbee is on an AE-Xbee-USB and is connected to the pc vie USB. I used XCTU to set as Coordinator API-2.

The second Xbee is on an AE-Xbee-Reg-DIP which is connectet to the arduino with 2 wires (RX/TX).
It is an Router API-2. Data sampling is turned off.

Sending frames from one xbee to the other is no problem. Sampling data with the second xbee and sending it to the first works good.

So my arduino is getting datathrough i2c. This works too.

As i said the goal is to send the sampled date with the second xbee. Would it be better to use the second xbee in AT mode? do i have to build the frames that will be send with in the program?

#include <SoftwareSerial.h>
#include <Wire.h>

byte val = 10001100;
SoftwareSerial xbee(2, 3); // RX, TX

int LED = 1;

void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(B1001000);
Wire.write(val);
Wire.endTransmission();
xbee.begin(9600);
}

void loop()
{
Wire.requestFrom(B1001000, 3);
Wire.read();
int h = Wire.read();
int l = Wire.read();
int r = Wire.read();
xbee.println( h );

Serial.print(h);
Serial.print(" “);
Serial.print(l);
Serial.print(” ");
Serial.println(r);

if ( LED == 0 )
digitalWrite(13, LOW);
else
digitalWrite(13, HIGH);
LED = 1 - LED;
delay( 1000 );
}

as i said, i am new to to using micro-controllers and to this forum. Please be pstient with me :wink:

which is connectet to the arduino with 2 wires (RX/TX).

It takes a minimum of 4 wires - power, ground, data out, and data in. You're only half way there.

Would it be better to use the second xbee in AT mode?

The two XBees need to use the same mode. Since the microcontroller on the XBee is not collecting data or toggling output pins, it is far easier if both are in AT mode.

do i have to build the frames that will be send with in the program?

In API mode, yes.

 xbee.println( h );

That is NOT how to send data in API mode. That IS how to send data in AT mode. (See why AT mode is better?)

Thank you for your help.

I did all you recommended. I connected Vcc and Gnd directly to my Arduino and i set both my Xbees to AT mode.

The problem is, i still don`t get any signal on my coordinator.

may there be a problem with my xbee setting?

Coordinator:
ID 2001
The rest is on default right now.

Router:
ID 2001
DH 13A200 (SH of Coordinator)
DL 40B414AE (SL of Coordinator)
The rest is on default. So IR, IC is 0
And the D1, D5, D7 P0 ar 1 the others are 0. SM is 0 too because it`a router.

Do i have to activate the RX/TX pins via command?

Do i have to activate the RX/TX pins via command?

Of course.

The second Xbee is on an AE-Xbee-Reg-DIP which is connectet to the arduino with 2 wires (RX/TX).

And yet you appear to be using SoftwareSerial to read data from/write data to pins 2 and 3.

Post a picture of your actual setup.

I am sorry right now i can`t provide a picture of my setup.

And yet you appear to be using SoftwareSerial to read data from/write data to pins 2 and 3.

Is this unusual? Are there different options?

Do i have to activate the RX/TX pins via command?

Of course.

So what is the command for that? Do i have to change pin settings in XCTU?

I could solve the problem !! :smiley:

The problem was, that arduino leonardo has two Serial Ports. So i had to set xbee to Serial1

This is my new code

#include <SoftwareSerial.h>
#include <Wire.h>

byte val = 10001100;                                           // configuration ADS1112
SoftwareSerial xbee(2, 3);                                     // RX, TX

int  LED = 1;

void setup()  
{
   Wire.begin();  
   Serial.begin(9600);
   Serial1.begin(9600);
   Wire.beginTransmission(B1001000);                           // I2C Adresse
   Wire.write(val);
   Wire.endTransmission();
   xbee.begin(Serial1);
}

void loop()  
{
 Wire.requestFrom(B1001000, 3);                                // Request 3 bytes
 Wire.read();
	int h = Wire.read();
  	int l = Wire.read();
  	int r = Wire.read();
  Serial1.print(l);
  
  Serial.print(h);       
  Serial.print("  ");       
  Serial.print(l);       
  Serial.print("  ");       
  Serial.println(r); 
  

  if ( LED == 0 )                                              // LED active when sending data
    digitalWrite(13, LOW);
  else
    digitalWrite(13, HIGH);
  LED = 1 - LED;
  delay( 1000 );
}

Thank you so much for your help :slight_smile:

This is my new code

What version of the IDE does that compile on? Calling SoftwareSerial::begin() with an instance of the HardwareSerial class is not supported on any version of the IDE that I have used.