在pcduino上搭载Xbee Shield

酸酸苹果汁 发布于 2014/01/16 13:55
阅读 215
收藏 1

Xbee shield能使一块Arduino板通过一些无线通讯模块比如蓝牙或者zigbee等达到短程的无线通讯效果。你可以把它看成是串口或者USB的替代品。它可以使2个Arduino达到通讯效果,甚至可以实现Arduino和pc之间的无线通讯。

Xbee-02

实验元件

arduino x 1

pcduino x 1

Xbee sheild x 2

Xbee module x 2

T-board x 1

面包板 x 2

杜邦线若干

连线图

Xbee-arduinoXbee-pcduinoIMG_20131125_092407

注意:pcduino上面需要装上T-board 并且把开关拨到+5V的位置

实验代码

arduino 代码:

#define led_pin 9
#define button_pin 10
void setup()
{
pinMode(led_pin,OUTPUT);
pinMode(button_pin,INPUT);
digitalWrite(led_pin,HIGH);
Serial.begin(9600);
}
void loop()
{
if(digitalRead(button_pin)==LOW)
{
while(digitalRead(button_pin)==LOW){;}
Serial.print(‘a’);
}
/*
if(digitalRead(button_pin) == LOW){
delay(30);
if(digitalRead(button_pin)==LOW)
Serial.print(‘a’);
delay(200);
}
*/
if (Serial.available() > 0)
{
unsigned char word;
word = Serial.read();
if(word == ‘a’)
{
digitalWrite(led_pin,LOW);
delay(1500);
digitalWrite(led_pin,HIGH);
}
}
}

pcduino代码:

#include <core.h>
#include “Serial.h”

#define led_pin 9
#define button_pin 10
#define rate 9600
unsigned char flag = 0;

void setup(){
pinMode(led_pin,OUTPUT);
digitalWrite(led_pin, HIGH);
pinMode(button_pin,INPUT);
Serial.begin(rate);
}

void loop(){
if(Serial.available() > 0){
char receive = Serial.read();
if(receive) {
flag++;
printf(“the data received is %c\n”,receive);
}
if((flag % 2) == 0) {
digitalWrite(led_pin,LOW);
printf(“led on\n”);
}
else {
digitalWrite(led_pin,HIGH);
printf(“led off\n”);
}
}
//delay(1000);
if(digitalRead(button_pin)==LOW){
delay(10);
if(digitalRead(button_pin)==LOW){
Serial.print(‘b’);
}
}
//unsigned int value1 = digitalRead(led_pin);
//unsigned int value2= digitalRead(button_pin);
//printf(“led_pin = %d,button_pin = %d\n”,value1,value2);
delay(1000);
}

效果图

按下arduino对应的面包板电路的按钮,pcduino上面的led会亮屏幕打印“led on”,再按一下pcduino上面的灯熄灭并显示”led off”,并打印接收到得数据。

IMG_20131121_172157IMG_20131121_172530IMG_20131121_172521


linksprite学习中心


加载中
0
mickelfeng
mickelfeng
不错。不知道硬件贵不。像我等屌丝能买得起不
0
酸酸苹果汁
酸酸苹果汁

不贵,买的起得,淘宝链接你去上面看看http://lsprite.taobao.com/shop/view_shop.htm?spm=a1z09.1.0.310.k62YeK&mytmenu=mdianpu&utkn=g,nruw423tobzgs5dfgiydcmi1372057745187&user_number_id=774781652&scm=1028.1.1.20001

返回顶部
顶部