I got around to testing multiple chips.
xval = x_encoder.measured_value();
yval = y_encoder.measured_value();
What doesn’t work (yet) is:
My hope was that I could share data and clock amongst a whole bunch of chips, and just hardwire a line to the chip select of each chip. That doesn’t work, and I’m going to have to do some reading about whether it’s even possible.
However, in the meantime, wiring five AS5040’s (or 5045’s or a mixture) is now much easier.
This is something I should have written like five years ago. I’m making an electronic ignition controller for an old sportscar, and need to make a lot of calls to an AS5040 as a throttle position sensor. My old code works, but wouldn’t it be nice to have the rotary encoder work, in code, the way an LCD does? So I wrote a library.
Now I — or you — can write code like:
AS5040 my5040(2,3,4); // data, clock, chip select pins
measured_degrees = my5040.encoder_degrees();
WAAAAY easier and cleaner-looking than the previous pile of code.
So I’ve written encoder_value, giving the raw value (out of 1024 bits for the AS5040 and 4096 bits for the 5045), encoder_degrees (calculated from previous) and encoder_error, which returns a long int containing the errorcodes, but also populates a struct containing all the errors the chip reports so you can check which is occurring without having to unpack the error number.
Library and demo arduino code here: http://madscientisthut.com/forum_php/viewtopic.php?f=11&t=17 along with some instructions on how to install a new library, in case you haven’t done this.