/* * 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 = 0; /* 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; // the structure of the packet that we're sending to the other pole #define LAT 0 #define LON 1 #define SPEED 2 #define HEADING 3 #define ALTITUDE 4 #define HOURS 5 #define MINUTES 6 #define SECONDS 7 float GPSbuffer[8]; 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.display(); display.clearDisplay(); } void loop() { float latitude, longitude, speed, angle, altitude; // if there is new information if (radio.available()) { // Variable for the received timestamp radio.read( &GPSbuffer, sizeof(float)*8); // update the display display.clearDisplay(); // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.print(GPSbuffer[0]); display.print(" N "); display.print(GPSbuffer[1]); display.println(" W"); display.print(GPSbuffer[2]); display.println("knots"); display.print((int)GPSbuffer[3]); display.print(" deg "); display.print((int)GPSbuffer[4]); display.println(" m"); display.print((int)GPSbuffer[HOURS]); display.print(":"); display.print((int)GPSbuffer[MINUTES]); display.print(":"); display.print((int)GPSbuffer[SECONDS]); display.display(); } } // Loop