NRF24L01

Used Products:

1. Arduino UNO
2. NRF24L01

Content:

Çeşme: http://www.bajdi.com/rf24-library-revisited/ http://hack.lenotta.com/arduino-nrf24l01-modules-testing/

Used Libraries:

1. RF24

Code:

Transmitter.ino ----------------------- /* http://www.bajdi.com This sketch transmits 2 analog values through an nRF24L01 wireless module. http://shanes.net/another-nrf24l01-sketch-string-sendreceive/ */ #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" #define ledPin 13 #define buttonBluePin 2 #define buttonGreenPin 3 #define buttonRedPin 4 #define ARRAY_SIZE 5 int joystick[ARRAY_SIZE]; RF24 radio(9,10); const uint64_t pipe = 0xE8E8F0F0E1LL; unsigned long lastConnectionTime = 0; const unsigned long postingInterval = 3L * 1000L; void setup(void) { Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(buttonBluePin, INPUT); pinMode(buttonGreenPin, INPUT); pinMode(buttonRedPin, INPUT); radio.begin(); radio.openWritingPipe(pipe); } void loop(void) { int buttonBlueState = digitalRead(buttonBluePin); int buttonGreenState = digitalRead(buttonGreenPin); int buttonRedState = digitalRead(buttonRedPin); digitalWrite(ledPin, buttonBlueState==1||buttonGreenState==1||buttonRedState==1); joystick[0] = -1; joystick[1] = buttonBlueState; joystick[2] = buttonGreenState; joystick[3] = buttonRedState; joystick[4] = 2; int r = radio.write( joystick, sizeof(joystick) ); Serial.println(r); radio.powerDown(); delay(3); radio.powerUp(); } Receiver.ino ----------------------- /* http://www.bajdi.com This sketch receives 2 analog values through an nRF24L01 wireless module. http://shanes.net/another-nrf24l01-sketch-string-sendreceive/ wifi shield problem solved ----------------------------- Pin 10 selects Ethernet/Wifi shield. Pin 8 selects NRF24L01 module, pin 9 enables module. (8-9 in my sketch, you can modify it) 11,12 and 13 are commons. https://github.com/maniacbug/RF24Network/issues/14 */ #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" #define ARRAY_SIZE 5 #define BLUE_LED_PIN 2 #define GREEN_LED_PIN 3 #define RED_LED_PIN 4 int joystick[ARRAY_SIZE]; RF24 radio(9,10); const uint64_t pipe = 0xE8E8F0F0E1LL; void setup(void) { pinMode(BLUE_LED_PIN, OUTPUT);pinMode(GREEN_LED_PIN, OUTPUT);pinMode(RED_LED_PIN, OUTPUT); Serial.begin(9600); radio.begin(); radio.openReadingPipe(1,pipe); radio.startListening(); } void loop(void) { if ( radio.available() ) { // Dump the payloads until we've gotten everything bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. radio.read( joystick, sizeof(joystick) ); if (joystick[0] == -1) { for (int i = 0; i < ARRAY_SIZE; i++) { Serial.print(joystick[i]); Serial.print(","); } Serial.println(); digitalWrite(BLUE_LED_PIN, joystick[1]==1); digitalWrite(GREEN_LED_PIN, joystick[2]==1); digitalWrite(RED_LED_PIN, joystick[3]==1); } } } else { Serial.println("No radio available"); } }