lesterlo / Notched-Shaft-Encoder

Control a Notched Shaft Encoder with and Arduino
MIT License
7 stars 1 forks source link

Enabling HD44780 LCD Support breaks encoder #2

Closed LoungeFlyZ closed 3 years ago

LoungeFlyZ commented 3 years ago

I started with just using the serial output and everything worked well. I turned it clockwise and then counter clockwise and here is the output i got the following as expected:

Encoder Position: 1
Encoder Position: 2
Encoder Position: 3
Encoder Position: 4
Encoder Position: 5
Encoder Position: 4
Encoder Position: 3
Encoder Position: 2
Encoder Position: 1
Encoder Position: 0

Then i enabled HD44780 using #define DISPLAY_MODE 2 and tried again. However this time the same rotary changes gave erratic output:

Encoder Position: 1
Encoder Position: 2
Encoder Position: 3
Encoder Position: 2
Encoder Position: 3
Encoder Position: 4
Encoder Position: 5
Encoder Position: 6
Encoder Position: 5
Encoder Position: 6
Encoder Position: 5
Encoder Position: 6
Encoder Position: 7
Encoder Position: 8
Encoder Position: 9
Encoder Position: 10
Encoder Position: 9
Encoder Position: 10
Encoder Position: 9
Encoder Position: 10

You will notice the duplicates and that it only ever counted up.

I have the rotary encoder using pins 10, 11 and 12. And the HD44780 using SDA & SCL on my Leonardo.

Any idea what might be going wrong?

LoungeFlyZ commented 3 years ago

I found that this was being caused by not using two interrupt pins for the rotary encoder. The LCD library must also use interrupts and it conflicts I think. I switched to an Arduino Mega which has more interrupt pins and used two for the encoder and its all working correctly now. Closing this issue.

lesterlo commented 3 years ago

Yes, the encoder library needs interrupt pins to operate.

If you have any question. Please feel free to find me again.