debugging steps of xbee sensor expansion board

14
solid Wuxi SuT eng Solid Digital Technologies Co ,.Ltd Tel+86-510-85387391 Fax+86-510-85387691 Webwww.soliddigi.com Mail[email protected] Online storewww.soliddepot.com Skype jessicadong6 1 / 14 rduino XBee Sensor Expansion Board Debugging Arduino is the open source control board. This module is senor expansion board compatible Arduino. It is not only expand the existing interfaces such as data/analog port on the Arduino board, IIC interface, SPI interface, but also the RS485, SD card module interface, Xbee/Bluetooh Bee Bluetooth wireless data transmission interface and APC220/Bluetooh V3 Bluetooth wireless data transmission interface which makes the connection of most sensors to Arduion very easily. It can do you a favor in your electronic production with Arduino. Function diagram. NoteBefore power on, use multimeter to test the board. Check whether the main power is short to GND

Upload: soliddigi

Post on 04-Mar-2015

88 views

Category:

Documents


0 download

DESCRIPTION

Debugging Steps of XBee Sensor Expansion Board

TRANSCRIPT

Page 1: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

1 / 14

rduino XBee Sensor Expansion Board Debugging

Arduino is the open source control board. This module is senor expansion board compatible Arduino. It

is not only expand the existing interfaces such as data/analog port on the Arduino board, IIC interface,

SPI interface, but also the RS485, SD card module interface, Xbee/Bluetooh Bee Bluetooth wireless

data transmission interface and APC220/Bluetooh V3 Bluetooth wireless data transmission interface

which makes the connection of most sensors to Arduion very easily. It can do you a favor in your

electronic production with Arduino.

Function diagram.

Note::::Before power on, use multimeter to test the board. Check whether the main power is short to GND

Page 2: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

2 / 14

or not. Protect the board from burnt.

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();

Page 3: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

3 / 14

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:

Page 4: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

4 / 14

2、 SPI interface testing on the expansion board:

SPI interface on this board is compatible with SD card storage module. SD card storage module can be

inserted directly for using. Hardware see following photo:

Note::::Before using the SD card, format the FAT. Or you will be fail in the initialization.

Arduino codes are as following:

Page 5: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

5 / 14

/*

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 {

Page 6: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

6 / 14

// if the file didn't open, print an error:

Serial.println("error opening test.txt");

}

// 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:

Page 7: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

7 / 14

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:

Page 8: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

8 / 14

Debugging finished.

3、 XBee/Bluetooh Bee Bluetooth wireless transmission interface testing

The testing uses Wireless Programming Module which uses XBEE design and compatible with XBee

module’s expansion board. It can achieve the download to Arduino wireless program in certain range. It

also can be used as general wireless data transmission module (UART interface). This wireless module

Baud rate can be debugged in 2.4-2.5GHz. The maximum value of Baud rate register is 125 and the unit

debugging frequency is 0.0008GHz. The same set Baud rate is necessary for the communication. This

module has only 4 commands. The register needs to be configured one by one. You can’t configure

them in one time.

When set the module, toggle the toggle switch 1: MODE to the left (ON). In this case, the blue LED turns

on. Toggle switch 2: toggle PROG_EN to right (this switch is used for manufacturer’s programming only.

User is forbidden to use it). When the module specifications’ configuration is finished, toggle MODE DIP

switch 1 to right, enable the wireless receive / send mode.

Note::::Use external power to supply the Arduion. If you connect it to USB line, the corresponding FT232

module will be active. In this case, the communication will be abnormal because of the conflict between

serial achieved by FT232 and serials on wireless data transmission module.

Following is the hardware connection:

Page 9: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

9 / 14

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:

Page 10: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

10 / 14

4、 RS485 interface on expansion board testing:

Hardware wiring see following picture:

Arduino codes:

Page 11: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

11 / 14

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);

}

}

}

Page 12: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

12 / 14

Write codes into two Arduino separately. SCK light on the receiving terminal expansion board will be

shinning by the intervals 0.5S.

5、 APC220/Bluetooh V3 Bluetooth wireless transmission interface

The testing uses APC220 wireless transmission module. In the programs of achieving Arduino wireless

data transmission, the easiest way is to use wireless transmission like APC22 which achieves by serials.

Hardware wiring:

Note::::Use external power to supply the Arduion. If you connect it to USB line, the corresponding FT232

module will be active. In this case, the communication will be abnormal because of the conflict between

serial achieved by FT232 and serials on wireless data transmission module.

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 APC’s, attention to the

inserting position when do the connection:

Page 13: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

13 / 14

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 can’t download normally.

Arduino codes:

int val = 0;

int ledPin = 13;

Page 14: Debugging Steps of XBee Sensor Expansion Board

solid

Wuxi SuTeng Solid Digital Technologies Co ,.Ltd

Tel:+86-510-85387391 Fax:+86-510-85387691

Web:www.soliddigi.com Mail:[email protected]

Online store:www.soliddepot.com Skype :jessicadong6

14 / 14

void setup()

{

Serial.begin(9600); //Baud rate need to be the same as APC220

}

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):