Rotary Encoder RPM?
Hello, I have purchased the Incremental Photoelectric Rotary Encoder - 400P/R (SKU:SEN0230)
Do you have sample code for Arduino to find out the RPM of how fast the Encoder is spinning?
Thanks in advance!
Do you have sample code for Arduino to find out the RPM of how fast the Encoder is spinning?
Thanks in advance!
2018-06-15 04:57:43 Hi, thank you for the reply. I did see that already and it looks like it just increments depending on the direction the encoder spins. Here is my current solution to detect how fast it is spinning:
Code: Select all
alex volatile unsigned int flag_A = 0;
unsigned long previousMillis = 0;
const long interval = 50;
void setup() {
pinMode(A_PHASE, INPUT);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt( A_PHASE), interrupt, RISING);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.print(flag_A);
flag_A = 0;
}
}
void interrupt(){
flag_A += 1;
}
2018-06-13 10:11:15 There is a code to count the cylinder number of the encoder in the wiki https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0230 robert.chen