Created
April 4, 2012 14:38
-
-
Save arduinoboard/2301902 to your computer and use it in GitHub Desktop.
The file that is currently on an Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 with a serial number of A4016EYA
This file contains hidden or 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
/** | |
* A Mirf example to test the latency between two Ardunio. | |
* | |
* Pins: | |
* Hardware SPI: | |
* MISO -> 12 | |
* MOSI -> 11 | |
* SCK -> 13 | |
* | |
* Configurable: | |
* CE -> 8 | |
* CSN -> 7 | |
* | |
* Note: To see best case latency comment out all Serial.println | |
* statements not displaying the result and load | |
* 'ping_server_interupt' on the server. | |
*/ | |
#include <SPI.h> | |
#include <Mirf.h> | |
#include <nRF24L01.h> | |
#include <MirfHardwareSpiDriver.h> | |
void setup(){ | |
Serial.begin(9600); | |
/* | |
* Setup pins / SPI. | |
*/ | |
/* To change CE / CSN Pins: | |
* | |
* Mirf.csnPin = 9; | |
* Mirf.cePin = 7; | |
*/ | |
Mirf.cePin = 9; | |
Mirf.csnPin = 10; | |
Mirf.spi = &MirfHardwareSpi; | |
Mirf.init(); | |
/* | |
* Configure reciving address. | |
*/ | |
Mirf.setRADDR((byte *)"clie1"); | |
/* | |
* Set the payload length to sizeof(unsigned long) the | |
* return type of millis(). | |
* | |
* NB: payload on client and server must be the same. | |
*/ | |
Mirf.payload = sizeof(unsigned long); | |
/* | |
* Write channel and payload config then power up reciver. | |
*/ | |
/* | |
* To change channel: | |
* | |
* Mirf.channel = 10; | |
* | |
* NB: Make sure channel is legal in your area. | |
*/ | |
Mirf.config(); | |
Serial.println("Beginning ... "); | |
} | |
void loop(){ | |
unsigned long time = millis(); | |
Serial.println(time); | |
Mirf.setTADDR((byte *)"serv1"); | |
Mirf.send((byte *)&time); | |
while(Mirf.isSending()){ | |
} | |
Serial.println("Finished sending"); | |
delay(10); | |
while(!Mirf.dataReady()){ | |
//Serial.println("Waiting"); | |
if ( ( millis() - time ) > 1000 ) { | |
Serial.println("Timeout on response from server!"); | |
return; | |
} | |
} | |
Mirf.getData((byte *) &time); | |
//Serial.print("Ping: "); | |
Serial.println((millis() - time)); | |
delay(1000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment