Added code
This commit is contained in:
		
							parent
							
								
									867eae1178
								
							
						
					
					
						commit
						13a3963d74
					
				
							
								
								
									
										30
									
								
								Reciver/Reciver.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Reciver/Reciver.ino
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
#include <SPI.h>
 | 
			
		||||
#include <RF24.h>
 | 
			
		||||
 | 
			
		||||
RF24 radio(9, 10); // (CE, CSN)
 | 
			
		||||
 | 
			
		||||
struct gps_info{
 | 
			
		||||
  double latitude;
 | 
			
		||||
  double longitude;
 | 
			
		||||
  unsigned long date;
 | 
			
		||||
  unsigned long time;
 | 
			
		||||
}gps_data;
 | 
			
		||||
const byte address[6] = "5RF24";
 | 
			
		||||
void setup() {
 | 
			
		||||
  radio.begin();
 | 
			
		||||
  radio.setPALevel(RF24_PA_MAX); 
 | 
			
		||||
  radio.setChannel(125);
 | 
			
		||||
  radio.openReadingPipe(0, address); 
 | 
			
		||||
  radio.startListening();
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
  radio.enableDynamicPayloads();
 | 
			
		||||
  radio.setDataRate(RF24_250KBPS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() { 
 | 
			
		||||
  if (radio.available()) {
 | 
			
		||||
    byte gpsData;
 | 
			
		||||
    radio.read(&gps_data, sizeof(gps_data));
 | 
			
		||||
    Serial.write((uint8_t*)&gps_data, sizeof(gps_data));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								Transmitter/Transmitter.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Transmitter/Transmitter.ino
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
#include <SPI.h>
 | 
			
		||||
#include <RF24.h>
 | 
			
		||||
#include <SoftwareSerial.h>
 | 
			
		||||
#include <NMEAGPS.h>
 | 
			
		||||
#include <GPSport.h>
 | 
			
		||||
 | 
			
		||||
RF24 radio(5, 6); // (CE, CSN)
 | 
			
		||||
const byte address[6] = "5RF24";
 | 
			
		||||
static NMEAGPS  gps;
 | 
			
		||||
struct gps_info{
 | 
			
		||||
  double latitude;
 | 
			
		||||
  double longitude;
 | 
			
		||||
  unsigned long date;
 | 
			
		||||
  unsigned long time;
 | 
			
		||||
}gps_data;
 | 
			
		||||
void setup() {
 | 
			
		||||
  //Setup radio
 | 
			
		||||
  radio.begin();
 | 
			
		||||
  radio.setPALevel(RF24_PA_MAX); 
 | 
			
		||||
  radio.setChannel(125);
 | 
			
		||||
  radio.openWritingPipe(address); 
 | 
			
		||||
  radio.stopListening();
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
  radio.setAutoAck(true);
 | 
			
		||||
  radio.setRetries(5,15);
 | 
			
		||||
  radio.enableDynamicPayloads();
 | 
			
		||||
  radio.setDataRate(RF24_250KBPS);
 | 
			
		||||
  //Setup NeoGPS
 | 
			
		||||
  gpsPort.begin(9600);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void doSomeWork( const gps_fix & fix );
 | 
			
		||||
static void doSomeWork( const gps_fix & fix )
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  if (fix.valid.location) {
 | 
			
		||||
    if ( fix.dateTime.seconds < 40 )
 | 
			
		||||
      gps_data.latitude=fix.latitude();
 | 
			
		||||
      gps_data.longitude=fix.longitude();
 | 
			
		||||
      radio.write(&gps_data, sizeof(gps_data));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} // doSomeWork
 | 
			
		||||
 | 
			
		||||
static void GPSloop();
 | 
			
		||||
static void GPSloop()
 | 
			
		||||
{
 | 
			
		||||
  while (gps.available( gpsPort ))
 | 
			
		||||
    doSomeWork( gps.read() );
 | 
			
		||||
 | 
			
		||||
} // GPSloop
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  GPSloop();
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue