After waaaaaaay too long, I finally got around to porting the Arduino AS5040 code to python. This is very preliminary, but it does work.
As self-hosted versions of wordpress appear to do a lousy job of formatting, and python is formatting-specific, I’ll put the code on github where I can guarantee that it looks the way it should: https://github.com/smellsofbikes/AS5040_python_beaglebone
import Adafruit_BBIO.GPIO as GPIO
def read_raw_val(data, chip_select, clock):
a = 0
output = 0
readbit = 0
while a < 16:
readbit = GPIO.input(data)
output = ((output << 1) + readbit)
a += 1
rawval = read_raw_val(“P9_15″, “P9_11″, “P9_12″)
print “read: ” + str(rawval)
print “raw rotation: ” + str(rawval >> 6)
I still need to strip and decode errors, extend it another two bits for the AS5045, and make the whole thing into an importable library.
Note that on the Beaglebone, the Adafruit GPIO library doesn’t yet fully support setting pull-up or pull-down resistors on pins. As such, you may have trouble with some pins not working. I know these three pins work, because I’ve tested them. The code should work for Raspberry Pi without any problem, and at some point I’ll port this to Bonescript, where I do have control over setting the internal pull-up and pull-down resistors, so any set of I/O pins can be used.