Three Problems/questions (hall sensor code)

Hey all, I'm trying to rig up 3 bike wheels and get ticks from the wheels for RPMs.
I'm using Serial.write and such to send data to Max7.

I have three basic problems with the code that follows that I don't understand:

  1. I can only get Pin 2 & 3 to work, I replace the (digitalPinToInterrupt(9): nine with
    another pin and it doesn't work. Only 2 & 3 work. Any ideas why?

  2. How can I do this with 3 sensors? I tried creating three sets of the code, but I'm not
    sure I'm doing it right. Any suggestions would help. See below.

  3. What is that first "Serial.begin(115200)" line do?


volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
// pinMode(2, input);
attachInterrupt(digitalPinToInterrupt(9), 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");
Serial.write(1);
}

//////////////////////////////////////// SENSOR 2 ////////////////////////////////////////

  1. Did you read the attachInterrupt() reference? An Uno(ish) only has 2 external interrupts, pin 2 and pin 3....

  2. Do you really need to get the RPM of three wheels?

  3. Did you read the Serial reference? (Not going to link it for you..)

If you're not interested in helping, then maybe just don't say anything.

Yes I've read the references, I'm new to coding in Arduino (coding in general).

And yes, I really need three difference speed sensors.

Thanks anyways though.

  1. What is that first "Serial.begin(115200)" line do?

Yes I've read the references,

With less attitude and more looking you would have found this Serial.begin() - Arduino Reference

And yes, I really need three difference speed sensors.

If you only have two external interrupts on your model Arduino, you will have to use a pin change interrupt to pick up the third wheel. A good library is PinChangeInterrupt.h by Nico Hood. It is available through the ide.

Other Arduino models have more than two pins that support external interrupts. I have no intention of telling you which ones, though, since you can't be civil.

pauleary:
If you're not interested in helping, then maybe just don't say anything.

I helped you just fine :wink:

pauleary:
Yes I've read the references, I'm new to coding in Arduino (coding in general).

Then maybe you need help with reading and this is the wrong forum. Because it's explained into detail in the reference pages.

pauleary:
Thanks anyways though.

Fixed it :wink: Don't be an *ss to the people who help you. As always, the answers are as good as the question. We can't help you didn't read the reference pages :slight_smile: