Hi All,
First time post, but I've used the forum in the past for projects so thanks to all you guys for the help so far.
I have a HEDS 9000 optical encoder and the matching wheel. I've mounted it as per the instructions and I've had it working using various interrupt codes from the 'Reading Rotary Encoders' part of this site. And then it stopped working - no software change, no hardware change. At first I thought it was the encoder, so I bought a new one, but still the same problem. The setup is now as simple as possible - channel A and B on pins 2 and 3 respectively and 5V and GND wired up appropriately. It had been working reliably and without issue and now all I get is is a 0 1 read out in to the serial port when I rotate. If I remove channel B it jumps to the next series and then when I put it back in again and remove it it continues in the same manner. The other way round (i.e. channel A removed and B remains in) nothing happens. This makes me think there is no signal coming from channel B and only one from channel A which would mean the encoder was faulty but this seems unlikely as its brand new. I've checked and checked I have A and B going to 2 and 3 and the gnd / 5V correctly hooked up. When I swap in for a simple mechanical encoder it works fine - i just can't figure out what the problem is. Any ideas or thoughts would be gratefully received
HEDS 9000 Optical Encoder Reader:
http://docs-europe.electrocomponents.com/webdocs/12cd/0900766b812cdcb6.pdf
Rotary Encoder section on this site:
http://playground.arduino.cc/Main/RotaryEncoders
The library which seemed to work best:
http://www.pjrc.com/teensy/td_libs_Encoder.html
Without the encoder, if you set pins 2 and 3 to INPUT_PULLUP and jumper them to ground can you see a 1 and 0 when you print out of the digital read values of the pins as the ground wire is connected and opened? It is possible that the Arduino has a bad input.
What do you see when you reverse pin 2 and 3 between A and B and run the encoder?
When I swap in for a simple mechanical encoder it works fine
Can your read both directions with the mechanical encoder? Is the code to interpret the quadrature states the same for both the optical and mechanical encoder?
Hi cattledog, thanks for the response.
I will try what you suggest to check the board but I've tried the set up on two different Unos and I see the same problem each time.
When I switch the inputs around on pins 2 and 3 the direction is reversed.
The mechanical encoder works in both directions.
The codes I've been using for optical and mechanical encoder are the same - which seemed to be fine in the past.
Does this all point to a faulty encoder?
I've double checked on a different uno board and see the same behaviour.
If you're uncertain of whether it's a faulty encoder or arduino, you should test each seperately. Like cattledog said, test the arduino inputs you're using by initialising them with the pull ups. Then just do Serial.println(digitalRead(pin1)); for each input pin and you should see the serial monitor going between 0 and 1 depending on whether you've connected the pin to ground or not.
To test the encoder, connect the vcc to 5v and gnd to gnd, then use a multimeter to test whether the encoder is outputting signal voltages. If you touch the black probe on gnd and the red probe on either channel a or channel b. You should see the voltage go between 0v and 5v as you rotate the encoder wheel. If there is no change, there could be a problem with encoder.
If the voltages are going high and low as expected, and the input to the arduino is working OK, then there is probably an issue with the code somewhere.
Lawmate, thanks very much for the response. Yep, I think the next thing to do is check the signal from the encoder. I'll do as you suggest and report back.
I've tested with a multimeter. Channel A is giving a signal which varies from 0.05V to 4.9V, channel B is sitting a 0.04V and the NC pin is giving a signal of 0.3V to 2.9V but takes a lot longer to rise and fall than channel A. Connecting the NC pin to one of the interrupts doesn't change my output from a series of 0 and 1s.
I guess this means my encoder is faulty.
At first I thought it was the encoder, so I bought a new one, but still the same problem.
I guess this means my encoder is faulty.
An encoder which died, and then a bad one to replace it is an improbable scenario. It may be correct, but it makes me question what is going on.
Do the encoder and wheel come as a pair, and you replaced both? I don't know what could be wrong with the code wheel, but if it was not replaced, you might want to investigate its condition. Perhaps its not aligned correctly.
Can you test the encoder without the code wheel? If without the wheel in place you can see both A and B high, and then both low if you block the slot you can possible separate encoder/code wheel issues.
Update: tested on an oscilloscope - it seems one of the channels isn't working...encoder number three ordered - hope this one works!
Hi,
Check the circuit you are connecting the encoder to, make sure its input is not a short to gnd.
Tom......