Go Down

Topic: DHT11 sensor Sending data by xbee to xbee (Read 12932 times) previous topic - next topic

PaulS

Digi claims that the XBees can communicate straight out of the box. That is plain horseshit. They can not.

You must, at a minimum set PAN ID, MY, and DL for each XBee. PAN ID must be the same for both of them.

MY on one must be DL on the other, and neither value should be 0.
The art of getting good answers lies in asking good questions.

vmansmx5

I set the xbees like so
XBEE1
ID=3005
MY=10
DL=11

XBEE2
ID=3005
MY=11
DL=10

Is this the right way to do this.

PaulS

Quote
Is this the right way to do this.

Yes.
The art of getting good answers lies in asking good questions.

vmansmx5

Just got back on to this tonight still no luck
what i have is.

B1 this board this the sensors on it
ID=3005
MY=10
DL=11
B2 arduino board and xbee
ID=3005
MY=11
DL=10
B3 is xbee and adaptor board to com's
ID=3005
MY=11
DL=10

So B2 sends out <R> to B1 and B1 gets it then sends out <TXX.XX> B3 is getting the reading on the coms but B2 is not its only sending <R> and not getting the Value.

B1 Code
Code: [Select]

#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);

char inData[24];
byte index;
boolean started = false;
boolean ended = false;

int Sensor1 = A0;
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.02;    // !! resistance of R1 !!
float R2 =  7399.40;     // !! resistance of R2 !!
// variable to store the value
int value = 0;

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

void loop()
{

while(Serial.available() > 0)
  {
char aChar = Serial.read();
if(aChar == '<')
{
    started = true;
    index = 0;
    inData[index] = ' ';
}
else if(aChar == '>')
{
    ended = true;
}
else if(started)
{
    inData[index] = aChar;
    index++;
    inData[index] = ' ';
}
  }

  if(started && ended)
  {
// Use the value
if(inData[0] == 'R')
{
           inData[0] = ' ';
           delay(1000);
           float t = dht.readTemperature();
   Serial.print("<T");
           Serial.print(t);
           Serial.print(">");
}
else if(inData[0] == 'B')
     {
           inData[0] = ' ';
           delay(1000);
           float h = dht.readHumidity();
   Serial.print("<H");
           Serial.print(h);
           Serial.print(">");
        }
        else if(inData[0] == 'C')
     {
   inData[0] = ' ';
           delay(1000);
           int Sensor1 = analogRead(A0);
           Serial.print("<M");
           Serial.print(Sensor1);
           Serial.print(">");
        }
        else if(inData[0] == 'D')
     {
           inData[0] = ' ';
           delay(1000);
           value = analogRead(analogInput);
           vout = (value * 5.0) / 1024.0;
           vin = vout / (R2/(R1+R2));
   Serial.print("<V");
           Serial.print(vin);
           Serial.print(">");
     }

started = false;
ended = false;

index = 0;
inData[index] = ' ';
  }
}


B2 Code
Code: [Select]

// Global variables
char inData[24];
char reply[80];
int index = 0;
boolean started = true;
boolean ended = true;

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

void loop() {
 
 
Serial.print("<R>");
waitForReply(2000);
delay(1000);


}

void waitForReply(unsigned long howLongToWait)
{
   index = 0;
   unsigned long startTime = millis();
   while(millis() - startTime < 3000)
   {
      char aChar = Serial.read();
      if(aChar == '<')
      {
         started = true;
         index = 0;
         reply[index] = '\0';
      }
      else if(aChar == '>')
      {
        ended = true;
      }
      else if(started)
      {
         reply[index] = aChar;
         index++;
         reply[index] = ' ';
      }

      if(started && ended)
      {
        if(inData[0] == 'T')
{
   inData[0] = ' ';
   int windVal = atoi(inData);
           Serial.println(" ");
           Serial.print("GotReply");
   Serial.print("Temp:");
           Serial.print(inData);
           Serial.print("C");
           Serial.println(" ");
           
           }

started = false;
ended = false;

index = 0;
inData[index] = ' ';
           
      }
   }
}

PaulS

As you've seen, you have problems when you have 2 XBees with the same MY value on a network.
The art of getting good answers lies in asking good questions.

vmansmx5

well when b3 is not plugd in this still dose not work B2 sends out <R> i can see in the coms monitor and b1 gets it then sends out <Txx.xx> witch i see in the coms monitor but B2 is not showing that value or not reciving it

PaulS

Quote
but B2 is not showing that value or not reciving it

Does the RX light on the XBee shield/adapter board flash when B2 should be receiving serial data?
Does the RX light on the Arduino flash when B2 should be receiving data?

I'd put some more Serial.print() and/or Serial.println() statements in the code on the B2 Arduino to see what it is receiving. They will confuse the B1 Arduino, but at least you can get a handle on whether the B2 receives anything.
The art of getting good answers lies in asking good questions.

vmansmx5

:) :) I got it all working i changed some of the code the same as B1 all working B2 is know displaying the values.
How can i have more Xbees as in more B1 type with sensors that send there data back to B2
Code: [Select]

char inData[24];
byte index;
boolean started = false;
boolean ended = false;


Code: [Select]

void waitForReply(unsigned long howLongToWait)
{
   index = 0;
   unsigned long startTime = millis();
   while(millis() - startTime < 3000)
   while(Serial.available() > 0)
   {
char aChar = Serial.read();

vmansmx5

is there  a way of sending more values  at 1 time. The way i have It sends each value at a time thats 6readings for differnt sensors  can i read all 6 then send the lot as i packet?

sams99

please help me,,,i have 2 xbee s2 with shield,2 arduino uno and sensor dht11,,give me sketch transmit and receive
thanks

cmpunk112


PaulS

Quote
Can you send me a circuit diagram
Any old circuit diagram?
The art of getting good answers lies in asking good questions.

Go Up