Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: vmansmx5 on Jul 06, 2012, 12:52 pm

Title: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 06, 2012, 12:52 pm
Well after a few hours nuting it out i just about have it working but with one little problem with the reciver end here is the tx code
Code: [Select]
#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);

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

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();

Serial.print("<T:");
Serial.print(t, DEC);
Serial.print(">");

delay(2000);

Serial.print("<H:");
Serial.print(h, DEC);
Serial.print(">");

delay(2000);
}

The Rx code
Code: [Select]
char inData[24];
byte index;
boolean started = false;
boolean ended = false;

void setup()
{
Serial.begin(9600);
Serial.println("Temperature & Humidity");
}

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

  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(" ");
}
else if(inData[0] == 'H')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
     }

started = false;
ended = false;

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

This is what im getting in the coms on the reviver end
Code: [Select]
Temp: :16.0000000000,C

Humidity: :42.0000000000,%

Temp: :16.0000000000,C

Humidity: :42.0000000000,%

Temp: :16.0000000000,C

Humidity: :42.0000000000,%

Temp: :16.0000000000,C

Humidity: :42.0000000000,%

the problem is whats all the 000000000000 on the end i just want 16.00C or 42.00%
How can i fix this need help
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 06, 2012, 01:19 pm
well i added the lcd to the reciver end works great but all them 0000000000 i dont get
Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,21);
char inData[24];
byte index;
boolean started = false;
boolean ended = false;

void setup()
{
Serial.begin(9600);
Serial.println("Temperature & Humidity");
lcd.init();                     
lcd.backlight();
lcd.begin(20, 4);
lcd.setCursor(6, 1);
lcd.print("WELCOME");
delay(3000);
lcd.clear();
}

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

  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(" ");
           lcd.setCursor(0, 0);
           lcd.print("Temp:");
           lcd.setCursor(0, 1);
           lcd.print(inData);
           lcd.print("C");
}
else if(inData[0] == 'H')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
           lcd.setCursor(0, 2);
           lcd.print("Humidity:");
           lcd.setCursor(0, 3);
           lcd.print(inData);
           lcd.print("%");
     }

started = false;
ended = false;

index = 0;
inData[index] = '\0';
  }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 06, 2012, 01:29 pm
I fixd it here we go
Code: [Select]
#include "DHT.h"
#define DHTPIN 2    
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);

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

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();

Serial.print("<T");
Serial.print(t);
Serial.print(">");

delay(2000);

Serial.print("<H");
Serial.print(h);
Serial.print(">");

delay(2000);
}


i took out the Serial.print(h, DEC);
and it works great  :)
Code: [Select]
Temperature & Humidity

Temp: 17.00,C

Humidity: 57.00,%

Temp: 17.00,C

Humidity: 56.00,%

Temp: 17.00,C

Humidity: 55.00,%
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 07, 2012, 05:51 am
Quote
i took out the Serial.print(h, DEC);

For floats, the 2nd argument is the number of decimal places to print. You are telling it to print 10 decimal places.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 07, 2012, 10:24 am
Ok is that good.
here i have the transmitter with temp sensor moisture sensor and voltage but have proplems with the moisture reading on the reciver end. im geting .00 coming up when its on 0 this so my display its a 4line lcd
Quote

Temp:        17.00 C
Humidity:   40.00 %
Moisture:    0 .00
Voltage:     5.00  V


This is the code for the TX unit
Code: [Select]
#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);

int Sensor1 = A0;
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.02;   
float R2 =  7399.40;     
int value = 0;

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

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();
int Sensor1 = analogRead(A0);
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));

Serial.print("<T");
Serial.print(t);
Serial.print(">");

delay(1000);

Serial.print("<H");
Serial.print(h);
Serial.print(">");

delay(1000);

Serial.print("<M");
Serial.print(Sensor1);
Serial.print(">");

delay(1000);

Serial.print("<V");
Serial.print(vin);
Serial.print(">");

delay(5000);
}

and the RX
Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,21);
char inData[24];
byte index;
boolean started = false;
boolean ended = false;

void setup()
{
Serial.begin(9600);
Serial.println("Temperature & Humidity");
lcd.init();                     
lcd.backlight();
lcd.begin(20, 4);
lcd.setCursor(6, 1);
lcd.print("WELCOME");
delay(3000);
lcd.clear();
delay(100);
}

void loop()
{
  lcd.setCursor(0, 0);
  lcd.print("Temp:");
  lcd.setCursor(0, 1);
  lcd.print("Humidity:");
  lcd.setCursor(0, 2);
  lcd.print("Moisture:");
  lcd.setCursor(0, 3);
  lcd.print("Voltage:");
           
  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] == 'T')
{
   inData[0] = ' ';
   int windVal = atoi(inData);
           Serial.println(" ");
   Serial.print("Temp:");
           Serial.print(inData);
           Serial.print("C");
           Serial.println(" ");
           lcd.setCursor(11, 0);
           lcd.print(inData);
           lcd.print("C");
}
else if(inData[0] == 'H')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
           lcd.setCursor(11, 1);
           lcd.print(inData);
           lcd.print("%");
        }
        else if(inData[0] == 'M')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Moisture:");
           Serial.print(inData);
         
           Serial.println(" ");
           lcd.setCursor(11, 2);
           lcd.print(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(" ");
           lcd.setCursor(11, 3);
           lcd.print(inData);
           lcd.print("V");
     }

started = false;
ended = false;

index = 0;
inData[index] = ' ';
  }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 07, 2012, 04:25 pm
Code: [Select]
else if(started)
{
    inData[index] = aChar;
    index++;
    inData[index] = ' ';
}

The last line, inData[index] being assigned a space, is wrong. That array element should be assigned a NULL, instead.
Code: [Select]
        inData[index] = '\0';
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 08, 2012, 04:45 am
ok i put thet bit in and it works but had to add in a line to clear the last val it stayed on the lcd
           lcd.setCursor(11, 2);
           lcd.print("     ");
           lcd.setCursor(11, 2);
           lcd.print(inData);

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,21);
char inData[24];
byte index;
boolean started = false;
boolean ended = false;

void setup()
{
Serial.begin(9600);
Serial.println("Temperature & Humidity");
lcd.init();                      
lcd.backlight();
lcd.begin(20, 4);
lcd.setCursor(6, 1);
lcd.print("WELCOME");
delay(3000);
lcd.clear();
delay(100);
}

void loop()
{
 lcd.setCursor(0, 0);
 lcd.print("Temp:");
 lcd.setCursor(0, 1);
 lcd.print("Humidity:");
 lcd.setCursor(0, 2);
 lcd.print("Moisture:");
 lcd.setCursor(0, 3);
 lcd.print("Voltage:");
         
 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 TempVal = atoi(inData);
          Serial.println(" ");
  Serial.print("Temp:");
          Serial.print(inData);
          Serial.print("C");
          Serial.println(" ");
          lcd.setCursor(11, 0);
          lcd.print(inData);
          lcd.setCursor(18, 0);
          lcd.print("C");
}
else if(inData[0] == 'H')
    {
  inData[0] = ' ';
          int HumidityVal = atoi(inData);
  Serial.println(" ");
          Serial.print("Humidity:");
          Serial.print(inData);
          Serial.print("%");
          Serial.println(" ");
          lcd.setCursor(11, 1);
          lcd.print(inData);
          lcd.setCursor(18, 1);
          lcd.print("%");
       }
       else if(inData[0] == 'M')
    {
          inData[0] = ' ';
          int MoistureVal = atoi(inData);
          Serial.println(" ");
          Serial.print("Moisture:");
          Serial.print(inData);
          Serial.println(" ");
          lcd.setCursor(11, 2);
          lcd.print("     ");
          lcd.setCursor(11, 2);
          lcd.print(inData);
         
       }
       else if(inData[0] == 'V')
    {
  inData[0] = ' ';
          int VoltageVal = atoi(inData);
  Serial.println(" ");
          Serial.print("Voltage:");
          Serial.print(inData);
          Serial.print("Volts");
          Serial.println(" ");
          lcd.setCursor(11, 3);
          lcd.print("          ");
          lcd.setCursor(11, 3);
          lcd.print(inData);
          lcd.setCursor(18, 3);
          lcd.print("V");
    }

started = false;
ended = false;

index = 0;
inData[index] = ' ';
 }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 08, 2012, 05:01 am
i have also been working on this code for the transmiter what im tying to do is have the reviver send a code to the transmitter then it reads it then sends the value to the reciver then the reviver displays the value then sends out the next code and so on till it gets all 4 values then it delays then dose it all again.
So what i want is the reciver to send this

send this <R> For Temp Val
wait for incoming val
then display incoming Val

send this <B> For Humidity Val
wait for incoming val
then display incoming Val

send this <C> For Soil Val
wait for incoming val
then display incoming Val

send this <D> For Volt Val
wait for incoming val
then display incoming Val

then delay for 5mins then start again

This works great if i send them out the coms using my xbee coms board
Can anyone help me with this

This is the transmitter 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] = ' ';
           float t = dht.readTemperature();
   Serial.print("<T");
           Serial.print(t);
           Serial.print(">");
}
else if(inData[0] == 'B')
     {
           inData[0] = ' ';
           float h = dht.readHumidity();
   Serial.print("<H");
           Serial.print(h);
           Serial.print(">");
        }
        else if(inData[0] == 'C')
     {
   inData[0] = ' '; 
           int Sensor1 = analogRead(A0);
           Serial.print("<M");
           Serial.print(Sensor1);
           Serial.print(">");
        }
        else if(inData[0] == 'D')
     {
           inData[0] = ' ';
           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] = ' ';
  }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 08, 2012, 10:20 am
ok so i put on a TFT color LCD looks Great just been playing around with it here are some photos of my workbench the photos are not the best.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 09, 2012, 01:53 am
Quote
This works great if i send them out the coms using my xbee coms board
Can anyone help me with this

So, what is the problem?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 09, 2012, 02:29 am
Well not sure on the reciver code how to set it up like this.
i can send the  R B C D by my xbee adapter board and the transmitter sends back the values.
But how to set up the reviver part im not sure can i put in a delay that waits for incoming val then sends out the next code......
So what i want is the reciver to Run like this

send this <R> For Temp Val
wait for incoming val
then display incoming Val

send this <B> For Humidity Val
wait for incoming val
then display incoming Val

send this <C> For Soil Val
wait for incoming val
then display incoming Val

send this <D> For Volt Val
wait for incoming val
then display incoming Val

then delay for 5mins then start again

Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 09, 2012, 04:49 pm
Quote
So what i want is the reciver to Run like this

send this <R> For Temp Val
wait for incoming val
then display incoming Val

<snip>

send this <D> For Volt Val
wait for incoming val
then display incoming Val

then delay for 5mins then start again

I'm confused. What are you sending "<R>" to? What is sending data? Why does the receiver need to wait?

In my mind, the receiver should do nothing until it receives a letter command. It should then process that command, which means sending the appropriate output. There is no reason for it to delay at all.

The application that sends the letter commands should only send them once every 5 minutes.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 09, 2012, 09:46 pm
the reciver is sending <R> for temp to the transmitter then the transmitter sends back the value for the of temp
the reciver then displays the value.
then the reciver sends <B> For Humidity to the  transmitter then the transmitter sends back the value for the of temp
the reciver then displays the value.
and so on
I tryd this but it keeps sending then out and cant get the value back delays dont work
Code: [Select]
void loop()
{
  lcd.setCursor(0, 0);
  lcd.print("Temp:");
  lcd.setCursor(0, 1);
  lcd.print("Humidity:");
  lcd.setCursor(0, 2);
  lcd.print("Moisture:");
  lcd.setCursor(0, 3);
  lcd.print("Voltage:");
 
  Serial.print("<R>");
 
  Serial.print("<B>");

  Serial.print("<C>");
   
  Serial.print("<D>");
 
 
           
  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] == 'T')
{
   inData[0] = ' ';
   int windVal = atoi(inData);
           Serial.println(" ");
   Serial.print("Temp:");
           Serial.print(inData);
           Serial.print("C");
           Serial.println(" ");
           lcd.setCursor(11, 0);
           lcd.print(inData);
           lcd.print("C");
}
else if(inData[0] == 'H')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
           lcd.setCursor(11, 1);
           lcd.print(inData);
           lcd.print("%");
        }
        else if(inData[0] == 'M')
     {
   inData[0] = ' ';
           int temp = atoi(inData);
   Serial.println(" ");
           Serial.print("Moisture:");
           Serial.print(inData);
         
           Serial.println(" ");
           lcd.setCursor(11, 2);
           lcd.print(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(" ");
           lcd.setCursor(11, 3);
           lcd.print(inData);
           lcd.print("V");
     }

started = false;
ended = false;

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

Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 09, 2012, 11:48 pm
Code: [Select]
  Serial.print("<R>");
 
  Serial.print("<B>");

  Serial.print("<C>");
   
  Serial.print("<D>");

Send a bunch of requests on every pass through loop. Then, don't wait for a response or for any data to have arrived. OK, I think I see the problem.

You need to create a blocking function, called after each request for data, that waits for a reply.

You are sending R, B, C, and D, and expecting T, H, M, and V. Why is that?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 10, 2012, 09:07 am
Quote
You are sending R, B, C, and D, and expecting T, H, M, and V. Why is that?

Becouse i want the reciver to send out R,B,C,D to get the value back by T,H,M,V

Quote
You need to create a blocking function, called after each request for data, that waits for a reply.

How can this be done?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 10, 2012, 01:22 pm
Quote
How can this be done?


Code: [Select]
// Global variables
char reply[80];
int index = 0;

void waitForReply(unsigned long howLongToWait)
{
   index = 0;
   unsigned long startTime = millis();
   while(millis() - startTime < howLongToWait)
   {
      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)
      {
         break; // Exit the while loop
      }
   }
}


This assumes that sending <R> results in <XXX> coming back. If so, reply will contain the XXX stuff.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 11, 2012, 10:44 am
Just tying this out not sure if this is the right way to go about it but must be missing somthing when i click verify i get this message
Quote

test_RX1:0: error: expected ',' or '...' before numeric constant
test_RX1:17: error: expected ',' or '...' before numeric constant


Code: [Select]

char reply[80];
int index = 0;
boolean started = true;
boolean ended = true;

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

void loop() {
 
Serial.print("<R>");

waitForReply(1);
}

void waitForReply(unsigned long 3000 ,1)
{
   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)
      {
        Serial.print("GotReply");
        break; // Exit the while loop
      }
   }
}


Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 11, 2012, 12:59 pm
Code: [Select]
void waitForReply(unsigned long 3000 ,1)
{

3000 is not a valid variable name. Neither is 1, which is untyped.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 11, 2012, 09:47 pm
Ok so this workd but its sending <R> too many times how can i get it to send 1 time then to wait for reply
Quote
char reply[80];
int index = 0;
boolean started = true;
boolean ended = true;

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

void loop() {
 
 
Serial.print("<R>");


}

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)
      {
        Serial.print("GotReply");
        break; // Exit the while loop
      }
   }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 12, 2012, 12:41 pm
Quote
Ok so this workd but its sending <R> too many times how can i get it to send 1 time then to wait for reply

Maybe you need to actually call the function.

Code: [Select]
void loop()
{  // Moved down here where it belongs
  Serial.print("<R>");
  waitForReply(1000);
}


Why does the function take an argument, how long to wait, and then wait for a hardcoded amount of time?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 13, 2012, 12:22 pm
OK so been trying this the reciver sends out the <R> and the transmitter gets it then sends back the <T16.00> but the reciver is not geting it or displaying anything
Code: [Select]
char inData[24];
char reply[80];

byte index;
boolean started = true;
boolean ended = true;

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

void loop() {
 
 
Serial.print("<R>");
waitForReply(5000);



}

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] = ' ';
      }
      else if(aChar == '>')
      {
        ended = true;
      }
      else if(started)
      {
         reply[index] = aChar;
         index++;
         reply[index] = '\0';
      }

      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] = ' ';
           
      }
   }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 13, 2012, 08:00 pm
What code is running on the transmitter?

Your initial post contains references to LiquidCrystal that implied that you have an LCD connected to the Arduino. Why not use that to show some debug messages, and perhaps get an idea what is happening?

Remind me what kind of XBees you have, how they are connected to the Arduinos, and how they are configured.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 14, 2012, 01:40 am
Ok so what i have is.
The reciver sends out the <R> the tansmiter gets it and sends back the <T13.00> Temp the Test Reciver displays it but the Reciver board dose not just keeps sending <R>

Transmitter:
Arduino Mega + Xbee shield + V1 Xbee + Sensors
Reciver:
Arduino duemilanove + adapter board + V1 xbee
Test Reciver:
MY own Designd PCB with V1 xbee and TFT LCD

All V1 xbee are xbee default baud.

Transmitter:
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] = ' ';
           float t = dht.readTemperature();
   Serial.print("<T");
           Serial.print(t);
           Serial.print(">");
}
else if(inData[0] == 'B')
     {
           inData[0] = ' ';
           float h = dht.readHumidity();
   Serial.print("<H");
           Serial.print(h);
           Serial.print(">");
        }
        else if(inData[0] == 'C')
     {
   inData[0] = ' '; 
           int Sensor1 = analogRead(A0);
           Serial.print("<M");
           Serial.print(Sensor1);
           Serial.print(">");
        }
        else if(inData[0] == 'D')
     {
           inData[0] = ' ';
           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] = ' ';
  }
}


Reciver:
Code: [Select]

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


Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 14, 2012, 01:42 am
Test Reciver:
Code: [Select]

#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);
   
 
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 14, 2012, 02:53 am
Is it just me, or is the receiver code actually on the transmitter, and vice verso?\

Only the "receiver" keeps sending <R>. The "transmitter" keeps reading serial data and replying.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 14, 2012, 03:09 am
yes the receiver is sendind the <R> 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?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 14, 2012, 03:20 am
Lets just call the devices A and B. B sends <R>. A receives <R>, 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:
Code: [Select]
   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).
Code: [Select]
      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.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 14, 2012, 03:59 am
Ok so B Sends <R> 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 <R> 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
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 14, 2012, 04:10 am
Please re-read the last 5 words of reply #21.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 14, 2012, 04:32 am
and how they are configured.
as in the Xbees thay are the default program
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 14, 2012, 01:57 pm
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.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 15, 2012, 09:58 pm
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.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 16, 2012, 01:57 am
Quote
Is this the right way to do this.

Yes.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 19, 2012, 08:34 am
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] = ' ';
           
      }
   }
}
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 19, 2012, 12:01 pm
As you've seen, you have problems when you have 2 XBees with the same MY value on a network.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 19, 2012, 09:38 pm
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
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Jul 19, 2012, 09:46 pm
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.
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 21, 2012, 11:28 pm
:) :) 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();
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: vmansmx5 on Jul 23, 2012, 09:44 pm
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?
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: sams99 on Nov 09, 2016, 05:37 am
please help me,,,i have 2 xbee s2 with shield,2 arduino uno and sensor dht11,,give me sketch transmit and receive
thanks
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: cmpunk112 on Dec 08, 2016, 07:34 pm
Can you send me a circuit diagram
Title: Re: DHT11 sensor Sending data by xbee to xbee
Post by: PaulS on Dec 08, 2016, 09:40 pm
Quote
Can you send me a circuit diagram
Any old circuit diagram?