使用 Arduino Fio 读取 xbee 的 ID 并通过串行通信发送
我正在尝试将多个 Arduino Fio 与 Xbee 作为从设备进行联网,将我的计算机作为主设备与 Explore 和 Xbee 进行联网。
假设我通过串口向所有 Arduino 发送并命令“读取”。每个人都回答“好吧”。
我的问题是让它们做出类似“Arduino ID1 说 OK”或“Arduino ID2 说 OK”等的响应。
现在,每个 arduino 都烧录了单独的程序,这可能很容易。但就我而言,所有 arduino 都应该具有相同的程序。
我知道我们在第一次配置 Xbee 时为其分配了 MyID 和 Pan ID。
的程序中的某些函数
所以我正在寻找烧录到 Arduino 示例“readMyXbeeID()”或其他内容
。我有什么想法可以做到这一点吗?或者还有其他方法可以实现同样的效果吗?
I am trying to network multiple Arduino Fio with Xbee as slaves and my computer as Master with an Explore and Xbee.
Suppose i send and command 'Read' over serial to all Arduinos. Everyone responds suppose 'OK'.
My problem is to make them respond something like 'Arduino ID1 says OK' or 'Arduino ID2 says OK' etc.
Now this may be easy of each arduinos have separate programs burnt into them. But in my case all arduinos are suppose to have identical programs.
I know we assign MyID and Pan ID to each Xbee while configuring them for the first time.
So i am looking for some function in the program burnt into the Arduinos example
'readMyXbeeID()' or something.
Any ideas how i can do this? Or any other way to achieveArd the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以使用 AT 命令获取 MYID。
您需要阅读 XBEE 文档来确认这些。
使用
“+++”
进入命令模式(不要忘记>一秒的延迟来“保护”此序列)。{ 我使用:延迟(1200); Serial.print ( "+++" ) ; }
XBEE
将响应OK\r
。然后
ATMY\r
将为您提供MYID,返回为以“\r”结尾的 ascii 字符串
。[在我的例子中,我将
MYID
设置为 2,因此我看到了字符串"2\r"
]使用命令
ATCN\r
完成退出命令模式。I was able to get MYID by using AT commands.
You will need to read the XBEE documentation confirm these.
Use
"+++"
to get in to command mode (not forgetting the > one second delay to 'guard' this sequence).{ I used:
delay(1200); Serial.print ( "+++" ) ;
}The
XBEE
will respondOK\r
.Then
ATMY\r
will give youMYID returned as an ascii string terminated with "\r"
.[In my case I had set a
MYID
of 2 so I saw the string"2\r"
]Finish with the command
ATCN\r
to exit command mode.如果您想管理与多个设备的通信,我建议您使用API模式而不是AT模式。如果您使用 Arduino,有一些非常好的库:Xbee-Api 和XBee-Arduino。在这里您将找到可能对您的项目有所帮助的有用信息和示例。
我用这些库指导了一些项目(ZigBee 技术的完全初学者),他们很快就掌握了所有概念。 100%值得推荐。
关于你的问题,你为所有 Arduino 编写一个程序是正确的。否则,您将必须为每个节点创建不同的十六进制文件,这是没有意义的。识别 ZigBee 节点的最简单方法就是使用 64 位物理地址。您可以通过 AT 命令轻松获取该地址。但请记住,在 API 模式下,每当您发送消息时,源地址都会自动包含在帧中,因此您不必显式包含此信息。
If you want to manage communications with several devices, I recommend you to use the API mode instead of the AT mode. If you are working with Arduino, there are some really good libraries: Xbee-Api and XBee-Arduino. Here you will find useful information and examples that may help in your project.
I mentored a few projects with these libraries (complete beginners in ZigBee technology), and they got all concepts really fast. 100% recomendable.
Regarding your question, you are right about writing just one program for all Arduinos. Otherwise you will have to create different hex-files for each node, which makes no sense. The easiest way for identifiying the ZigBee nodes is just using i.e. the 64-bit physical address. You can get this address easily through AT Commands. But keep in mind that in API Mode, whenever you send a message, the source address is automatically included in the frame, so you do not have to include explicity this information.