hola amigos estoy en un proyecto de unos sistemas mteorologicos, tengo 3 arduinos con sus shield de xbee y sus 3 xbee en el que hasta ahora he podido comunicar mi arduino emisor con mi arduino receptor
pero ahora lo que quiero es poder comunicarme desde el receptor al emisor tratando de enviar una T desde el monitor serie para que me envie los datos de los sensores cada ves que lo mande la T y no me este enviando los datos constantemente
codigo del EMISOR
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int PinAlimentacion = 13; //PIN QUE DA 5V
int analog_pin = A0;//PIN A0 PARA LEER LM35
int cont;
float temperatura, tmedia;
void setup()
{
Serial.begin(9600);
pinMode(PinAlimentacion, OUTPUT);
digitalWrite(PinAlimentacion, HIGH); //5V en pin 13
}
void loop()
{
float hA = dht.readHumidity();
float tA = dht.readTemperature();
int tempValor;
tempValor = 0;
tempValor = analogRead(A0);
Serial.print("<SS.M#1 :");
Serial.println(tempValor);
Serial.print(">");
Serial.println(" ");
Serial.print("<TS.M#1 :");
Serial.print(tA);
Serial.print(">");
Serial.println(" ");
Serial.print("<HS.M#1 :");
Serial.print(hA);
Serial.print(">");
Serial.println(" ");
}
Como te expliqué por privado (por cierto no comunicarse por privado para pedir códigos).
En tu receptor estas usando el puerto Serie asi que jamás podrás enviar nada a menos que lo liberes.
Debes usar SoftwareSerial.
SoftwareSerial mySerial(10, 11); // RX, TX
Y ves que RX = 10 y TX = 11
Asi que solo conectas ahi el XBee y conservarás el Monitor serie.
Observa que tambien en lugar de usar Serial ahora todo se llama mySerial, pero eso solo es un nombre y podría llamarse Xbee
Solo le pones
SoftwareSerial Xbee(10, 11); // RX, TX
y si quieres enviar algo al Xbee pones
Xbee.print(dato);
Veamos como queda tu código modificado para que ahora conectes el Xbee a los pines 10,11 o los que tengas disponibles.
Y uses el puerto serie para enviar T.
Como aun no dices nada, el envio de la T hara que el Emisor transmita los datos a los 3 Xbee esclavos. Ojo con eso!!!
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int analog_pin = A0;//PIN A0 PARA LEER LM35
int cont;
float temperatura, tmedia;
int in;
bool estado = false;
void setup()
{
Serial.begin(9600);
}
void loop() {
float hA = dht.readHumidity();
float tA = dht.readTemperature();
int tempValor;
tempValor = 0;
tempValor = analogRead(A0);
if (enviarDatos()) {
Serial.print("<SA:");
Serial.println(tempValor);
Serial.print(">");
Serial.print("<TA:");
Serial.print(tA);
Serial.print(">");
Serial.println(" ");
Serial.print("<HA:");
Serial.print(hA);
Serial.print(">");
Serial.println(" ");
estado = false;
}
}
bool enviarDatos() {
if (Serial.available() > 0) {
char aChar = Serial.read();
if (aChar == 'T')
estado = true;
}
return estado
}
Quedaría luego ver si quieres que la respuesta sea para cada esclavo, entonces cada uno enviara un T1... T2 o T3 con 1..2..3 como nro de esclavo..
Pero creo que XBee asi transmite en modo broadcast o sea a todo el mundo y no tiene modo de discriminarlo. A menos que lo hagamos en el receptor.
La imagen corresponde a los mismos pines que te he indicado en el código
The XBee shield has two jumpers (the small removable plastic sleeves that each fit onto two of the three pins labelled XBee/USB). These determine how the XBee's serial communication connects to the serial communication between the microcontroller (ATmega8 or ATmega168) and FTDI USB-to-serial chip on the Arduino board.
With the jumpers in the XBee position (i.e. on the two pins towards the interior of the board), the DOUT pin of the XBee module is connected to the RX pin of the microcontroller; and DIN is connected to TX. Note that the RX and TX pins of the microcontroller are still connected to the TX and RX pins (respectively) of the FTDI chip - data sent from the microcontroller will be transmitted to the computer via USB as well as being sent wirelessly by the XBee module. The microcontroller, however, will only be able to receive data from the XBee module, not over USB from the computer.
With the jumpers in the USB position (i.e. on the two pins nearest the edge of the board), the DOUT pin the XBee module is connected to the RX pin of the FTDI chip, and DIN on the XBee module is connected to the TX pin of the FTDI chip. This means that the XBee module can communicate directly with the computer - however, this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the XBee module.
me parece que no puedes hacer o que yo te proponía. Ya que tienes todo fisicamente establecido.
Solo mover dos jumpers y veo que tampoco.
Lo que si veo es que XBEE permite direccionamiento de modo que tienes bastante para trabajar además de ese código que no usa las prestaciones de lo que tienes.
Aca tienes un tutorial que usa una librería especial para Xbee.
Aclaro: yo no tengo ni uso Xbee asi que de acá en mas lo dejo en manos de quien los conozca.
Por lo que veo, no puedes usar SoftwareSerial ni conectarte a otros pines que no sean Tx y Rx con esa Shield.
Asi que deberas trabajar con el direccionamiento y con peticiones para que el Master responda.
With the jumpers in the USB position (i.e. on the two pins nearest the edge of the board), the DOUT pin the XBee module is connected to the RX pin of the FTDI chip, and DIN on the XBee module is connected to the TX pin of the FTDI chip. This means that the XBee module can communicate directly with the computer - however, this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the XBee module.