Debugging Steps of XBee Sensor Expansion Board
Debugging Steps of XBee Sensor Expansion Board
Ltd
solid
Function diagram.
NoteBefore power on, use multimeter to test the board. Check whether the main power is short to GND
1 / 14
solid
According the resource on the expansion board, you need 5 experiments to debug it. 1 IIC interface on the expansion board testing:
There is IIC interface on this Arduion XBee sensor expansion board which can be used in the communication between Arduino and devices with IIC interface. The test uses IIC/SPI to serial chip M1172 expansion board. Hardware wiring is as following:
Following are testing codes: //XR20M1172 two channel I2C/SPI UART with 64-byte FIFO #include <Wire.h> // XR20M1172 Register definitions #define RHR 0x00 //read-only #define THR 0x00 //write-only,LCR[7]=0 #define ISR 0x02 //Read=only,LCR[7]=0 #define FCR 0x02 //Write-only,LCR[7]=0 #define LCR 0x03 #define DLL 0x00 //Read/Write,LCR[7]=1,LCR!=0xBF #define DLM 0x01 //LCR[7]=1,LCR!=0xBF #define DLD 0x02 //LCR[7]=1,LCR!=0xBF,EFR[4]=1 void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output RTC_init();
2 / 14
solid
RTC_init(); }
void loop() { //step1:instruct sensor to read echoes Wire.beginTransmission(0x30); //transmit to device #48(0x30) //the address specified in the datasheet is 96(0x60) //but i2c adressing uses the high 7 bits so it's 48 Wire.send(THR); //sets register pointer to the command register(0x00) Wire.send(0x55); // sends byte Wire.endTransmission(); // stop transmitting //step2:wait for readings to happen delay(500); } int RTC_init() { Wire.beginTransmission(0x30); Wire.send( LCR<<3); Wire.send(0x80); Wire.endTransmission(); Wire.beginTransmission(0x30); Wire.send(DLM<<3); Wire.send(0x00); Wire.endTransmission(); Wire.beginTransmission(0x30); Wire.send(DLL<<3); Wire.send(0x60); Wire.endTransmission(); Wire.beginTransmission(0x30); Wire.send(LCR<<3); Wire.send(0x03); Wire.endTransmission(); } Data the serial receives see the serial debugging tools:
3 / 14
solid
NoteBefore using the SD card, format the FAT. Or you will be fail in the initialization. Arduino codes are as following:
4 / 14
solid
/* SD card read/write
This example shows how to read and write data to and from an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 10 */ #include <SD.h> File myFile; void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(10)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); //myFile.println("testing 1, 2, 3."); myFile.println("Welcome to here!"); myFile.println("Wish lucky to you!"); // close the file: myFile.close(); Serial.println("done."); } else {
5 / 14
solid
} // re-open the file for reading: myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:");
// read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } //you can delete the file you creat: /* Serial.println("Remove test.txt..."); SD.remove("test.txt"); if(SD.exists("test.txt")){ Serial.println("test.txt exists."); } else{ Serial.println("test.txt doesn't exist."); } */ } void loop() { // nothing happens after setup } Download program compilation to Arudino and open the serial assistant to watch the data needs to be stored:
6 / 14
solid
The data showed in serial assistant is which to be stored in SD card. Until now, we can shut down Arduino power, remove the SD card and use SD card reader to read the SD card content.
There is already the file named test.txt in SD card which is data file written by Arduino. Open it and you can see the internal data storage:
7 / 14
solid
Debugging finished.
8 / 14
solid
In this case, Arduino is equal to a XBEE adapter plate. Codes are wirelessly sent by the port (COM24) generated byXBEE USBA adaptor to MCU in Arduino development board. You can see Arduino runs the related results. Arduino codes void setup() { Serial.begin(57600); // start serial communication for Bluetooth } unsigned int val; void loop() { if( Serial.available() ) // if data is available to read { val=Serial.read(); Serial.println("Data received"); // Send info back } } The transmission result between two wireless modules sees Serial Monitor. Write one number in sending area, click Send and you can see:
9 / 14
solid
4 RS485 interface on expansion board testing: Hardware wiring see following picture:
Arduino codes
10 / 14
solid
RS485 Transmit Data int EN = 2; //RS485 has a enable/disable pin to transmit or receive data. Arduino Digital Pin 2 = Rx/Tx 'Enable'; High to Transmit, Low to Receive void setup() { pinMode(EN, OUTPUT); Serial.begin(9600); } void loop() { // send data digitalWrite(EN, HIGH);//Enable data transmit Serial.print('A'); delay(1000); } RS485 Receiving Data int ledPin = 13; int EN = 2; int val; void setup() { pinMode(ledPin, OUTPUT); pinMode(EN, OUTPUT); Serial.begin(9600); } void loop() { // receive data digitalWrite(EN, LOW);//Enable Receiving Data val = Serial.read(); if (-1 != val) { if ('A' == val) { digitalWrite(ledPin, HIGH); delay (500); digitalWrite(ledPin, LOW); delay(500); } } }
11 / 14
solid
shinning by the intervals 0.5S.
Write codes into two Arduino separately. SCK light on the receiving terminal expansion board will be
The chip of this set APC220 USB adapter is CP2102. Download drive file cp210x_vcp_win2k_xp_s2k3.zip and finish the installation. Insert the USB adapter into the USB interface on PC. Find the serial simulated by cp2102 (default is COM25). Now you can connect one APC220 module to USB adapter. As the pin quantity on USB adapter is different from APCs, attention to the inserting position when do the connection:
12 / 14
solid
Open the setting program RF-ANET provided by APC220 manufacturer. However, the RF-ANET program can not open it (COM25) normally. In device manager, set the serial to COM2 (the smaller COM number), and re-insert the USB adapter and open RF-ANET. Click Read button. If everything is fine, the status bar shows read succeed which means can communicate with APC220 normally.
Now, the testing environment of APC220 on PC port has been finished. Plug another APC220 TO Arduino sensor module. Set the default Baud rate be 9600. You can use following codes to test. Attention that when download programs to Arduino, remove the APC2220 module first, or it may cant download normally.
Arduino codes
solid
void setup() { Serial.begin(9600); }
void loop() { val = Serial.read(); if (-1 != val) { if ('A' == val || 'a' == val) { Serial.println("Hello from Arduino!"); }else if ('B' == val || 'b' == val) { digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); } } }
Connect one APC220 module to PC and Arduino separately and has written the related testing codes into Arduino. First of all, we have to use external power to supply the Arduino. When connect to APC220 USB adapter, open Arduino. Choose COM2 simulated by USB adapter in the menu Tools -> Serial Ports. Then, open the Serial Monitor in Arduino. Send character A. It will receive Hello from Arduino! returned from Arduino. Send character B can light on LED 13 on Arduino (lasting 0.5S):
14 / 14