• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
nRF24L01
#1
Witam!
Od dłuższego czasu męczę się z modułami nRF24L01. wgrywałem wiele różnych programów ale żaden nie działa. Ostatni był ze strony Arduino.   https://create.arduino.cc/projecthub/muh...ion-0c13d4
Kod nadajnika:
Kod:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN         
const byte address[6] = "00001";     //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
int button_pin = 2;
boolean button_state = 0;
void setup() {
pinMode(button_pin, INPUT);
radio.begin();                  //Starting the Wireless communication
radio.openWritingPipe(address); //Setting the address where we will send the data
radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.stopListening();          //This sets the module as transmitter
}
void loop()
{
button_state = digitalRead(button_pin);
if(button_state == HIGH)
{
const char text[] = "Your Button State is HIGH";
radio.write(&text, sizeof(text));                  //Sending the message to receiver
}
else
{
const char text[] = "Your Button State is LOW";
radio.write(&text, sizeof(text));                  //Sending the message to receiver
}
radio.write(&button_state, sizeof(button_state));  //Sending the message to receiver
delay(1000);
}
Kod odbiornika:
Kod:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
boolean button_state = 0;
int led_pin = 3;
void setup() {
pinMode(6, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening();              //This sets the module as receiver
}
void loop()
{
if (radio.available())              //Looking for the data.
{
char text[32] = "";                 //Saving the incoming data
radio.read(&text, sizeof(text));    //Reading the data
radio.read(&button_state, sizeof(button_state));    //Reading the data
if(button_state == HIGH)
{
digitalWrite(6, HIGH);
Serial.println(text);
}
else
{
digitalWrite(6, LOW);
Serial.println(text);}
}
delay(5);
}
Próbowałem na 4 modułach i zero czegokolwiek. Proszę o pomoc.
Pozdrawiam!
 
Odpowiedź
  


Wiadomości w tym wątku
nRF24L01 - przez Julek Rogalski - 18-09-2019, 23:06
RE: nRF24L01 - przez kaczakat - 19-09-2019, 00:27
RE: nRF24L01 - przez Julek Rogalski - 19-09-2019, 19:25
RE: nRF24L01 - przez kaczakat - 19-09-2019, 19:55
RE: nRF24L01 - przez Julek Rogalski - 19-09-2019, 22:38
RE: nRF24L01 - przez kaczakat - 20-09-2019, 02:45
RE: nRF24L01 - przez semi - 20-09-2019, 09:35
RE: nRF24L01 - przez kaczakat - 20-09-2019, 15:38
RE: nRF24L01 - przez Julek Rogalski - 20-09-2019, 21:15
RE: nRF24L01 - przez kaczakat - 20-09-2019, 21:59
RE: nRF24L01 - przez Julek Rogalski - 20-09-2019, 22:02
RE: nRF24L01 - przez Julek Rogalski - 20-09-2019, 22:24
RE: nRF24L01 - przez kaczakat - 21-09-2019, 00:34
RE: nRF24L01 - przez Julek Rogalski - 21-09-2019, 11:28

Skocz do:


Przeglądający: 1 gości