I am using Feather M4 express development board with DC Motor + Stepper FeatherWing and Ethernet FeatherWing stacked on it. The idea is to control the steps of the stepper motor by reading the encoder values. The SPI bus is shared between the Ethernet FeatherWing and the AS5045 encoder and they have their unique CS pins.
I am using this library for reading the encoder values. The encoder board is connected to the main board using cables. Since the encoder is operating on 5V logic while the Ethernet board on the 3.3V, I am using a level shifter for the encoder board.
Using this setup, only the EthernetWing seems to work but not the encoder as it always reads a full scale value. Removing the EthernetWing and connecting the encoder directly in its place with 5V power works as the encoder reads all the correct positions. Is the level shifter not compatible with this current design? How can this issue be solved?
#include <AS5045.h>
#include <Adafruit_MotorShield.h>
#define CSpin 9
#define CLKpin 25
#define DOpin 23
AS5045 enc(CSpin, CLKpin, DOpin);
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
uint16_t angle = 0;
void setup() {
Serial.begin(9600);
if (!enc.begin())
Serial.println("Error setting up AS5045");
Serial.println("Stepper test!");
if (!AFMS.begin()) {
Serial.println("Could not find Motor Shield. Check wiring.");
}
else {
Serial.println("Motor Shield found, reading encoder");
}
myMotor->setSpeed(60);
}
void loop() {
myMotor->step(50, FORWARD, DOUBLE);
Serial.print("Encoder reading: ");
angle = enc.read()* 0.08789;
Serial.println(angle);
delay(100);
}