我们需要什么? 列表: 1。 1个 Arduino NANO或Pro mini(小尺寸) 2。NRF24L01无线电模块 3。4个可调电阻(这可能是一个高价购买。我所做的是从旧的遥控器拆出2个操纵杆) 4。串行TTL / FTDI FT232RL模块(如果您使用得是Pro mini) 5。9V电池 6。电线,导线,焊锡,烙铁...... 小介绍 我们想要做的是将4个电位器连接到arduino的模拟输入,并使用NRF24模块将每个输入值发送到接收器。我们将创建4个无线电通道,我们将读取4个模拟输入中的每一个,将值映射到所需范围,并使用8位通道为每个输入发送每个值。 如果您使用的是Arduino NANO,则不需要FTDI模块来编程微控制器。首先,我们必须烧录我们的Arduino。为此,我们将9V电池直接连接到RAW输入引脚和arduino接地。启动板必须有自己的5V或3.3V稳压器。NRF24模块使用大量的电流,因此我们不会从arduino的3.3V输出供电。我们将使用外部3.3电压调节器代替。给这个模块施加一个更高的电压,它会在瞬间烧毁,所以要小心。我们必须在NRF24模块和Arduino之间共享。无线电模块的引脚连接如上图所示。我们需要做的就是将每个电位器的中间引脚连接到arduino的模拟输入。连接5V并接地到每个电位器的其他2个引脚,我们完成了。 我们现在需要做的就是编程微控制器并开始发送数据。 下面为控制代码,使用Arduino IDE1.6.0环境编写 /* //4 channels transmitter */ #include #include #include const uint64_t pipeOut = 0xE8E8F0F0E1LL; //This same code should be in the receiver as well RF24 radio(9, 10); //select CE and CSN pins //We can have up to 32 channels of 8 bits struct MyData { byte throttle; //We define each byte to an analog input byte yaw; byte pitch; byte roll; }; MyData data; void resetData() { //We define the start value of our data data.throttle = 0; data.yaw = 127; data.pitch = 127; data.roll = 127; } void setup() { radio.begin(); radio.setAutoAck(false); radio.setDataRate(RF24_250KBPS); radio.openWritingPipe(pipeOut); resetData(); } /**************************************************/ // We map the values from 0-1024 a 0-255, //because we have 8 bits channels and 8 bits = 254, //once we receive the values in the receiver we can map the values once again so don't worry int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse) { val = constrain(val, lower, upper); if( val < middle=""> val = map(val, lower, middle, 0, 128); else val = map(val, middle, upper, 128, 255); return ( reverse ? 255 - val : val ); } void loop() { // We read the analog input values //Set to 'true' it will invert the value reading //Set to 'false' it will use values from 0 to 1024 //This part is just in case you connect the pontenciometers reversing the wires //and to adjust the values data.throttle = mapJoystickValues( analogRead(0), 13, 524, 1015, true ); data.yaw = mapJoystickValues( analogRead(1), 1, 505, 1020, true ); data.pitch = mapJoystickValues( analogRead(2), 12, 544, 1021, true ); data.roll = mapJoystickValues( analogRead(3), 34, 522, 1020, true ); radio.write(&data, sizeof(MyData));//Enviamos los datos } |
|