简体   繁体   English

使用433 MHz发送器/接收器将消息从一个arduino发送到另一个

[英]Sending a message from one arduino to the other using 433 mhz transmitter/receiver

Today I got some cool radio receiver and transmitter the problem is that when I type the message I want to send it spits out gibbirish on the other arduino. 今天,我有了一些很酷的无线电接收器和发射器,问题是当我键入该消息时,我想发送该消息时会吐出另一个arduino上的乱码。

//transmitter
#include <VirtualWire.h>

void setup()
{
  Serial.begin(9600);
  vw_set_ptt_inverted(true);
  vw_setup(3000);
  vw_set_tx_pin(7);
}

void loop()
{
  String inData;

  while(Serial.available())
  {
    char recieved = Serial.read();
    inData += recieved; 
    char bits[inData.length()];

    Serial.print(":");
    Serial.print(inData);


    for(int i=0;i<inData.length();i++)
    {
    bits[i] = inData.charAt(i);

    vw_send((uint8_t *)bits[i], 1);
    }

    inData = "";
    delay(50);
  }
}

//below is the receiver! //下面是接收者!

#include <VirtualWire.h>

void setup()
{
  vw_set_ptt_inverted(true);
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  Serial.begin(9600);
  vw_setup(3000);
  vw_set_rx_pin(7);
  vw_rx_start();
}

void loop()
{
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  uint8_t buf[buflen];

  if(vw_get_message(buf, &buflen))
  {
    for(int i = 0;i < buflen;i++)
    {
     char c = buf[i];
     Serial.println(c,DEC);

      delay(50);
    }
  }
}

So if i type in "hello", on the other serial port I will see "0 53 0 0 2" which is weird due to the fact that I always get the same amount of characters but not the actual character I want. 因此,如果我键入“ hello”,则在另一个串行端口上,我会看到“ 0 53 0 0 2”,这很奇怪,因为我总是得到相同数量的字符,但不是我想要的实际字符。

So I do not have an answer per se, as I do not know that it will help, but I noticed some quirks in your code. 所以我本身没有答案,因为我不知道这会有所帮助,但是我注意到您的代码中有一些怪癖。

I noticed that you configure the pin for OUTPUT in the receiver, yet you want it to act as a receiver. 我注意到您在接收器中配置了OUTPUT的引脚,但是您希望它充当接收器。 I am not familiar enough with Arduino hardware and its configurations, but be sure that setting it to OUTPUT will not affect its ability to be driven by a transmitter. 我对Arduino硬件及其配置还不太熟悉,但是请确保将其设置为OUTPUT不会影响其由发送器驱动的能力。 What could likely be happening is that there is contention on the line - your transmitter is sending out the data, but the receiver is trying to hold the line LOW , leading to garbage data (with the same number of characters you transmitted!). 可能发生的情况是线路上存在争用-发送器正在发送数据,但是接收器试图将线路保持为LOW ,从而导致垃圾数据(具有与您发送的字符数相同的字符!)。

Also, based on the samples posted here , it seems that you need to define the transmit enable pin in both cases. 此外,根据此处发布的示例,似乎在两种情况下都需要定义发送使能引脚。 It looks like the library has an interrupt service routine that relies on that PTT line to indicate a start of transmission. 似乎该库具有一个中断服务例程,该例程依赖于该PTT行来指示传输开始。 That can cause a lot of problems for either end which may be relying on a PTT interrupt to send out or receive a signal, especially if flow control is involved. 这可能会给两端带来很多问题,可能依赖于PTT中断发送或接收信号,尤其是在涉及流控制的情况下。

Lastly, the example code makes use of a vw_wait_tx() function call before sending out more data. 最后,示例代码在发送更多数据之前利用vw_wait_tx()函数调用。 You are only waiting 50ms before trying to do another TX operation, which may not be enough time for the transmitter to finish sending out whatever data it has. 您只需要等待50毫秒,然后再尝试执行另一次TX操作,这可能不足以使发送器完成发送出的所有数据。 I do not know the specific implementation of the library, but I would definitely use this function to be sure that you are not trying to send out more data than the port can handle. 我不知道该库的具体实现,但是我肯定会使用此功能来确保您不会发送超出端口可以处理的数据量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用C从一个发送器到一个接收器读写文件(视频或图片格式) - Reading and writing a file (in video or picture format)in C, from one transmitter to a receiver 使用结构将浮点数从 Arduino 发送到 Python - Sending floats from Arduino to Python using a struct 设计面向对象的同步接收器和发送器 - Designing object oriented synchronous receiver and transmitter C Linux pthreads:使用消息队列将数据从一个线程发送到另一个线程会产生意外结果 - C Linux pthreads: sending data from one thread to antoher using message queue gives unexpected result 如何从接收者向发送者发送 NACK 消息 - How to send NACK message from receiver to sender 将浮点类型数据从Arduino发送到Python - Sending float type data from Arduino to Python 从处理发送字符串到Arduino无法正常工作 - Sending String from Processing to Arduino Not Working 使用radio.write()发送小数 与Arduino - Sending decimals using radio.write(); with Arduino 使用Amarino将数据结构从Arduino发送和接收到Android(反之亦然) - Sending and recieving data structs from Arduino to Android (and vice versa) using Amarino Arduino 上未声明变量的错误消息,使用 typedef - Error message for undeclared variable on Arduino, using typedef
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM