I am trying to send DHT data through an XBee. I combined sketches and ended up with the following:
/*****************************************************************
XBee_Serial_Passthrough.ino
Set up a software serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
The XBee Shield makes all of the connections you'll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
the XBee's DOUT and DIN pins to Arduino pins 2 and 3.
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN 35
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(10, 11); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
pinMode(31,OUTPUT);
pinMode(33,OUTPUT);
digitalWrite(31, LOW);
digitalWrite(33, HIGH);
Serial.println("DHTxx test!");
XBee.write("DHTxx Test!");
dht.begin();
}
void loop()
{
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
XBee.write("Humidity: ");
XBee.write(h);
XBee.write(" %\t");
XBee.write("Temperature: ");
XBee.write(t);
XBee.write(" *C ");
XBee.write(f);
XBee.write(" *F\t");
XBee.write("Heat index: ");
XBee.write(hic);
XBee.write(" *C ");
XBee.write(hif);
XBee.write(" *F");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}
IT displays the proper data in the monitor attached to the Arduino IDE, but in both XTCU and CoolTerm I do not get the values, merely a 'K'. Please see attached image.
Thank you for your assistance.
