Rotary Encoder Connections

LesJones

Joined Jan 8, 2017
4,511
Click on the link to the PDF data sheet just below the picture of the encoder in your link. Connect one side of each set of contacts together. That wil then be the common connection.

Les.
 

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Yes, (Or 1 and 4) Either way is functionally the same.

Les.
LesJones Im connecting in that way...but this is working on CW not CCW. I'm using below code.
Code:
// Setting up the counter
int reading = 0;
int lowest = -12;
int highest = 12;
int changeamnt = 1;

// Timing for polling the encoder
unsignedlong currentTime;
unsignedlong lastTime;


// Pin definitions
constint pinA = 12;
constint pinB = 11;

// Storing the readings

boolean encA;
boolean encB;
boolean lastA = false;

void[B]setup[/B]() {
// set the two pins as inputs with internal pullups
pinMode(pinA, INPUT_PULLUP);
pinMode(pinB, INPUT_PULLUP);
// Set up the timing of the polling
 currentTime = millis();
 lastTime = currentTime; 
// Start the serial monitor for debugging
[B]Serial[/B].begin(9600);
} 


void[B]loop[/B]()
{
// Read elapsed time
 currentTime = millis(); 
// Check if it's time to read
if(currentTime >= (lastTime + 5))
 {
// read the two pins
 encA = digitalRead(pinA);
 encB = digitalRead(pinB);
// check if A has gone from high to low
if ((!encA) && (lastA))
 {
// check if B is high 
if (encB)
 {
// clockwise
if (reading + changeamnt <= highest)
 {
 reading = reading + changeamnt; 
 }
 }
else
 {
// anti-clockwise
if (reading - changeamnt >= lowest)
 {
 reading = reading - changeamnt; 
 }
 }
// Output reading for debugging
[B]Serial[/B].println(reading);
 }
// store reading of A and millis for next loop
 lastA = encA;
 lastTime = currentTime;

 }

}
 

bertus

Joined Apr 5, 2008
22,925
Hello,

The difference between CW and CCW is wich signal comes first.

encoder.png

You now only have the A and B signals.

Bertus
 

Kjeldgaard

Joined Apr 7, 2016
476
I have not analyzed the source code in detail, but I'm missing a lastB Boolean variable.

And then the code must be very symmetrical with respect to the Encoder Inputs and the stored Inputs from the previous passes.
 

EM Fields

Joined Jun 8, 2016
583
Hello everyone,
Please guide how do wire to this rotary encoder which one is com and signal pins?
you can find rotary encoder from the link: http://www.piekarz.pl/pl/?item=25879

Thanks
The device appears to be a 2 channel rotary switch with each channel galvanically isolated from the other and designed to output 20 momentary pulses per revolution on one channel (let's call it channel "CW"), and nothing on the other channel (channel "CCW") when the switch is being rotated clockwise. Then, when the switch is being rotated counter-clockwise, channel CCW will output 20 momentary pulses per revolution and channel CW will be silent.

The switch wiring is going to depend entirely on whether you need positive true or negative true signals for the inputs into your SBC, so if you'd post a schematic of how you've got things hooked up that would help us a lot
in getting you where you want to be.
 

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
The device appears to be a 2 channel rotary switch with each channel galvanically isolated from the other and designed to output 20 momentary pulses per revolution on one channel (let's call it channel "CW"), and nothing on the other channel (channel "CCW") when the switch is being rotated clockwise. Then, when the switch is being rotated counter-clockwise, channel CCW will output 20 momentary pulses per revolution and channel CW will be silent.

The switch wiring is going to depend entirely on whether you need positive true or negative true signals for the inputs into your SBC, so if you'd post a schematic of how you've got things hooked up that would help us a lot
in getting you where you want to be.
thanks for your response.
output should be positive when i rotate switch CW and should be negetive when i rotate switch CCW...can the switch provide the above output?
 
Top