Esempio n. 1
1
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
}
Esempio n. 2
0
void loadSingleBuffer(boolean wBf){
  int bCount = 0; int fails = 0;
  //if(!playing){return;}

  while(bCount < buffSize){

    if(txSelX(3,0)){
        for(int i=0; i<payloadSize; i++){
          buffer[wBf][bCount] = tmpArr[i]; bCount++;
            //if(bCount > buffSize){ Serial.println("BuffSize needs to be a multiple of 32"); noTun(); return;}
        }
          //radio.powerUp();
    }else{
          if(tmpArr[0] == 4 &&  tmpArr[1] == 3 && tmpArr[2] == 2){
          noTun(); retryClose();
          Serial.println("ebp");
           return;
         }

       if(fails >= 300){Serial.println("fail");noTun(); retryClose(); return;}
          fails++;
    }

    radi.powerUp();
  }
  buffEmpty[wBf] = 0; radi.powerUp();
  return;
}
Esempio n. 3
0
void setup(void){

    radio.begin();
    radio.setPALevel(RF_24_PA_MAX);
    radio.setChannel(0x75);
    radio.openWritingPipe(0xF0F0F0F0E1LL);
    radio.enableDynamicPayloads();
    radio.powerUp();

}
Esempio n. 4
0
void COM_24g::listeningPipe(RF24 _radioCom)	//Listen all available pipes
{
  int i;
	for (i=1;i<5;i++) {
		if (_readingPipe[i] != NULL) {
		_radioCom.openReadingPipe(i,_readingPipe[i]);
		}
	}
  _radioCom.startListening();
  _radioCom.powerUp();

}
Esempio n. 5
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();
}
Esempio n. 6
0
void pcmRX::pollForMusic(){

  if(!playing){
      int steps = 1;
      //testDataRates2();
    if(steps == 1){
            radi.powerUp();  // << VERY important step for some reason
            delay(5);
            if( txSelX(4,5) ){
              if( tmpArr[0] == 1 && tmpArr[1] == 2 && tmpArr[2] == 3 ){
                steps = 2;  //togLed();//txSelX(5,5); //txSelX(5,50);
              }else{txSelX(5,0); }
            }
    }
    if(steps == 2){
             Serial.println("S2");
             if ( txSel(3,5)){
              radi.read(&intData,sizeof(intData));
              if(intData < 8000 || intData > 22100){Serial.print("st2 "); /*delay(200);Serial.println(intData);*/ return;}
              //Serial.println("strt");
              whichBuff = 0;
              loadSingleBuffer(0); loadSingleBuffer(1);
              buffEmpty[0] = 0; buffEmpty[1] = 0; intCount = 0;
              SAMPLE_RATE = intData;
              if(intData > 20000){SAMPLE_RATE = 20000;}
              //Serial.println("playing");

//              if(timerTracker){  timerTracker=0; startTimer();
//              }else{resumeTimer();}
              if(!playing){ startTimer();
              }else{resumeTimer();}

            }else{ Serial.println("pl2");}
}

  }

}
Esempio n. 7
0
bool COM_24g::initiate(RF24 _radioCom)
{
    bool status = false;
    int i;
	//RF24 _radioCom(_ce,_csn);
	_radioCom.begin();
	// optionally, increase the delay between retries & # of retries
	_radioCom.setRetries(15,_maxRetry);
	
	_radioCom.setChannel(_channel);

	// optionally, reduce the payload size.  seems to improve reliability
	//_radioCom.setPayloadSize(8);

	// Open pipes to other nodes for communication
	//seen if this is an issue _radioCom.openWritingPipe(_writingPipe);
	for (i=1;i<5;i++) {
		if (_readingPipe[i] != NULL) {
		_radioCom.openReadingPipe(i,_readingPipe[i]);
        printf("Now listening pipe %d at adress %x \n",i,_readingPipe[i]);

		status = true;
		}
	}
	if (status == true) {
        printf("INITIALIZATION : We are listening \n");

	_radioCom.startListening();
        _radioCom.powerUp();

	} else {
          printf("We are doing a f*****g power down");

	_radioCom.powerDown();
	}
return status;
}
Esempio n. 8
0
int main(){
    init();
    setup();

    while(1){
        #ifdef PRINT_TO_SERIAL
            // Turn off serial during sleep.. ?
            Serial.flush();
            Serial.end();
        #endif
        

        // Disable stuff needed during awake-time
        #ifdef PRINT_TO_SERIAL
            Narcoleptic.disableSerial();
        #endif
        Narcoleptic.disableMillis();
        Narcoleptic.disableWire();

        // this is necessary to bring current consumption down from 0.35mA to 0.15mA in sleep
        digitalWrite(A4, LOW); // SDA low
        digitalWrite(A5, LOW); // SCL low

        // Sleep
        Narcoleptic.delay(DELAY_MILLISECONDS);
        // Re-enable stuff needed during awake-time
        Narcoleptic.enableWire(); // i2c
        Narcoleptic.enableMillis(); // without this, i2c doesn't work

        // for timing / diagnostics
        awake_timer = millis();

        #ifdef PRINT_TO_SERIAL
            Narcoleptic.enableSerial(); // printing
        #endif

        #ifdef PRINT_TO_SERIAL
        // Re-start serial
        Serial.begin(115200);
        #endif


        if(Narcoleptic.wasInterrupted()){
            // Print something if we woke up due to an interrupt
            #ifdef PRINT_TO_SERIAL
                Serial.println("Interrupt!");
            #endif

        // Enter a new state
            busymode();
        }
        else{
            // Read and print if we woke up without interrupt

        // Take a set of readings 
            digitalWrite(SHT_PIN, HIGH);
            float h = SHT2x.GetHumidity();
            float t = SHT2x.GetTemperature();
            digitalWrite(SHT_PIN, LOW);
        
        // Serial
            #ifdef PRINT_TO_SERIAL
                // Print to serial
                Serial.print("Humidity(%RH): ");
                Serial.println(h);
                Serial.print("Temperature(C): ");
                Serial.println(t);
            #endif


        // RF24 stuff
            // Write data in packet format
            packet p;
            p.t = t;
            p.h = h;

            snprintf((char*)data, PAYLOADLEN, "T: %f RH: %f (%u)", (double) t, (double) h, pkt_num++);

            // Turn on the radio
            radio.powerUp();

            // Send!!
            send((uint8_t *) data);
            // send((uint8_t *) &p);

            // Turn off the radio
            radio.powerDown();

        // Serial
            #ifdef PRINT_TO_SERIAL
                Serial.print("Awake: ");
                Serial.println(millis() - awake_timer);
            #endif
        }
    }

    return 0;
}
Esempio n. 9
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);
}
Esempio n. 10
0
void loop() {
  // - Sleep loop
  int i = 0;
  for(i = 0; i < SLEEP_STEP_NB; i++) {
    LowPower.powerDown(SLEEP_STEP_DURATION, ADC_OFF, BOD_OFF);
  }

  Serial.println(F("Awake"));

  // - Wake up the sensor through the step-up converter
  digitalWrite(STEP_UP_PIN, HIGH);
  // - Wait few ms for sensor init (TBD: minimal value)
  delay(100);

  // - Let's measure the distance between the sensor and the surface of the water
  int valuesInCm[NB_MEASURES];
  double avgMeasureCm = 0.0d;
  for(i = 0; i < NB_MEASURES; i++) {
    valuesInCm[i] = sonar.ping_cm();
    Serial.print(F("Distance: "));
    Serial.print(valuesInCm[i]);
    Serial.println(F("cm"));

    // - Skip some values if necessary
    if(i >= NB_MEASURES_SKIP) {
      avgMeasureCm += valuesInCm[i];
    }

    // - Delay for remaining echos (cf. sensor datasheet) before next reading
    delay(70);
  }

  // - Power off the sensor
  digitalWrite(STEP_UP_PIN, LOW);

  // - Computing average value (still in centimeters)
  unsigned short valueToSend = (unsigned short) round(avgMeasureCm / (double) (NB_MEASURES - NB_MEASURES_SKIP));

  Serial.print(F("Now sending: "));
  Serial.println(valueToSend);

  // - Message content
  Message msg;
  msg.address = nodeAddress[0];
  msg.value = valueToSend;

  // - Time to start the radio
  radio.powerUp();

  // - Message emission (with ACK)
  if ( radio.write(&msg, PAYLOAD_SIZE) ) {
      if(!radio.available()) {
          Serial.println(F("Got (blank) ack"));
      }
  } else {
    Serial.println(F("Sending failed"));
  }

  // - Time to stop the radio
  radio.powerDown();

  Serial.println(F("----------"));

  // - Delay necessary to serial buffer flush
  delay(50);
}