Last active
August 29, 2015 13:57
-
-
Save circuitsenses/9746573 to your computer and use it in GitHub Desktop.
nRF24L01+ RXTX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include "nRF24L01.h" | |
#include "RF24.h" | |
// Teensy 3.0 | |
#define CE_PIN 5 | |
#define CS_PIN 10 | |
// Config Radio (CEPin, CSPin) | |
RF24 radio(CE_PIN, CS_PIN); | |
// Radio transmit pipe addresses | |
const uint64_t pipe = 0xE8E8F0F0E1LL; | |
int txdata[1] = {0xA5}; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Starting up RF24\n"); | |
delay(1000); | |
radio.begin(); | |
// optionally, increase the delay between retries & # of retries | |
radio.setRetries(15,1); | |
// Serial.println("Setting up channel"); | |
radio.setChannel(115); | |
radio.setPALevel(RF24_PA_MAX); | |
radio.openWritingPipe(pipe); | |
} | |
void loop() { | |
bool sent = false; | |
sent = radio.write(txdata, sizeof(int)); | |
Serial.println(); | |
if(!sent){ Serial.println("ON Byte Tx Failure"); } | |
delay(50); | |
txdata[0] = 0x5A; | |
sent = radio.write(txdata, sizeof(int)); | |
Serial.println(); | |
if(!sent){ Serial.println("OFF Byte Tx Failure"); } | |
delay(100); | |
txdata[0] = 0xA5; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <RF24.h> | |
#include <SPI.h> | |
// Teensy 3.1 | |
#define CE_PIN 9 | |
#define CS_PIN 10 | |
#define LED_PIN 3 | |
// Config Radio (CEPin, CSPin) | |
RF24 radio(CE_PIN, CS_PIN); | |
// Radio transmit pipe addresses | |
const uint64_t pipe = 0xE8E8F0F0E1LL; | |
int txdata; | |
void setup() { | |
pinMode(LED_PIN, OUTPUT); | |
Serial.begin(9600); | |
delay(1000); | |
Serial.println("Starting up RF24\n"); | |
radio.begin(); | |
// optionally, increase the delay between retries & # of retries | |
radio.setRetries(15,1); | |
// Serial.println("Setting up channel"); | |
//radio.setPayloadSize(8); | |
radio.setChannel(115); | |
radio.setPALevel(RF24_PA_MAX); | |
radio.openReadingPipe(1, pipe); | |
//radio.setAutoAck(false); | |
radio.startListening(); | |
digitalWrite(LED_PIN, LOW); | |
} | |
void loop() { | |
//delay(2000); | |
if(radio.available()) | |
{ | |
bool done = false; | |
while(!done) | |
{ | |
done = radio.read(&txdata, sizeof(int)); | |
if(txdata == 0xA5){ digitalWrite(LED_PIN, HIGH); } | |
if(txdata == 0x5A){ digitalWrite(LED_PIN, LOW); } | |
} | |
} | |
else | |
{ | |
//Serial.println("No Radio Detected"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment