adrpi
Posts: 1
Joined: Sat Mar 22, 2014 9:48 am

reading encoder channels

Sat Mar 22, 2014 10:32 am

Hello everyone,

I am a beginner with the Raspberry Pi and I want to use it to control DC motors to conduct some experiments. I have an incremental encoder with two channels A and B in quadrature and I want to connect those channels to the pins of the Raspberry to count the pulses and get the position of the motor to which the encoder is attached. I am powering the encoder with the 3.3V source of the Raspberry, so when I rotate the rotor of the motor the measured voltage between the channels of the encoder and GND switch between 0 and 3.3V. The hardware specifications of the encoder say that the max current flowing from any of the channels of the encoder is 5mA. My question is: can I connect DIRECTLY the encoder channels to two pins of the Raspberry Pi and read their digital value without damaging the board? What is the maximum current that the pins can get when configured as digital inputs? I do not want to damage the Pi.

I want to configure the pins as digital inputs using something like this (Python):

chA = GPIO.input( xx )

I have attached a diagram to help explain the situation. I hope I have explained clearly the doubt.Can this be achieved as I propose or is it wrong?

Thank you very much in advance :)

Adrian
Attachments
encoder_pi_question.png
Diagram of the connection between the Raspberry Pi and the incremental encoder.
encoder_pi_question.png (20.31 KiB) Viewed 1631 times

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: reading encoder channels

Sat Mar 22, 2014 10:57 am

It might be best to post the specs of the encoder.

The ones I've seen have open collector outputs A and B which may be connected directly to a Pi gpio. The gpios then have their internal pull-ups enabled. That means A and B read 1 (pull-up to 3.3V) or 0 (pulled down to ground as the encoder spins).

http://abyz.co.uk/rpi/pigpio/python.html

http://abyz.co.uk/rpi/pigpio/code/rotary_encoder_py.zip

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: reading encoder channels

Sat Mar 22, 2014 10:59 am

adrpi wrote:What is the maximum current that the pins can get when configured as digital inputs? I do not want to damage the Pi.
In the same way that a 5V/100A PSU wouldn't harm the Pi if connected as a power source, your input to a GPIO pin set up as an input won't harm it if it's within design voltage limits. Current is something that an input sinks at will, not something that an attached device forces through it.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: reading encoder channels

Sat Mar 22, 2014 12:39 pm

Apart from the above, you might like to consider what happens if you do something wrong - for example, setting the two GPIOs as outputs and sending 3v3 while the encoder is trying to send 0v (or vice versa)

Putting a resistor between the GPIO pin and the encoder, of perhaps 1k, will limit the current in either case to 3.3 mA

Return to “Automation, sensing and robotics”