Library for reading positions from CUI Devices/Same Sky 12-bit AMT absolute encoders
This implements the protocol for 12-bit encoders and has been tested with RS-485 variants (AMT21-series). It should work with any variant that is accessible via an interface that appears as a serial device and would be trivial to change to support 14-bit position data, but I haven't done this because I don't have a 14-bit encoder on hand.
Note that these encoders are synchronous, so this library has been implemented accordingly.
To connect an AMT212A, AMT213A, AMT212E, or AMT213E, you'll need the following:
- FTDI USB-RS485-WE-1800-BT
- Molex 502578-0601 connector plug body/housing
- 4x Molex 2157111122 pre-crimped leads
If in doubt, check the documentation for both the FTDI adapter and the encoders. The contact positions are counted left-to-right from the back side of the Molex connector plug body/housing with the clip pointing up. Match the colored wires on the FTDI adapter cable to these positions:
- Red (5V)
- Yellow (B)
- Orange (A)
- Black (GND)
Plug the completed USB to RS-485 adapter into an open USB port on your computer and the other end into your encoder.
These use a different Molex connector plug/housing. See the documentation for details.
Assuming all the defaults are correct for your environment: You have a 2Mbaud variant encoder, you have connected the encoder to your computer using a USB to RS-485 cable that appears as /dev/ttyUSB0 (described above), and you have permissions to access this device, the following is all you need to do to see it read positions with a 100ms delay between each read:
git clone https://github.com/memory-hole/amtenc.git && cd amtenc
python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt
python3 amtenc.py
The only dependency outside python3 is the pyserial library (pyserial/pyserial GitHub Repo, pyserial PyPI Project).
Included is a requirements.txt for the lone requirement:
pip install -r requirements.txt
Alternatively, you can install the library system-wide:
sudo apt-get install python3-pyserial
apk add py3-pyserial
pip3 install pyserial
The following assumes that you have an A variant encoder with a 2Mbaud serial rate. If you don't, you'll need to adjust the baud and timeout values to work with your encoder.
Copy the amtenc.py file into your project and import it:
from amtenc import AMT_12bit
Elsewhere, you can initialize it like so:
enc = AMT_12bit()
Then you can read it:
position, valid = enc.read()
Note that in addition to the MIT license that applies to this code, it in turn depends on the following libraries with the indicated licenses:
| Library | License |
|---|---|
| pyserial | BSD-3-Clause |