Skip to content

Commit

Permalink
fix rf24 module pin
Browse files Browse the repository at this point in the history
  • Loading branch information
arex.huang committed Dec 12, 2024
1 parent ccec30e commit 80813ed
Showing 1 changed file with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,23 @@ void loop() {
}
```

将示例程序`examples/gamepad_subscribe_rf24/gamepad_subscribe_rf24.ino`下载到接收端, 内容如下:
将示例程序`examples/gamepad_subscribe_rf24/gamepad_subscribe_rf24.ino`下载到接收端,

*注意***Arduino AVR NANO 和 Arduino AVR UNO 的与RF24模块连接的引脚不一样**:

| Arduino AVR UNO | RF2.4 Module |
| --- | --- |
| 10 | CE |
| 9 | CS |

| Arduino AVR NANO | RF2.4 Module |
| --- | --- |
| 7 | CE |
| 8 | CS |

所以烧录的时候选择的Arduino IDE上选择的开发板要选择正确

代码内容如下:

```c++
#include <Arduino.h>
Expand All @@ -207,9 +223,28 @@ void loop() {
emakefun::GamepadSubscriberRf24 g_gamepad_subscriber;
emakefun::GamepadModel g_gamepad_model;

#if defined(ARDUINO_AVR_UNO)
constexpr uint8_t kRf24CePin = 10;
constexpr uint8_t kRf24CsPin = 9;
#elif defined(ARDUINO_AVR_NANO)
constexpr uint8_t kRf24CePin = 7;
constexpr uint8_t kRf24CsPin = 8;
#else
#error "unsupported board type"
#endif

void setup() {
Serial.begin(115200);
g_gamepad_subscriber.Initialize(7, 8, 115, 5, 0x0011000011LL);
#if defined(ARDUINO_AVR_UNO)
Serial.println("Arduino AVR UNO");
#elif defined(ARDUINO_AVR_NANO)
Serial.println("Arduino AVR NANO");
#endif
Serial.print("rf24 ce pin: ");
Serial.print(kRf24CePin);
Serial.print(", cs pin: ");
Serial.println(kRf24CsPin);
g_gamepad_subscriber.Initialize(kRf24CePin, kRf24CsPin, 115, 5, 0x0011000011LL);
g_gamepad_subscriber.AttachModel(&g_gamepad_model);
Serial.println("setup done");
}
Expand Down Expand Up @@ -504,12 +539,10 @@ bool ButtonReleased(const ButtonType button_type) const {

`g_gamepad_model.GetGravityAcceleration().z`



以上函数直接调用即可

若遇上解决不了的问题

## 联系我们

**技术 + 合作:WX号: EmakefunService**
**技术 + 合作:WX号: EmakefunService**

0 comments on commit 80813ed

Please sign in to comment.