Interruptions and mesures

Everything about programming the platform and using the Waspmote API
Post Reply
weicky
Posts: 17
Joined: Fri Feb 12, 2016 12:47 pm

Interruptions and mesures

Post by weicky » Wed Jul 03, 2019 11:50 am

I'm developing an Events Plug&Sense Waspmote program and I have the following needs:
  • Every time a door is open (hall effect sensor), I send a Xbee Frame
  • Every 30 minutes I send a Xbee Frame of data from Temperature, pressure, humidity and liquid flow.
My program looks like this:
//Definitions
unsigned short int MAX_CYCLES = 1800;
unsigned short int interval;

//Setup
interval = 0;

//Loop
if(interval >= MAXCYCLES){
// Create frame
// Get values from the sensors
// Send frame
interval = 0;
}
interval += 1;
delay(1000);

//Test hall effect interruptions and if it is produced:
// Disable Interruptions
// Load interruptions flag
// Check interr...
// Create and send frame
// Clean flag
// Enable interruptions


Is there any way more elegant to do this? Something like RTC interruption or similar.
Thank you very much.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Interruptions and mesures

Post by libelium-dev » Thu Jul 04, 2019 8:09 am

Hi,

Yes, you can do that using interruptions. You should use the RTC_ABSOLUTE mode. It could be something like this

Code: Select all

  RTC.ON();
  USB.println(RTC.getTime());
  if ((RTC.minute > 0) && (RTC.minute <= 30 )) {
    PWR.deepSleep("00:00:30:00", RTC_ABSOLUTE, RTC_ALM1_MODE4, ALL_OFF);
  }
  else {
    PWR.deepSleep("00:00:00:00", RTC_ABSOLUTE, RTC_ALM1_MODE4, ALL_OFF);
  }

  ///////////////////////////////////////
  // 3. Check Interruption Flags
  ///////////////////////////////////////

  // 3.1. Check interruption from RTC alarm
  if (intFlag & RTC_INT)
  {
    USB.println(F("-----------------------------"));
    USB.println(F("RTC INT captured"));
    USB.println(F("-----------------------------"));

    // clear flag
    intFlag &= ~(RTC_INT);
  }

  // 3.2. Check interruption from Sensor Board
  if (intFlag & SENS_INT)
  {
    // Disable interruptions from the board
    Events.detachInt();

    // Load the interruption flag
    Events.loadInt();

    // Check interruption
    if (hall.getInt())
    {
      USB.println(F("-----------------------------"));
      USB.println(F("Interruption from Hall effect"));
      USB.println(F("-----------------------------"));
    }

    // Clean the interruption flag
    intFlag &= ~(SENS_INT);

    // Enable interruptions from the board
    Events.attachInt();
  }
Regards

weicky
Posts: 17
Joined: Fri Feb 12, 2016 12:47 pm

Re: Interruptions and mesures

Post by weicky » Tue Oct 22, 2019 7:56 pm

Hi all,

Sorry, but I have a doubt: Do sensor interruptions work perfectly in deepSleep mode? I need to send a frame when a door is opened, in this moment.

And second question: I should write the code sending a frame with temperature, presure... when RTC interruption is detected, right?

Regards,

Thank you very much.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Interruptions and mesures

Post by libelium-dev » Wed Oct 23, 2019 9:00 am

Hi,

Yes, the sensor interrupts work in deepSleep mode but it's necessary to keep the sensor board ON. Therefore, you have to use the SENSOR_ON argument instead of ALL_OFF.

Yes, if you want to send the temp, hum and press data every 30 minutes, you have to send the frame when an RTC interrupt is detected.

Code: Select all

  RTC.ON();
  USB.println(RTC.getTime());
  if ((RTC.minute > 0) && (RTC.minute <= 30 )) {
    PWR.deepSleep("00:00:30:00", RTC_ABSOLUTE, RTC_ALM1_MODE4, SENSOR_ON);
  }
  else {
    PWR.deepSleep("00:00:00:00", RTC_ABSOLUTE, RTC_ALM1_MODE4, SENSOR_ON);
  }

  ///////////////////////////////////////
  // 3. Check Interruption Flags
  ///////////////////////////////////////

  // 3.1. Check interruption from RTC alarm
  if (intFlag & RTC_INT)
  {
    USB.println(F("-----------------------------"));
    USB.println(F("RTC INT captured"));
    USB.println(F("-----------------------------"));

    // clear flag
    intFlag &= ~(RTC_INT);
  }

  // 3.2. Check interruption from Sensor Board
  if (intFlag & SENS_INT)
  {
    // Disable interruptions from the board
    Events.detachInt();

    // Load the interruption flag
    Events.loadInt();

    // Check interruption
    if (hall.getInt())
    {
      USB.println(F("-----------------------------"));
      USB.println(F("Interruption from Hall effect"));
      USB.println(F("-----------------------------"));
    }

    // Clean the interruption flag
    intFlag &= ~(SENS_INT);

    // Enable interruptions from the board
    Events.attachInt();
  }
Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest