|
淘宝上大把的315与433MHZ超再生模块一组才三五块,价钱可说是非常的平易近人
上次有人在论坛提到修改红外线库来控制这模块,这次就介绍个更方便用的库:RadioHead
首先是库的官网:http://www.airspayce.com/mikem/arduino/RadioHead/
下载连结:http://www.airspayce.com/mikem/a ... /RadioHead-1.41.zip
硬件连接方式很简单,发送端默认D12脚,接收端默认D11脚,加上电源与接地就各三条线
想试试效果可以先用库提供的范例,下一篇再做说明
发送端: - // ask_transmitter.pde
- #include <RH_ASK.h>
- #include <SPI.h> // Not actually used but needed to compile
- RH_ASK driver;
- void setup()
- {
- Serial.begin(9600); // Debugging only
- if (!driver.init())
- Serial.println("init failed");
- }
- void loop()
- {
- const char *msg = "hello";
- driver.send((uint8_t *)msg, strlen(msg));
- driver.waitPacketSent();
- delay(200);
- }
复制代码
接收端: - // ask_receiver.pde
- #include <RH_ASK.h>
- #include <SPI.h> // Not actualy used but needed to compile
- RH_ASK driver;
- void setup()
- {
- Serial.begin(9600); // Debugging only
- if (!driver.init())
- Serial.println("init failed");
- }
- void loop()
- {
- uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
- uint8_t buflen = sizeof(buf);
- if (driver.recv(buf, &buflen)) // Non-blocking
- {
- int i;
- // Message with a good checksum received, dump it.
- driver.printBuffer("Got:", buf, buflen);
- }
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|