Max and Arduino Serial Intermittent.
Hey all, I'm working for the first time with an Arduino; just trying to send some basic hall sensor data
into Max7 with my Arduino Uno.
My problem is it works intermittently. I don't know what to do with that. Literally the serial port might
pick up the signal from arduino 30% of the time. Which I don't understand.
Here's my basic patch:
In arduino:
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
// pinMode(2, input);
attachInterrupt(digitalPinToInterrupt(3), magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
half_revolutions = 0;
rpm = 0;
timeold = 0;
Serial.begin(9600);
}
void loop()//Measure RPM
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
Serial.println(rpm,DEC);
}
}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
half_revolutions++;
Serial.println("detect");
}