void setupRadio() {
  printf_begin();

  // Setup and configure radio
  radio.begin();
  radio.setAutoAck(1);                    // Ensure autoACK is enabled
  radio.enableAckPayload();               // Allow optional ack payloads
  radio.setRetries(2,15);                 // Smallest time between retries, max no. of retries
  radio.setPayloadSize(8);
  radio.setDataRate(RF24_250KBPS);
  
  if( radio.getDataRate() == RF24_250KBPS ) 
  {
    debugPrint("Radio is available");
    radio_hw_available = true;
    
    radio.startListening();                 // Start listening
    radio.powerUp();
  
    radio.openWritingPipe(pipes[0]);       // Open different pipes when writing. Write on pipe 0, address 0
    radio.openReadingPipe(1,pipes[1]);     // Read on pipe 1, as address 1
  } else {
    debugPrint("Radio is NOT available");
  }
  //radio.printDetails(); // Dump the configuration of the rf unit for debugging
}
Example #2
0
/********************************************************************************
Main
********************************************************************************/
int main(void) {
    // initialize code
	usart_init();

    // enable interrupts
    //sei();

	_delay_ms(2000);

    printf("Start NRF24L01P test...");

    radio.begin();
    radio.setRetries(15,15);
    radio.setPayloadSize(8);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(120);

    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1,pipes[0]);

    radio.startListening();

    radio.printDetails();

	loop();

    // main loop
    while (true) {
    	_delay_ms(1000);
    	printf("Elapsed: %u \n", TCNT1);
    }
}
Example #3
0
void setup() {
  // - Setup serial port
  Serial.begin(115200);

  // - Pin initialization
  pinMode(STEP_UP_PIN, OUTPUT);
  digitalWrite(STEP_UP_PIN, LOW);

  // - Read address selection
  pinMode(ADDRESS_SELECTION_PIN, INPUT_PULLUP);
  if(digitalRead(ADDRESS_SELECTION_PIN) == HIGH) {
    nodeAddress[0] = 0x01;
  } else {
    nodeAddress[0] = 0x02;
  }

  // - Setup and configure radio
  radio.begin();
  //radio.enableDynamicPayloads();
  radio.setPayloadSize(PAYLOAD_SIZE);
  radio.setDataRate(RF24_250KBPS); // - Lower speed
  radio.setPALevel(RF24_PA_HIGH); // - Higher power level

  radio.openWritingPipe(gatewayAddress); // - To send values
  radio.openReadingPipe(1, nodeAddress); // - Not used in reality

  radio.powerDown();
}
Example #4
0
int main(int argc, char** argv){

//  bool role_ping_out = true, role_pong_back = false;
//  bool role = role_pong_back;

  printf("RF24/examples/GettingStarted/\n");

  // Setup and configure rf radio
  radio.begin();

  radio.setChannel(2);
  radio.setDataRate(RF24_2MBPS);
  radio.setPayloadSize(8);

  // optionally, increase the delay between retries & # of retries
//  radio.setRetries(15,15);
  // Dump the configuration of the rf unit for debugging
  radio.printDetails();


/***********************************/
	radio.startListening();
	
	// forever loop
	while (1)
	{

		// if there is data ready
		if ( radio.available() )
		{
			// Dump the payloads until we've gotten everything
			unsigned long got_time;

			// Fetch the payload, and see if this was the last one.
			while(radio.available()){
				radio.read( &got_time, sizeof(unsigned long) );
			}
//			radio.stopListening();
				
//			radio.write( &got_time, sizeof(unsigned long) );

			// Now, resume listening so we catch the next packets.
//			radio.startListening();

			// Spew it
			printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
			
				
		}
		delay(925); //Delay after payload responded to, minimize RPi CPU time
		printf("."); fflush(stdout);
//  radio.printDetails();
		

	} // forever loop

  return 0;
}
Example #5
0
void setupRadio() {
  radio.begin();
  radio.setRetries(0,15);
  radio.setPayloadSize(sizeof(PosData));
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);

  radio.startListening();
}
/********************************************************************************
	Main
********************************************************************************/
int main(void) {
    // initialize usart module
	usart_init();

    // enable interrupts
    sei();

    // Init GPIO
    initGPIO();

    // Init Timer 1
    initTimer();

    // Init Timer 0 & 2
    initTimers();

	OCR0A = 255;
	OCR0B = 255;
	OCR2A = 255;
	OCR2B = 255;

    _delay_ms(1000);

	OCR0A = 0;
	OCR0B = 0;
	OCR2A = 0;
	OCR2B = 0;

    fixZeroValueOCR();

	// Console friendly output
    printf("Start...");
    printf(CONSOLE_PREFIX);

    // Init NRF24L01+
    radio.begin();
    radio.setRetries(15,15);
    radio.setPayloadSize(8);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(115);

    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);

    radio.startListening();

    // Some RF module diagnostics logs
    radio.printDetails();

	// main loop
    while (1) {
    	// main usart loop for console
    	usart_check_loop();
    }
}
Example #7
0
void rf24_init(RF24& radio) {
	const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
	radio.begin();
	//	radio.setChannel(100);
	radio.setRetries(15, 15);
	radio.setPayloadSize(sizeof(report_t));
	radio.setDataRate(RF24_250KBPS);
	radio.openWritingPipe(pipes[1]);
	radio.openReadingPipe(1, pipes[0]);
	radio.startListening();
	radio.printDetails();
}
Example #8
0
void initialiseBoard()
{
    Serial.begin(57600);
    radio.begin();
    mapFreeCH();
    // optionally, increase the delay between retries & # of retries
    radio.setRetries(15,15);
    radio.setPayloadSize(PAYLOAD_SIZE);
    \
    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);
    radio.startListening();

}
Example #9
0
void setup(void)
{
  //
  // Print preamble
  //

  //Serial.begin(57600);
  //printf_begin();
  printf("\n\rRF24/examples/scanner/\n\r");

  //
  // Setup and configure rf radio
  //

  radio.begin();
  radio.setAutoAck(false);
//	radio.enableDynamicPayloads();
	radio.setPayloadSize(2);
	radio.setDataRate(RF24_250KBPS);
	radio.setPALevel(RF24_PA_MAX);
//	radio.setChannel(76);
	radio.setCRCLength(RF24_CRC_16);

  // Get into standby mode
  radio.startListening();
  radio.stopListening();

  radio.printDetails();

  // Print out header, high then low digit
  int i = 0;
  while ( i < num_channels )
  {
    printf("%x",i>>4);
    ++i;
  }
  printf("\n\r");
  i = 0;
  while ( i < num_channels )
  {
    printf("%x",i&0xf);
    ++i;
  }
  printf("\n\r");

}
Example #10
0
void setup(){
  uextPowerOn();
  pinMode(LED, OUTPUT);
  pinMode(OUT, OUTPUT);

  Serial.begin(115200);
  printf_begin();

  radio.begin();
  radio.setCRCLength(RF24_CRC_16);
  radio.setDataRate(RF24_1MBPS);
  radio.setAutoAck(0);
  radio.setRetries(0,0);
  radio.setPayloadSize(3);                
  radio.powerUp();
  radio.printDetails(); 
  setupReceive();
}
void RF24Setup( void (*processPacket)(Packet) )
{
  radio.begin();
  radio.setPayloadSize(sizeof(Packet));
  //radio.setChannel(4);
  //radio.setDataRate(RF24_250KBPS);
  //radio.setRetries(0,15);

  radio.openReadingPipe(1,base_pipe);
  radio.setAutoAck(1, false);
  radio.startListening();

//TODO prety print based on --verbose argument
//  printf("\n\rRF24SensorHub!\n");
  radio.printDetails();

  printf("size of packet   = %hu\n", sizeof(Packet));
  
  _processPacket = processPacket;

}
Example #12
0
void setup(void)
{
  radio.begin();
  radio.setPayloadSize(PAYLOAD_SIZE);
  radio.setAutoAck(1);
  radio.setRetries(15,15);
  radio.setDataRate(RF24_1MBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.setChannel(10);
  radio.setCRCLength(RF24_CRC_16);

  //open the pipe
  radio.openReadingPipe(1,0xF0F0F0F0E1LL);

  // Start Listening
  radio.startListening();

  //print output
  radio.printDetails();
  printf("\n\rOutput below : \n\r");
  usleep(1000);
}
Example #13
0
void setup(void)
{
  //
  // Setup and configure rf radio
  //

  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(20, 20);

  radio.setPayloadSize(PAYLOAD);
  // TODO: set other crap (data rate, spi rate, etc)
  radio.setDataRate(RF24_2MBPS);
  radio.setChannel(0x4c);
  radio.setPALevel(RF24_PA_MAX);

  //
  // Open pipes to other nodes for communication
  //

  // TODO: configure this to match correctly on the Arduino
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);

  //
  // Start listening
  //

  radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  //radio.printDetails();
  std::cerr << "OK Listening for commands" << std::endl;
}
Example #14
0
int main(int argc, char** argv) 
{
    int fr = atoi(argv[1]);
    int to = atoi(argv[2]);
    int ac = atoi(argv[3]);
    
    printf("vendor/TMRh20/RF24_RPi/Task\n");
    
    // Refer to RF24.h or nRF24L01 DS for settings

    radio.begin();

    delay(5);
    
    radio.setPayloadSize(10);
    radio.setRetries(15,15); // optionally, increase the delay between retries & # of retries
    //radio.setAutoAck(1); // Ensure autoACK is enabled
    radio.setAutoAck(0); // Ensure autoACK is disabled
    radio.setPALevel(RF24_PA_HIGH);
    radio.setDataRate(RF24_250KBPS);
    //radio.setCRCLength(RF24_CRC_8);
    radio.setChannel(114);
    
    radio.openWritingPipe(pipes[(to-1)]); // atoi() change a char to a int
    radio.openReadingPipe(1,pipes[(fr-1)]);
    
    radio.startListening();
    
    radio.printDetails();
    
    // First, stop listening so we can talk.
    radio.stopListening();
    radio.powerUp();
    
    // Take the time, and send it.  This will block until complete

    char payload_send[10] = "";
    snprintf(payload_send, 10, "to:%d,ac:%d", to, ac);
    
    char payload_send_size[10] = "";
    snprintf(payload_send_size, 10, "%d", sizeof(payload_send));
    
    printf("Sending ..\n");
    printf("Payload size: ");
    printf(payload_send_size);
    printf("\n");
    printf("Payload: ");
    printf(payload_send);
    printf("\n");

    //bool ok = radio.write( &payload_send, 10 );
    radio.write( &payload_send, 10 );

    /*if (!ok){
        printf("failed.\n");
        exit(1);
    }*/
    
    //radio.powerDown();
    
    // Now, continue listening
    radio.startListening();

    // Wait here until we get a response, or timeout (250ms)
    unsigned long started_waiting_at = millis();
    bool timeout = false;
    
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    while ( ! radio.available() && ! timeout ) {
        if (millis() - started_waiting_at > 3000 ) {
            timeout = true;
        }
    }


    // Describe the results
    if ( timeout ) {
        printf("err: response timed out.\n");
        exit(1);
        
    } else {
        // Grab the response, compare, and send to debugging spew
        char payload_receive[10] = "";
        radio.read( &payload_receive, 10 );

        char payload_receive_size[10] = "";
        snprintf(payload_receive_size, 32, "%d", 10);
        // Spew it
        printf("Received ..\n");
        printf("Payload size: ");
        printf(payload_receive_size);
        printf("\n");
        printf("Payload: ");
        printf(payload_receive);
        printf("\n");
        
        printf(payload_receive);
        exit(0);
    }
    exit(1);
}
Example #15
0
int main (){


	HardwareInit();

	RF24 radio = RF24();
	// Radio pipe addresses for the 2 nodes to communicate.
	const uint64_t pipes[2] = { 0xF0F0F0F0BELL, 0xF0F0F0F0EFLL };

	setup_watchdog(wdt_64ms);

	//
	// Setup and configure rf radio
	//
	radio.begin();

	radio.setChannel(100);

	// optionally, increase the delay between retries & # of retries
	radio.setRetries(15,15);

	// optionally, reduce the payload size.  seems to
	// improve reliability
	radio.setPayloadSize(sizeof(report_t));

	radio.setDataRate(RF24_250KBPS);
	radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1,pipes[1]);
	radio.startListening();
	radio.stopListening();

	//unsigned long  pa = 0;
	uint8_t counter = 0;


	//check eeprom
	if (eeprom_read_byte(0)==EEPROM_MAGIC_NUMBER){
		minx=(char)eeprom_read_byte((uint8_t*)1);
		maxx=(char)eeprom_read_byte((uint8_t*)2);
		miny=(char)eeprom_read_byte((uint8_t*)3);
		maxy=(char)eeprom_read_byte((uint8_t*)4);
		minrx=(char)eeprom_read_byte((uint8_t*)5);
		maxrx=(char)eeprom_read_byte((uint8_t*)6);
		minry=(char)eeprom_read_byte((uint8_t*)7);
		maxry=(char)eeprom_read_byte((uint8_t*)8);
		calibrated=true;

#ifdef DEBUG
		print_string("read eeprom magic number");
		char temp[100];
		sprintf(temp,"minx:%d maxx:%d minry:%d maxry:%d \n",minx,maxx,minry,maxry);
		print_string(temp);
		_delay_ms(2000);
#endif

	}


	while(1){

		ReadController();
#ifdef DEBUG
		char temp[100];
		print_string("before convert\n");
		sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2);
		print_string(temp);
#endif

		convertAxes();

#ifdef DEBUG
		sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2);
		print_string(temp);
#endif

		//Calibration
		if(A_PRESSED && B_PRESSED && Z_PRESSED && L_PRESSED && R_PRESSED){
			calibrate();
		}

		counter=(counter+1)%20;
		sendData(counter==0,radio);


		do_sleep();
	}
	//never reached
	return 0;
}