You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having an issue with basic encoder functionality using Arduino Due specifically (code works on Arduino Mega no problem). It can be worked around by not using interrupts. However, it would be good for my application to be able to use interrupts.
Steps To Reproduce Problem
I used the attached code to perform the read function from this library. This works no problem on the Arduino Mega. However, on the Arduino Due, the read function works only when I use #define ENCODER_DO_NOT_USE_INTERRUPTS. When that line is not included, the CLK and DT values update as expected for the Due, but myEnc.read() returns a constant 0.
Hardware & Software
Arduino Mega 2560 R3 and Arduino Due
Arduino IDE 2.0.0-rc2
Encoder.h 1.4.2, Arduino SAM Boards (32-bits ARM Cortex-M3) 1.6.12 for Due, and Arduino AVR Boards 1.8.4 for Mega
Windows 10
Arduino Sketch
#defineENCODER_DO_NOT_USE_INTERRUPTS// this line is required for Due to function properly, can be disabled for Mega
#include<Encoder.h>// Encoder library available at https://www.pjrc.com/teensy/td_libs_Encoder.html// This should automatically set these pins to interrupt mode
#defineENCODER_CLK_PIN19
#defineENCODER_DT_PIN18
Encoder myEnc(ENCODER_DT_PIN, ENCODER_CLK_PIN);
int previous_encoder_pos = 0;
int current_encoder_pos = 0;
voidsetup(void) {
Serial.begin(9600);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Encoder test!");
}
voidloop() {
current_encoder_pos = myEnc.read();
if (current_encoder_pos > previous_encoder_pos){
Serial.print("DT: ");
Serial.println(digitalRead(ENCODER_DT_PIN));
Serial.print("CLK: ");
Serial.println(digitalRead(ENCODER_CLK_PIN));
Serial.print("current_encoder_pos = ");
Serial.println(current_encoder_pos);
}
elseif (current_encoder_pos < previous_encoder_pos){
Serial.print("DT: ");
Serial.println(digitalRead(ENCODER_DT_PIN));
Serial.print("CLK: ");
Serial.println(digitalRead(ENCODER_CLK_PIN));
Serial.print("current_encoder_pos = ");
Serial.println(current_encoder_pos);
}
previous_encoder_pos = current_encoder_pos;
}
The text was updated successfully, but these errors were encountered:
Description
Having an issue with basic encoder functionality using Arduino Due specifically (code works on Arduino Mega no problem). It can be worked around by not using interrupts. However, it would be good for my application to be able to use interrupts.
Steps To Reproduce Problem
I used the attached code to perform the
read
function from this library. This works no problem on the Arduino Mega. However, on the Arduino Due, theread
function works only when I use#define ENCODER_DO_NOT_USE_INTERRUPTS
. When that line is not included, theCLK
andDT
values update as expected for the Due, butmyEnc.read()
returns a constant 0.Hardware & Software
Arduino Mega 2560 R3 and Arduino Due
Arduino IDE 2.0.0-rc2
Encoder.h 1.4.2, Arduino SAM Boards (32-bits ARM Cortex-M3) 1.6.12 for Due, and Arduino AVR Boards 1.8.4 for Mega
Windows 10
Arduino Sketch
The text was updated successfully, but these errors were encountered: