/* * Getting Started example sketch for nRF24L01+ radios * This is a very basic example of how to send data from one node to another * Updated: Dec 2014 by TMRh20 * * Edited to add demo screen code from Adafruit. * */ #include /* for nRF24L01+ Modules */ #include "DigitalIO.h" #include "RF24.h" /* for OLED Screen */ #include #include #include // If using software SPI (the default case): #define OLED_MOSI 18 #define OLED_CLK 17 #define OLED_DC 16 #define OLED_CS 14 #define OLED_RESET 15 Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); /* Uncomment this block to use hardware SPI #define OLED_DC 6 #define OLED_CS 7 #define OLED_RESET 8 Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); */ #if (SSD1306_LCDHEIGHT != 32) #error("Height incorrect, please fix Adafruit_SSD1306.h!"); #endif /****************** User Config ***************************/ /*** Set this radio as radio number 0 or 1 ***/ bool radioNumber = 1; /* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */ RF24 radio(6,5); /**********************************************************/ byte addresses[][6] = {"1Node","2Node"}; // store current heading int currentHeading = 0; void setup() { Serial.begin(115200); Serial.println(F("GPS Screen Receiver")); radio.begin(); // Set the PA Level low to prevent power supply related issues since this is a // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default. radio.setPALevel(RF24_PA_LOW); // Open a writing and reading pipe on each radio, with opposite addresses if(radioNumber){ radio.openWritingPipe(addresses[1]); radio.openReadingPipe(1,addresses[0]); }else{ radio.openWritingPipe(addresses[0]); radio.openReadingPipe(1,addresses[1]); } // Start the radio listening for data radio.startListening(); /* Screen Setup */ // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) display.begin(SSD1306_SWITCHCAPVCC); // init done display.clearDisplay(); } void loop() { int degrees_; // if there is new information if(radio.available()){ // Variable for the received timestamp while (radio.available()) { // While there is data ready radio.read( °rees_, sizeof(int) ); // Get the payload } // let the transmitter know we got it radio.stopListening(); // First, stop listening so we can talk radio.write( °rees_, sizeof(unsigned long) ); // Send the final one back. radio.startListening(); // Now, resume listening so we catch the next packets. Serial.print(F("Sent response ")); Serial.println(degrees_); // check to see if it is different than what we already have if(currentHeading != degrees_) { currentHeading = degrees_; // if so then update the display display.clearDisplay(); // text display tests display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0,0); display.print(currentHeading); display.println("degrees"); display.display(); } } } // Loop