【发布时间】:2015-08-17 00:51:52
【问题描述】:
我无法理解我在 Arduino 设置中得到了什么。
场景是: 我使用运行 virtualwire 的芯片组将字符 A(可以是任何字符)从 TX 板发送到 RX 板。 RX 正在接收消息,缓冲区长度为 1。当我在串行监视器上打印出 buf[i] 时,我得到 255(这是我假设的最大 8 位整数)而不是字符 A。这是相关代码:
TX 文件 [代码] 无效设置(){
c = 'A'; //仅供测试
// 无线代码...TX 上的数据引脚连接到端口 7...vw 代表“virtualwire”
vw_setup(2000); // 初始化 tx 传输速率 vw_set_tx_pin(7); // 声明用于发送数据的 arduino 引脚 ...
空循环() {
... vw_send((uint8_t *)c, 1); // 打开蜂鸣器...发送字符
RX 文件
// RX数据引脚为8
空循环() {
Serial.println("Looping");
delay(2000);
uint8_t buflen = VW_MAX_MESSAGE_LEN;// Defines maximum length of message
uint8_t buf[buflen]; // Create array to hold the data; defines buffer that holds the message
if(vw_have_message() == 1) // Satement added by virtualwire library recommendation as one of three statements to use before the get_message statement below// not in original HumanHardDrive code
{
Serial.println("Message has been received");
}
if(vw_get_message(buf, &buflen)) // &buflen is the actual length of the received message; the message is placed in the buffer 'buf'
{
Serial.print("buflen from &buflen = ");
Serial.println(buflen); // Print out the buffer length derived from the &buflen above
for(int i = 0;i < buflen;i++)
{
Serial.print("i = ");
Serial.println(i); <--prints 0
Serial.print(" buf[0] = ");
Serial.print(buf[0]); <--prints 255
Serial.print(" buf[i] = ");
Serial.println(buf[i]); <--prints 255
if(buf[i] == 'A') <-- Does not recognize A since buf[i] comes out as 255
[/代码]
感谢您的任何建议!
【问题讨论】:
标签: arduino buffer wireless transmission