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?

  • \$\begingroup\$ Use I2C instead. \$\endgroup\$
    – Eugene Sh.
    Commented Nov 24, 2020 at 18:25
  • \$\begingroup\$ I checked Arduino Micro schematics and UART pins are not same as USB pins so UART pins are free. Are we looking at the same schematics? \$\endgroup\$
    – Justme
    Commented Nov 24, 2020 at 18:37
  • \$\begingroup\$ This exhibits a fairly complete misunderstanding of the situation. Doing it all in one processor would be normal (see any 3d printer) but NO, the 32U4's serial interace has nothing to do with its USB interface. This needs more research and an edit creating a complete re-write before there would be a valid and answerable question here. \$\endgroup\$ Commented Nov 24, 2020 at 18:38
  • \$\begingroup\$ I am pretty sure that this problem is totally solvable with good coding. It seems very unlikely that all 6 Hardware timers and the SPI interface(which CLK could be used for this task) are occupied. But to give you good advice: You can use a UART Multiplexer, AND-Gates or buffers for changing between Rx/Tx channels, maybe you can even use the RST signal to change direction. Your suggestion is alslo possible but a little hacky - you should cut the lines between UART to Serial converter and the µC, not the USB side. \$\endgroup\$ Commented Nov 24, 2020 at 18:38
  • \$\begingroup\$ The UART RX and TX are not tied to the USB bus on the Arduino Micro. They are free to use \$\endgroup\$
    – StarCat
    Commented Nov 24, 2020 at 20:00

1 Answer 1


After looking more into pin 0 & 1 and having helpful comments, it turns out they are a separate hardware serial pin from the USB serial. They are "Serial1" which is different than "Serial" found from the USB.

I've tested this with a basic setup and the micro was able to communicate with both my computer via USB and the Mega board at the same time.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.