Created
September 21, 2016 11:22
-
-
Save pfeerick/641ff25592cc61ae22c9d6ff83c305ed to your computer and use it in GitHub Desktop.
Arduino script to receive a NRF24L01+ sensor on a Digistump Oak
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" | |
//needed for printDetails | |
#define printf Serial.printf | |
#define sprintf(...) os_sprintf( __VA_ARGS__ ) | |
#define CE_PIN 10 | |
#define CSN_PIN 5 | |
// Set up nRF24L01 radio on SPI bus plus pins 10 & 5 (CE & CSN) | |
RF24 radio(CE_PIN, CSN_PIN); | |
// Single radio pipe address for the 2 nodes to communicate. | |
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0D3LL }; | |
const int STATUS_LED = 1; | |
float temp; | |
char tmpStr[8]; | |
void setup(void) | |
{ | |
pinMode(STATUS_LED, OUTPUT); | |
Particle.begin(); //OakTerm | |
Serial.begin(115200); | |
Serial.println("Sketch starting: NRF Receiver v0.1"); | |
Particle.publish("oak/userrom/startup", "NRF Receiver v0.1", PRIVATE); | |
radio.begin(); | |
//specific to my sensor configuration | |
radio.setChannel(50); | |
radio.setRetries(15, 15); | |
radio.setPALevel(RF24_PA_MAX); | |
radio.setPayloadSize(8); | |
radio.setDataRate(RF24_250KBPS); | |
radio.openWritingPipe(pipes[0]); // write via 1st address as this is Rx | |
radio.openReadingPipe(1, pipes[1]); // read via 2nd address as this is Rx | |
radio.startListening(); | |
// Dump the configuration of the rf unit to serial for debugging | |
radio.printDetails(); | |
} | |
void loop(void) | |
{ | |
if ( radio.available() ) | |
{ | |
radio.read( &temp, sizeof(temp) ); | |
Serial.println(temp); | |
dtostrf(temp, 5, 2, tmpStr); | |
Particle.publish("nrfTemp",tmpStr,PRIVATE); | |
digitalWrite(STATUS_LED, HIGH); | |
delay(200); | |
digitalWrite(STATUS_LED, LOW); | |
} | |
else | |
{ | |
delay(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment