极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12418|回复: 4

用超再生模块传输数据

[复制链接]
发表于 2015-3-31 22:23:19 | 显示全部楼层 |阅读模式
淘宝上大把的315与433MHZ超再生模块一组才三五块,价钱可说是非常的平易近人
上次有人在论坛提到修改红外线库来控制这模块,这次就介绍个更方便用的库:RadioHead
首先是库的官网:http://www.airspayce.com/mikem/arduino/RadioHead/
下载连结:http://www.airspayce.com/mikem/a ... /RadioHead-1.41.zip

硬件连接方式很简单,发送端默认D12脚,接收端默认D11脚,加上电源与接地就各三条线
想试试效果可以先用库提供的范例,下一篇再做说明

发送端:
  1. // ask_transmitter.pde

  2. #include <RH_ASK.h>
  3. #include <SPI.h> // Not actually used but needed to compile

  4. RH_ASK driver;

  5. void setup()
  6. {
  7.     Serial.begin(9600);          // Debugging only
  8.     if (!driver.init())
  9.          Serial.println("init failed");
  10. }

  11. void loop()
  12. {
  13.     const char *msg = "hello";

  14.     driver.send((uint8_t *)msg, strlen(msg));
  15.     driver.waitPacketSent();
  16.     delay(200);
  17. }
复制代码


接收端:
  1. // ask_receiver.pde

  2. #include <RH_ASK.h>
  3. #include <SPI.h> // Not actualy used but needed to compile

  4. RH_ASK driver;

  5. void setup()
  6. {
  7.     Serial.begin(9600);        // Debugging only
  8.     if (!driver.init())
  9.          Serial.println("init failed");
  10. }

  11. void loop()
  12. {
  13.     uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
  14.     uint8_t buflen = sizeof(buf);

  15.     if (driver.recv(buf, &buflen)) // Non-blocking
  16.     {
  17.         int i;

  18.         // Message with a good checksum received, dump it.
  19.         driver.printBuffer("Got:", buf, buflen);
  20.     }
  21. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2015-3-31 22:44:40 | 显示全部楼层
参数设置在这行:RH_ASK driver;
这个库默认的传输速度:2000bps,接收端D11,发送端D12
例如RH_ASK driver(3000,9,10); 表示传输速度3Kbps,接收端D9,发射端D10
可发送的内容是任何uint8_t的阵列,或者说是byte或char阵列如发送范例使用的一样
接收端基本上照著发送端设置,接收到的讯息可以直接从buf[]中取回

另外,真的不要期待这模块的速度,而且还存在同频率的模块间干扰问题
回复 支持 反对

使用道具 举报

发表于 2015-10-5 17:14:25 | 显示全部楼层
同频率干扰?不能像nrf设置收发ID么?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-10-5 20:19:35 | 显示全部楼层
從庫文件看是沒有設定收發位址的功能,多組使用應該會干擾
買了一組315模塊做遙控車,發現反應很慢就丟著了
回复 支持 反对

使用道具 举报

发表于 2015-10-6 12:01:18 | 显示全部楼层
这库很全呀,非常好
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 18:41 , Processed in 0.047051 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表