Hi all !. I’m currently building a robot (details will be updated later) for which I will need position data from an absolute encoder. In this walkthrough, I will explain how to interface an absolute encoder with a Raspberry Pi 3.
The encoder i’m using will be this : mouser absolute encoder
An absolute encoder returns position data as ‘grey codes’, through a synchronous serial interface (SSI) protocol. We will use a raspberry pi to extract this data from the encoder and turn it into valuable position information.
The mouser EMS22A50 is a 1024 ppr absolute encoder whose datasheet is available here. We will receive the absolute position data from the encoder by programming the raspberry pi in python to communicate, following the Synchronous communication protocol. For simplicity of this tutorial, I have ignored checking parity bits. We will only extract the 10 bit data from this encoder.
Above picture illustrates the output waveform from the DATA OUT pin of the encoder.
The EMS22A50 comes with a panel mount pin configuration, which means it cannot be mounted on a breadboard. We will follow this trick to interface this encoder with a raspberry pi : Take a female to female jumper wire. Pluck out the black strip out of one of the ends. Now plug in the metal connector into the encoder’s pins as shown in the picture below.
Your final setup should look like this :
“Make things simple, but not simpler” – Einstein.
Follow the same wiring pattern as programmed in the Python script. The script for polling the encoder data can be found in my repository here.
I have removed delay between two clock edges because of the inherent delay in polling caused by the GPIO library in raspberry pi. Source : benchmark.
UPDATE : I have updated the code to attach several of these sensors to the raspberry pi. Just connect the pins as in the code. I soldered a GPB to branch out VCC, CLK, CS and GND, as shown in the pic below :
Results : values ranging from 0-1023 that maps linearly between 0-360 degrees.
Thanks for reading ! If you think this article helped you, follow my blog for more cool stuff. Need more help ? shoot me a mail !.