Xbee arduino通讯编程
xbee arduino communication programming
我试着测试系统,我不确定问题是与xbee的,发送代码,还是接收代码。在我发布我的代码之前,我将解释我们正在用信号做什么。我们有三个模拟信号,将使用arduino和xbee屏蔽通过一个xbee串行发送。我们希望将这些信号发送到接收xbee, arduino将输出这些信号,通过导线连接到第三个arduino,用于Simulink程序。我们使用arduino mega作为发送端,arduino uno作为接收端。我被告知我需要做串行流,但我不确定如何做到这一点。我知道xbee和arduinos都是数字化信号,但我们希望得到的信号非常类似于我们正在传输的模拟信号。任何数量的帮助是非常感激的!!
以下是我在AT模式下配置xbees(系列1)的方式:
传输Xbee:
频道:10
Pan id: 1234
我:10
DL: 11
收到Xbee:
频道:10
Pan ID: 1234
我:11
DL: 10
传输Arduino代码:
void setup() {
Serial.begin(9600);
}
void loop() {
// read the input on analog pins
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);
// print out the value you read:
Serial.println(sensorValue1);
Serial.println(sensorValue2);
Serial.println(sensorValue3);
delay(1);
}
接收Arduino代码:
int received1=8;
int received2=9;
int received3=10;
void setup(){
pinMode(received1, OUTPUT);
pinMode(received2, OUTPUT);
pinMode(received3, OUTPUT);
Serial.begin(9600);
}
void loop(){
if(Serial.available() )
{
byte output1 = Serial.read();
byte output2 = Serial.read();
byte output3 = Serial.read();
digitalWrite(received1, HIGH);
digitalWrite(received2, HIGH);
digitalWrite(received3, HIGH);
}
}
听起来你正在使用"AT模式"或"透明串行"模式下的XBee模块,其中模块A的串行端口上接收的任何内容都是从模块B的串行端口发送出去的,反之亦然。
如果是这种情况,那么将两个设备的串行端口直接连接在一起进行初始开发可能会有所帮助。在那里找出您的串行协议,然后尝试在XBee模块作为串行电缆替代品的情况下运行它。
考虑你发送的数据的格式,以及你将如何在另一端处理它。如何分离读数并确定它们属于哪个模拟输入?使用当前的代码,您将读数打印在单独的行上,但不清楚哪个是A0
。也许你想把它们写成一行,每次阅读之间用逗号隔开?
在接收端,您需要使用atoi()
或strtoul()
等C函数将文本转换回整数。
如果您试图在Arduino上创建模拟输出,则可能使用PWM(脉宽调制)的数字输出。
- Arduino 模块化编程与全局和设置
- 使用 Arduino 对 ATtiny10 进行编程 ( "ld.exe" 错误)
- 尝试用纯 c 编程 arduino,得到以下错误:预期的"="、""、";",'asm'或"打印"之前的'__attribute__'|
- 当您希望在Arduino Uno编程中同时执行不同函数时,使用什么代码/语句
- 如何使用 3 个按钮对 Arduino 菜单进行编程?
- Arduino 阵列编程
- 在arduino上编程atmega328p的UART
- 在没有IDE(Linux)的情况下编程Arduino DUE
- 使用Arduino IDE编程是否适合商业产品
- 用Arduino编程一个简单的按钮LED电路
- 如何使用Arduino开始与完成的硬件进行编程/通信
- 使用 Arduino 进行 LCD 编程
- 什么编程语言最适合通过Arduino上的传感器控制屏幕上的动画?Java语言C++
- Arduino编程错误
- 如何使用c++ 11对Arduino进行编程?
- 在Arduino中编程时避免使用指针和#define
- 编译和上传到Arduino编程
- Arduino编程中的结构体数组
- 编程 Arduino 与标准 C 有何不同
- 用Visual c++编程arduino串口