# Interrupts and cloud connection

**URL:** <https://community.particle.io/t/interrupts-and-cloud-connection/48809>\
**Category:** Troubleshooting\
**Created:** [March 31, 2019, 2:17pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809 "2019-03-31T14:17:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![electronweather](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@electronweather](https://community.particle.io/u/electronweather)\
**Post date:** [March 31, 2019, 2:17pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/1 "2019-03-31T14:17:55Z")

</div>

Hi guys 🙂

I want to use a Davis 6410 wind sensor. There is a sample code for arduino:

> **[Davis Anemometer Arduino Hookup | Code (Part 2 of 3)](http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-wind-speed)**
>
> How to hookup Arduino to the Davis Anemometer and measure wind speed

I have adjusted the code that I can use it with my Photon:

```auto
#include <math.h>

#define WindSensorPin (2) // The pin location of the anemometer sensor

volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine

float WindSpeed; // speed miles per hour

void setup() {
Serial.begin(9600);

pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);

Serial.println("Davis Wind Speed Test");
Serial.println("Rotations\tMPH");
}

void loop() {

Rotations = 0; // Set Rotations count to 0 ready for calculations

attachInterrupt(WindSensorPin, isr_rotation, FALLING);
delay(3000);
detachInterrupt(WindSensorPin);
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75

WindSpeed = Rotations * 0.75;

Serial.print(Rotations); Serial.print("\t\t");
Serial.println(WindSpeed);

}

// This is the function that the interrupt calls to increment the rotation count
void isr_rotation () {

if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}

} 

```

But when I use this code I have problems uploading a new code OTA. I think the problem are is the interrupt function. How I can adjust my code that I can upload my new code OTA still using the interrupt function?

Best regards

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [March 31, 2019, 3:05pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/2 "2019-03-31T15:05:38Z")

</div>

@electronweather, you may want to try this code instead of `delay(3000)`. It allows the DeviceOS to process Cloud stuff during the delay.

```auto
for(uint32_t ms = millis(); millis() - ms < 3000L; Particle.process()); // Different version of delay(3000)

```

Also, use the correct Particle definition for the pin you want to use, in this case `D2` I assume. The first `attachInterrupt()` function is not needed since, instead of using `interrutps()` and `noInterrupts()` you use `attachInterrupt()` and `detachInterrupt()`, which is a wise substitute. With these changes, you code would look like this:

```auto
#include <math.h>

#define WindSensorPin (D2)	// The pin location of the anemometer sensor

volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine

float WindSpeed; // speed miles per hour

void setup() {
	Serial.begin(9600);

	pinMode(WindSensorPin, INPUT);

	Serial.println("Davis Wind Speed Test");
	Serial.println("Rotations\tMPH");
}

void loop() {

	Rotations = 0; // Set Rotations count to 0 ready for calculations

	attachInterrupt(WindSensorPin, isr_rotation, FALLING);
	for(uint32_t ms = millis(); millis() - ms < 3000L; Particle.process()); // Different version of delay(3000)
	detachInterrupt(WindSensorPin);
	// convert to mp/h using the formula V=P(2.25/T)
	// V = P(2.25/3) = P * 0.75

	WindSpeed = Rotations * 0.75;

	Serial.print(Rotations); Serial.print("\t\t");
	Serial.println(WindSpeed);

}

// This is the function that the interrupt calls to increment the rotation count
void isr_rotation () {

	if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
		Rotations++;
		ContactBounceTime = millis();
	}

} 

```

---

<div class="post-metadata">

**Author:** ![electronweather](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@electronweather](https://community.particle.io/u/electronweather)\
**Post date:** [March 31, 2019, 4:27pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/3 "2019-03-31T16:27:32Z")

</div>

Thank you! 🙂

But isn’t it necessary to reset “ms” each loop?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [March 31, 2019, 4:48pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/4 "2019-03-31T16:48:31Z")

</div>

@electronweather read the for loop! It gets reset there.

---

<div class="post-metadata">

**Author:** ![electronweather](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@electronweather](https://community.particle.io/u/electronweather)\
**Post date:** [March 31, 2019, 5:52pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/5 "2019-03-31T17:52:27Z")

</div>

Ah now I can see it 🙂

---

<div class="post-metadata">

**Author:** ![electronweather](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@electronweather](https://community.particle.io/u/electronweather)\
**Post date:** [April 2, 2019, 5:20pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/6 "2019-04-02T17:20:01Z")

</div>

Is it necessary to call Particle.process()); if SYSTEM\_THREAD(ENABLED); ?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [April 2, 2019, 5:23pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/7 "2019-04-02T17:23:01Z")

</div>

> [@electronweather](#):
>
> Is it necessary to call Particle.process()); if SYSTEM\_THREAD(ENABLED); ?

Nope, you won't need to do that anymore - not even in `SYSTEM_MODE(MANUAL)`

---

<div class="post-metadata">

**Author:** ![electronweather](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@electronweather](https://community.particle.io/u/electronweather)\
**Post date:** [April 6, 2019, 10:00pm UTC](https://community.particle.io/t/interrupts-and-cloud-connection/48809/8 "2019-04-06T22:00:39Z")

</div>

So I dont have to use Particle.process());?
