sketch stopping when sending data with RF95

Hello,

i have a sparkfun rf pro board with the RF95 lora on board.

i want to send a "1" every time a pulse from sensor (on pin2) come's in. but when i do this it is not working after 1 pulse:

/* Simple Pulse Counter

Counts digital pulses fed into pin 12. For reliability, the minimum pulse width is 1 millisecond.
If the signal is held high, the arduino will count it as one pulse.

*/

#include <RH_RF95.h>

RH_RF95 rf95;
float frequency = 868.0; // Change the frequency here. 
uint8_t data[] = "1";

void setup(){
  attachInterrupt(2, onPulse, FALLING);
  
  SerialUSB.begin(9600);
  SerialUSB.println(F("No pulses yet...")); // Message to send initially (no pulses detected yet).
       if (!rf95.init())
     SerialUSB.println("init failed");
  // Setup ISM frequency
   rf95.setFrequency(frequency);
   // Setup Power,dBm
   rf95.setTxPower(10);
//  sensors.begin(); 
}

void loop(){  

}

void onPulse()
{
     
//  rf95.send(data, sizeof(data));
 
    SerialUSB.println("1");

 }

but when i comment out the line i get a perfect read on the serial monitor. It is like if he sends the data he stops the sketch:

/* Simple Pulse Counter

Counts digital pulses fed into pin 12. For reliability, the minimum pulse width is 1 millisecond.
If the signal is held high, the arduino will count it as one pulse.

*/

#include <RH_RF95.h>

RH_RF95 rf95;
float frequency = 868.0; // Change the frequency here. 
uint8_t data[] = "1";

void setup(){
  attachInterrupt(2, onPulse, FALLING);
  
  SerialUSB.begin(9600);
  SerialUSB.println(F("No pulses yet...")); // Message to send initially (no pulses detected yet).
       if (!rf95.init())
     SerialUSB.println("init failed");
  // Setup ISM frequency
   rf95.setFrequency(frequency);
   // Setup Power,dBm
   rf95.setTxPower(10);
//  sensors.begin(); 
}

void loop(){  

}

void onPulse()
{
     
 rf95.send(data, sizeof(data));
 
    SerialUSB.println("1");

 }

a bit of help would be nice, i'm very new to this.

a second question would be how do i get the RF board and the RF95 to deep sleep until another "pulse" arrives? I want to let this sensor battery powered for months. I have a lipro battery connected to it so i want it to last long. important to know is that this board has the SAMD21 microprocessor on board.

thanks for the help in advance,

mathias

your onPulse() function is being called during an interrupt which means more interrupts are currently disabled. You can't call other functions that rely on that (I'm guessing the RF does). You should also NOT call Serial.print() since it uses interrupts as well.

Your onPulse() code needs to just set a flag and then have your main loop() function react to that flag and print or send data or whatever and then reset the flag.

mathiasc:
a second question would be how do i get the RF board and the RF95 to deep sleep until another "pulse" arrives?

I would check the library documentation........................

blh64:
your onPulse() function is being called during an interrupt which means more interrupts are currently disabled. You can't call other functions that rely on that (I'm guessing the RF does). You should also NOT call Serial.print() since it uses interrupts as well.

Your onPulse() code needs to just set a flag and then have your main loop() function react to that flag and print or send data or whatever and then reset the flag.

would it be possible to give me an example of this as i am (very) new to programming ?

Something like this:

/* Simple Pulse Counter

  Counts digital pulses fed into pin 12. For reliability, the minimum pulse width is 1 millisecond.
  If the signal is held high, the arduino will count it as one pulse.

*/

#include <RH_RF95.h>

RH_RF95 rf95;
float frequency = 868.0; // Change the frequency here.
uint8_t data[] = "1";

volatile bool pulseDetected;  // must be volatile when in an interrupt service routine (ISR)

void setup() {
  SerialUSB.begin(9600);
  SerialUSB.println(F("No pulses yet...")); // Message to send initially (no pulses detected yet).
  if (!rf95.init())
    SerialUSB.println("init failed");
  // Setup ISM frequency
  rf95.setFrequency(frequency);
  // Setup Power,dBm
  rf95.setTxPower(10);
  //  sensors.begin();
  pulseDetected = false;
  attachInterrupt(2, onPulse, FALLING);
}

void loop() {
  if ( pulseDetected ) {
    SerialUSB.println("1");
    rf95.send(data, sizeof(data));
    pulseDetected = false

  }
}

void onPulse()
{
  pulseDetected = true;
}