I’m designing a custom, Arduino Mega2560 based, PCB for my project. One of its job is to run a bipolar stepper motor via a TMC driver amongst many other things.
From what I know, the AccelStepper library works by sending a pulse whether it’s due for one in the run() command. Because of the other parts of the codes taking up time in the loop, my max step speed would be a lot lower than the 4000 steps/sec the Mega would be able to do.
One workaround I’m thinking is adding a dedicated ATMega32U4 (Arduino Micro) just for running the stepper so it can maintain the 3000-4000 steps/sec. The Mega will communicate with the 32U4 via hardware serial (baud rate set at 115200) to update the stepper motor’s motion.
Here is the tricky part; the 32U4 only have one hardware serial port (pin 0 and 1) but it’s also tied to the USB interface. Since D+ and D- pin is connected to the USB data pin, does that mean pin 0 and pin 1 is also tied to D+ and D- pin? This confuses me in how I should wire the pins.
I was thinking of a slide toggle switch to switch between the 32U4 being connected to a USB port or being connected the hardware serial port of the Mega uC chip. My thinking is I’d use the USB port to upload the sketch. Then I’d use the slide switch to break USB port line and reroute it to the Mega as it waits for commands. Do I break the D+/D- line or the D0/D1 or both?