Arduino NRF24L01 Скачать руководство пользователя страница 10

Receiver Code

1./*
2.* Arduino Wireless Communication Tutorial
3.* Example 2 - Receiver Code
4.* 
5.* by Dejan Nedelkovski, www.HowToMechatronics.com
6.* 
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
9.#include <SPI.h>
10.#include <nRF24L01.h>
11.#include <RF24.h>
12.#include <Servo.h>
13.#define button 4
14.RF24 radio(7, 8); // CE, CSN
15.const byte addresses[][6] = {"00001", "00002"};
16.Servo myServo;
17.boolean buttonState = 0;
18.void setup() {
19.pinMode(button, INPUT);
20.myServo.attach(5);
21.radio.begin();
22.radio.openWritingPipe(addresses[0]); // 00002
23.radio.openReadingPipe(1, addresses[1]); // 00001
24.radio.setPALevel(RF24_PA_MIN);
25.}
26.void loop() {
27.delay(5);
28.radio.startListening();
29.if ( radio.available()) {
30.while (radio.available()) {
31.int angleV = 0;
32.radio.read(&angleV, sizeof(angleV));
33.myServo.write(angleV);
34.}
35.delay(5);
36.radio.stopListening();
37.buttonState = digitalRead(button);
38.radio.write(&buttonState, sizeof(buttonState));
39.}
40.}

Содержание NRF24L01

Страница 1: ...le Hello World message from one Arduino to another and in the second example we will have a bi directional communication between the Arduino boards where using the Joystick at the first Arduino we wil...

Страница 2: ...ch unit can communicate with up to 6 other units at the same time The power consumption of this module is just around 12mA during transmission which is even lower than a single LED The operating volta...

Страница 3: ...used for setting the module in standby or active mode as well as for switching between transmit or command mode The last pin is an interrupt pin which doesn t have to be used So once we connect the NR...

Страница 4: ...al 3 Example 1 Transmitter Code 4 5 by Dejan Nedelkovski www HowToMechatronics com 6 7 Library TMRh20 RF24 https github com tmrh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF2...

Страница 5: ...rh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF24 radio 7 8 CE CSN 13 const byte address 6 00001 14 void setup 15 Serial begin 9600 16 radio begin 17 radio openReadingPipe 0...

Страница 6: ...t the same address and in that way we enable the communication between the two modules 1 radio openReadingPipe 0 address Then using the radio setPALevel function we set the Power Amplifier level in ou...

Страница 7: ...ments called text in which we will save the incoming data 1 void loop 2 if radio available 3 char text 32 4 radio read text sizeof text 5 Serial println text 6 7 Using the radion read function we read...

Страница 8: ...Joystick Module Amazon Arduino Board Amazon Servo Motor Amazon Pushbutton Amazon LED Amazon...

Страница 9: ...addresses 6 00001 00002 15 boolean buttonState 0 16 void setup 17 pinMode 12 OUTPUT 18 radio begin 19 radio openWritingPipe addresses 1 00001 20 radio openReadingPipe 1 addresses 0 00002 21 radio setP...

Страница 10: ...1 00002 16 Servo myServo 17 boolean buttonState 0 18 void setup 19 pinMode button INPUT 20 myServo attach 5 21 radio begin 22 radio openWritingPipe addresses 0 00002 23 radio openReadingPipe 1 address...

Страница 11: ...d the data to the receiver 1 radio stopListening 2 int potValue analogRead A0 3 int angleValue map potValue 0 1023 0 180 4 radio write angleValue sizeof angleValue On the other side using the radio st...

Страница 12: ...but some talented people have written Arduino libraries that make them easy to us They all use the same pinout as shown in the following diagram which is a TOP VIEW Correction Here are details of the...

Страница 13: ...o 3 3V not 5 0V although the Arduino itself may run at 5 0V and the signals will be OK The NRF24L01 IC is a 3 3V device but its I O pins are 5 V tolerant which makes it easier to interface to Arduino...

Страница 14: ......

Отзывы: