DHT11 sensor Sending data by xbee to xbee

Test Reciver:

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define SD_CS    4  // Chip select line for SD card
#define TFT_CS  10  // Chip select line for TFT display
#define TFT_DC   9  // Data/command line for TFT
#define TFT_RST  8  // Reset line for TFT (or connect to +5V)
#define bkl 2      //LCD Black Light
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

char inData[24];
byte index;
boolean started = false;
boolean ended = false;
\
void setup(void) {
  Serial.begin(9600);
  pinMode(TFT_CS, OUTPUT);
  digitalWrite(TFT_CS, HIGH);  
  pinMode(bkl, OUTPUT);
  digitalWrite(bkl, LOW); 
  // Our supplier changed the 1.8" display slightly after Jan 10, 2012
  // so that the alignment of the TFT had to be shifted by a few pixels
  // this just means the init code is slightly different. Check the
  // color of the tab to see which init code to try. If the display is
  // cut off or has extra 'random' pixels on the top & left, try the
  // other option!

  // If your TFT's plastic wrap has a Red Tab, use the following:
  tft.initR(INITR_REDTAB);   // initialize a ST7735R chip, red tab
  // If your TFT's plastic wrap has a Green Tab, use the following:
  //tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab

  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
    return;
  }
  Serial.println("OK!");

  bmpDraw("welcome.bmp", 0, 0);
  delay(5000);
  bmpDraw("b8.bmp", 0, 0);
  testfillrects(ST7735_WHITE);
  tft.fillCircle(15, 103, 5, ST7735_BLACK);
  tft.fillCircle(15, 121, 5, ST7735_BLACK);
  tft.fillCircle(15, 139, 5, ST7735_BLACK);
}

void loop() {
 
  delay(500);
  tft.fillCircle(15, 121, 5, ST7735_BLACK);
  tft.drawLine(0, 25, tft.width()-1, 25, ST7735_GREEN);
  tft.setCursor(25, 6);
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(2);
  tft.print("DISPLAY");
  tft.setCursor(5, 30);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Temperature");
  tft.setCursor(115, 30);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("C");
  tft.setCursor(5, 40);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Humidity");
  tft.setCursor(115, 40);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("%");
  tft.setCursor(5, 50);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Moisture");
  tft.setCursor(5, 60);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Voltage");
  tft.setCursor(115, 60);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("V");
  tft.setCursor(5, 70);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("0.1 deg C");
  tft.setCursor(5, 80);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Pressure");
  tft.setCursor(115, 80);
  tft.setTextColor(ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("Pa");
  tft.drawLine(0, 90, tft.width()-1, 90, ST7735_GREEN);
  
  tft.setCursor(28, 99);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(1.7);
  tft.print("TX");
  
  tft.setCursor(28, 119);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(1.7);
  tft.print("RX");
  
  tft.setCursor(28, 136);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(1.7);
  tft.print("SD");

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] = '\0';
	}
  }

  if(started && ended)
  {
	// Use the value
	if(inData[0] == 'T')
	{
	   inData[0] = ' ';
	   int windVal = atoi(inData);
           Serial.println(" ");
	   Serial.print("Temp:");
           Serial.print(inData);
           Serial.print("C");
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +25/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 30);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData);
           
	}
	else if(inData[0] == 'H')
     {
	   inData[0] = ' ';
           int temp = atoi(inData);
	   Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +46/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 40);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData);
           
        }
        else if(inData[0] == 'M')
     {
	   inData[0] = ' ';
           int temp = atoi(inData);
	   Serial.println(" ");
           Serial.print("Moisture:");
           Serial.print(inData);
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +67/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 50);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData);
        }
        else if(inData[0] == 'V')
     {
	   inData[0] = ' ';
           int temp = atoi(inData);
	   Serial.println(" ");
           Serial.print("Voltage:");
           Serial.print(inData);
           Serial.print("Volts");
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +86/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 60);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData);
        }
        else if(inData[0] == 'F')
     {
	   inData[0] = ' ';
           int temp = atoi(inData);
	   Serial.println(" ");
           Serial.print("Temperature:");
           Serial.print(inData);
           Serial.print("*0.1 deg C");
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +106/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 70);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData); 
        }
        else if(inData[0] == 'P')
     {
	   inData[0] = ' ';
           int temp = atoi(inData);
	   Serial.println(" ");
           Serial.print("Pressure:");
           Serial.print(inData);
           Serial.print(" Pa");
           Serial.println(" ");
           tft.fillCircle(15, 121, 5, ST7735_RED);
           tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +126/2, 40, 9, ST7735_WHITE);
           tft.setCursor(70, 80);
           tft.setTextColor(ST7735_RED);
           tft.setTextSize(1);
           tft.println(inData);
     }

	started = false;
	ended = false;

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

void testfillrects(uint16_t color1) {
  
    tft.fillRect(tft.width()/2 -130/2, tft.height()/2 -110/2 , 150, 65, color1);
    
  
}

Is it just me, or is the receiver code actually on the transmitter, and vice verso?\

Only the "receiver" keeps sending . The "transmitter" keeps reading serial data and replying.

yes the receiver is sendind the and waiting for the reply back from the transmitter it sends back the value of the senseor for the reciver to display the value on the com window but im not geting a replay back. the test reciver gets the reply back?

Lets just call the devices A and B. B sends . A receives , and stores R in inData, setting started and ended to true. After the while loop ends, started and ended are true, so A responds with <Txx.xx>.

So, what does device A do, if is receives serial data:

   while(millis() - startTime < 3000)
   {
      char aChar = Serial.read();

First, it tries to read data that might not be there, yet. That's not good.

But, let's assume that the data is quick in coming back (not a valid assumption, but, bear with me).

      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(" ");

Suppose that inData does contain Txx.xx. What do you do with that data? Yep, send it to the other XBee. What good is that? You need to separate the serial data being sent to the serial monitor from the serial data being sent to the XBee. That means that you need either a Mega with multiple hardware serial ports or you need to use NewSoftSerial/SoftwareSerial to talk to the XBee and Serial to talk to the Serial Monitor.

Ok so B Sends Then A recives it then it sends <Txx.xx> back to A and A should display the value
If i have The xbee adaptorboad plugd in the the usb i can send and get back the value on the coms window
but A is not geting the value back and displaying it so it must be the code on A thats not reading in the value

Please re-read the last 5 words of reply #21.

and how they are configured.
as in the Xbees thay are the default program

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.

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.

Is this the right way to do this.

Yes.

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 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 and not getting the Value.

B1 Code

#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

// 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] = ' ';
           
      }
   }
}

As you've seen, you have problems when you have 2 XBees with the same MY value on a network.

well when b3 is not plugd in this still dose not work B2 sends out 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

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.

:slight_smile: :slight_smile: 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

char inData[24];
byte index;
boolean started = false;
boolean ended = false;
void waitForReply(unsigned long howLongToWait)
{
   index = 0;
   unsigned long startTime = millis();
   while(millis() - startTime < 3000)
   while(Serial.available() > 0)
   {
	char aChar = Serial.read();

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?

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

Can you send me a circuit diagram

Can you send me a circuit diagram

Any old circuit diagram?