Encoder

MGLove

New member
I am struggling to get an encoder reading with the 4rel4in HAT. I have the "a"encoder wired to the IN1-com and "b" to the IN2-com. I am powering from another source. I can get the Relays to turn on and off so I know i have the library loaded. I am trying to have the encoder count for me or just give me a signal for A and B .
Thanks for your help
 

alexburcea

Moderator
Staff member
Hi,

The encoder function is not enabled by default so you have to enable it. Open a terminal and type "4rel4in 0 cfgencwr 1 1" or use the set_encoder_cfg function in python.
 

MGLove

New member
Hi,

The encoder function is not enabled by default so you have to enable it. Open a terminal and type "4rel4in 0 cfgencwr 1 1" or use the set_encoder_cfg function in python.
No luck attached is my Python code simple just to get a feel of how it should work
 

MGLove

New member
Cant copy my code here but I have everything else working do you have any sample code I could look at. I have set_encoder_cfg(1,0) and (1,1) if i set to (1,1) I get an repeating 1 and same with 0. looking for 32 bit
 

alexburcea

Moderator
Staff member
Hi,
This is the way you ca use the encoder except the fact that there are 2 lines of code that does not do anything. Adding the readed value with the total variable which you just put zero into it will have no meaning. The get_encoder() function will give you the accumulated value so you do not need to keep a variable for that.
Can you tell me which encoder you use and how you wire it to the card?
 

MGLove

New member
My simple code.
Hi,
This is the way you ca use the encoder except the fact that there are 2 lines of code that does not do anything. Adding the readed value with the total variable which you just put zero into it will have no meaning. The get_encoder() function will give you the accumulated value so you do not need to keep a variable for that.
Can you tell me which encoder you use and how you wire it to the card?
 

Attachments

  • encoder.jpg
    encoder.jpg
    22 KB · Views: 5
  • Wire2.jpg
    Wire2.jpg
    32.8 KB · Views: 4

alexburcea

Moderator
Staff member
Hi,
A datasheet for the encoder and a wiring diagram will be helpful. Is hard from the picture to see where you connect the wires but the fact that there're only 2 is definitely wrong. The inputs are optoisolated so you have to power the optocoupler LED, this lead you 2 wires per channel and the encoder have 2 channels, totally 4 wires (or 3 if one is common).
I tested with something like this https://www.farnell.com/datasheets/2006163.pdf
 

MGLove

New member
Sorry about the delay. atttached is a copy of the Data sheet. again if you have an encoder that you know will work I will find one.
 

Attachments

  • PAGE6_500_Series_datasheet_eng.pdf
    282.7 KB · Views: 2
Top