Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Encoder

2194 Views - Created 22/01/2018

22/01/2018

Posted by:
mediacowboyz

mediacowboyz Avatar

Location:
Amsterdam

Hi guys,



can the ADC Pi Plus is the right board if I want to hookup encoders right?

Do youhave examples of some code?



thanks!

22/01/2018

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hi

What type of encoders do you want to connect to your Raspberry Pi?

If it is a rotary encoder or any type of encoder that has a digital output then the best option would be to connect it directly to the Raspberry Pis GPIO port.

22/01/2018

Posted by:
mediacowboyz

mediacowboyz Avatar

Location:
Amsterdam

HI,

I plan to use 4 encoders and will have a touchscreen installed so I can only use the i2C port..

23/01/2018

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Do you have a part number for the encoders you are using or a link to where you bought them so I can check out how they need to be interfaced with the Raspberry Pi?

24/01/2018

Posted by:
mediacowboyz

mediacowboyz Avatar

Location:
Amsterdam

that would be awesome!

I just bought these:

https://benselectronics.nl/arduino-rotary-encoder/

and also have these:

https://hackerstore.nl/Artikel/88

as well as these:

COM-10982 ROHS

https://www.sparkfun.com/products/10982

I really need the push button functionality. But if there is no other way i can work with analog ones.

many thanks!

24/01/2018

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

The encoders you are using all output a digital signal so the ADC Pi Plus would not be suitable for connecting to the encoders as the ADC sample rate would be too slow to get an accurate reading.

Ideally, you need to connect the encoders directly to the GPIO port on your Raspberry Pi. I have found a tutorial on using encoders with the raspberry pi at https://www.modmypi.com/blog/how-to-use-a-rotary-encoder-with-the-raspberry-pi

The touchscreen you are planning to use should not use all of the available GPIO pins. Most touchscreens will only use the SPI bus and a few other GPIO pins for touch inputs and LCD control. The manufacturer of the LCD should have a schematic diagram showing which GPIO pins are used by the touch screen. Once you know which pins the touch screen uses you can then use any of the remaining GPIO pins to connect your encoders to the Raspberry Pi.

24/01/2018

Posted by:
mediacowboyz

mediacowboyz Avatar

Location:
Amsterdam

thanks!


So I can use any GPIO pin that is free?

Oh and if I add multiple so I need two pins for each additional encoder? or can i reuse one?

24/01/2018

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

You should be able to use any GPIO pin that is free. Ideally, you need two pins for each encoder, or three pins if you need to use the push switch on the encoder as well.

If you don't have enough GPIO pins spare then you could use a multiplexer chip to increase the number of available pins. A multiplexer converts a large number of input lines into a small number of output lines using digital logic. There is a good tutorial on how they work at https://www.tutorialspoint.com/digital_circuits/digital_circuits_multiplexers.htm

If you use a multiplexer then you will need to find one that works at 3.3V to make it compatible with the GPIO port. Something like a CD74HC4051 would probably do the job. The 74HC4051 multiplexer converts 8 inputs into three outputs plus an enable pin to turn the multiplexer on and off so you could read four encoders using four GPIO pins. Basically, the 8 inputs would create a 3-bit binary number on the three GPIO pins so by looking at the 3-bit number you can work out which of the 8 input pins are high and low and from that work out which encoder is currently being turned. You could wire up several multiplexers in parallel with all of the S0, S1 and S2 pins connected to the same GPIO inputs and each enable pin connected to a separate GPIO output. That way you can turn each enable pin on in turn and read the inputs from that multiplexer. This would allow you to add an extra four encoders for only one extra GPIO pin.

You would need a program to continuously monitor the GPIO pins so you don't miss any changes on the encoder inputs.

The multiplexer method is more complicated than wiring the encoders directly to the GPIO pins but it does mean you can use more encoders with only a few GPIO inputs.

24/01/2018

Posted by:
mediacowboyz

mediacowboyz Avatar

Location:
Amsterdam

thanks! Will let you know how it goes!

Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.