- System Overview
1x Arduino Duemilanove. Can be 2 Arduino Uno.
XBEE MODULES:
There are some hardware configuration that should be done to get all the devices ready to communicate with each other. The first step is configure the Xbee modules, for this project I just changed the destination address low DL = 0xFFFF. If DH is 0 and DL equals 0xFFFF, the module’s transmissions will be received by all modules.
To change this parameter is necessary a serial connection with the XBEE module. There are many ways to do it, in this case was used an Arduino Duemilanove (without the microprocessor!) that acts like a FTDI interface. The arduino UNO doesn’t work for this situation. The easiest way to modify the parameter is to use the software X-CTU supplied by Digi. This software works just with Windows SO and before connect to the hardware is necessary install the FTDI driver which emulate a USB serial port.
To test your configuration download the code below to one of the arduinos:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print('H');
delay(1000);
Serial.print('L');
delay(1000);
}
and to the other one download the software PhysicalPixel located in the arduino library. If everything is OK then you will see the led 13 blinking.
NOTE: FOR THIS TEST JUST STACK THE XBEE SHIELD WITH THE ARDUINO BOARD. DON’T STACK THE ETHERNET SHIELD YET.
When the shields are stacked some limitations need be resolved:
The Ethernet Shield don’t have the male ICSP conector but the XBEE Shield use this connection to supply 5Vcc to the board. The workaround to get 5Vcc in the Xbee Shield is sold a jumper from the second ICSP interface of Arduino (just Arduino UNO have it). To the ICSP connector of Xbee Shield. The pictures below shows where sold the cables in both boards.
Pressure and temperature sensors BMP085 needs a 3.3Vcc power supply but the Xbee Shield don’t have this header. The solution was again get the supply directly from the board pins.
The same happens with the 5Vcc for the other sensors. The solution was assembly small pins in the Ethernet Shield or Arduino right below the Xbee Shield.
Here is the complete stack with Arduino, Ethernet Shield and Xbee Shield. Note the power connection below the Xbee Shield.
Humidity sensor and Temperature sensor (TMP036) use simple analog input pins be careful to not use analog inputs that already been used by BMP085 and Ethernet Shield.
After finish with the hardware is time to start with the software.
The project use many libraries to control peripherals that was developed by the suppliers device or third person. The documentation about these libraries are easily found at the internet.
The goal here is explain more about the communication tasks between the two devices. The two devices was named according their functions:
1 – MASTER Device (Data Client): The device that contains the Ethernet Shield and is called Master because it always initiate the communication with the SLAVE asking for some information. The Master have the function of send the collected data to the internet (Pachube).
2 – SLAVE Device (Data Server): The device that collect data from the weather sensors and send to Master when requested. The slave never initiate the communication with the Master.
In a more complex scenario one Master could communicate with several slaves.
The master talk with the slave through a communication protocol. For this project was created a small protocol where the Master send a byte to slave asking for information and the slave returns a information packet containing the weather data.
The encoded packet sent by the slave have the following structure:
xxxxTyyyyPzzzzH where xxxx, yyyy and zzzz are the values and T, P and Z are the delimiters. A normal frame could have the following format 2340T1023P81H , decoding it you will get Temperature = 23.40 oC, Pressure = 1023 hPa and Humidity = 81%.
Here is the C code that encode the information:
Serial.print(temp_int, DEC);
Serial.print(‘T’);
Serial.print(press_int, DEC);
Serial.print(‘P’);
Serial.print(humidity, DEC);
Serial.print(‘H’);
and for decode:
if (LerSerial == 1){
char *chpt = strtok(valorlido, “T”);
if (chpt > 0) {
temperatureOut = atof(chpt)/100;
}
chpt = strtok(NULL, “P”);
if (chpt > 0){
pressure = atoi(chpt);
}
chpt = strtok(NULL, “H”);
if (chpt > 0){
humidity = atoi(chpt);
}