Esempio n. 1
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();
}
Esempio n. 2
0
void setupRF24(){
    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);
    radio.setPALevel(RF24_PA_MAX);

    // Open a writing and reading pipe
    radio.openWritingPipe((byte *) TXNAME);
    radio.openReadingPipe(1, (byte *) RXNAME);

    // Start the radio listening for data
    radio.startListening();

    radio.powerDown();
}
Esempio n. 3
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. 4
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. 5
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);
}