Hello to everyone.
I am having some trouble implementing this arduino code to particle photon.
I have replaced interrupt 0 = D2(arduino) for interrupt 4 = D4(photon)
// read RPM
//interrupt 0 is pin D2 on arduino for the Nano, connected to hall effect sensor S
int revolutions = 0;
int rpm = 0;
unsigned long lastmillis = 0;
void setup(){
Serial.begin(9600);
attachInterrupt(0, rpm_shaft, FALLING);
}
void loop(){
if (millis() - lastmillis == 1000){ // Uptade every one second, this will be equal to reading frecuency (Hz).
detachInterrupt(0); // Disable interrupt when calculating
rpm = revolutions * 60; // Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use half_revolutions * 30.
Serial.print("RPM =\t"); // print the word "RPM" and tab.
Serial.print(rpm); // print the rpm value.
Serial.print("\t Hz=\t"); // print the word "Hz".
Serial.println(revolutions); // print revolutions per second or Hz. And print new line or enter.
revolutions = 0; // Restart the RPM counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_shaft, FALLING); // enable interrupt
}
}
void rpm_shaft(){ // this code will be executed every time the interrupt 0 (pin2) gets low.
revolutions++;
}
Can someone please assist me with the correct code?
I need to send the rpm to Blynk app.
I tried it on arduino uno and it works, but have trouble getting it to work on the photon.
Thanks in advance