I have a working project around an Arduino Leonardo. It acts as a midi controller with one motorized fader, one button and an encoder.
I want more faders, buttons and encoders but scaling up I need more inputs/outputs than the Leonardo can handle.
So I successfully added a shift register for the h-bridge controlling the motor (from the motorized fader), but using shift registers doesn't work with the libraries i'm using for encoders and buttons. You can't refer to pins in the code with shift register, so it breaks my code.
I started trying I2C communication between the Leonardo and a Mega board, the mega could handle the number of pins needed. With this method, I feel like there is latency and the motor behavior is erratic.
So do you think I should rewrite code to follow with I2C or shift registers ? Is there another path ? (a board acting like an HID device with as many pins as the mega for example)
I believe you could follow a hard path to making the Mega into an HIDUSB capable board. But it is a slog and less than ideal for developing on.
Adding a second microprocessor for more pins is plausible but also introduces another kind of fun you'll be having quite a bit of doing.
As more of a software hacker, I would spend the time
unbreaking the code.
There may be libraries for the shift register that offer superior ways of dealing with the pins which might mean bringing your code into compliance would not be as hard.
Sketches can only be loaded to the Arduino when the 8U2/16U2 is running the arduino-usbserial.hex driver. You must flash this firmware back to the Arduino using DFU mode before you can load a new sketch.
and was reminded why ppl don't usually.
If indeed you need to go through the entire process back and forth to get a revised sketch in there, I would recommend postponing using the Mega until I was very sure the sketch was ready to go. Finding a trivial error woukd become a huge amount of work if you use the try this try that stuff we can find ourselves doing.
Keep in mind that the Due is an old board with IMHO poor software support. (Their compiler is stuck at GCC 4.8.5, which doesn't even have non-experimental C++11 support; the current release of GCC is 14.2).
You may want to have a look at the Control Surface library: it has an "ExtIO" framework that supports shift registers and multiplexers to allow building large MIDI controllers.
It also supports motorized faders, but it off-loads the actual low-level motor control loops to separate microcontrollers which communicate movement and setpoint changes to the main microcontroller over I²C.
Thank you for answering. I'm using this library for buttons and encoders, but I didn't use it for the motorized faders. I have to test it it.
I didn't know I could use it with shift registers and multiplexers, I'll read about it!
For users reading this post, I followed PieterP's advice and it was a good choice. The library and documentation are very good. I didn't expanded it with more than one AT328p at the moment, but I will in the future.