arduino to raspberry to pure data

Hello, I have an arduino MEGA connected to a touchscreen, 2 rotary encoders and 12 buttons via GPIO. On the other side I have a Raspberry pi 3B+ with a HifiBerry DAC+ADC running pure data. I want to use the Raspberry as a sampler/synth and arduino as a controller AND a GUI. What I do understand is that there are 2 ways to interface arduino with raspberry (GPIO and USB).

GPIO (Rx Tx) would be perfect as I already done that between two arduinos interfaced with a custom made protocol, however the Hifiberry HAT is sitting on top of all Raspberry GPIOs. I guess I could use cables between the pins that Raspberry and HifiBerry need to talk to each other, thus freeing up the Tx and Rx pins of Raspberry (Hifiberry does not use them).

Second option, USB, is even easier regarding hardware connections, just plug-in the USB cable and Raspbian detects the arduino. What I do not understand is how to interface arduino with PureData. I would really like to avoid PDuino and Firmata, as it would be extremely difficult if not impossible to use the touchscreen this way. My project requires: 1. reading a specific folder from the Raspberry file structure and desplaying it to the Touchscreen so that the user can choose which soundset is going to be used 2. sending a command from the touchscreen to save PRESETS on the raspberry 3. sending PLAY/STOP/VOLUME/PITCHBEND/etc commands to Puredata.

Can anyone guide me please? Thank you

What I do not understand is how to interface arduino with PureData.

You can use a serial input to PD. Like here:-

It dosn't matter where the serial comes from just so long as you define the correct com port in PD.

However, if you are using the serial on the GPIO port then you need signal level translation between the Arduino and the Pi, a simple potential divider may work.

The other way is that you could interface PD with the simple GPIO pins, not just the serial ones. Then connect the Arduino outputs through a potential divider to the GPIO pins and read them from PD. You need the code that links Wiring Pi to PD, you can get this from:- this comes in the form of a .tar file, and to decompress this, navigate to the download folder in a terminal window and type:- tar -vxf Pd-wiringPi.tar Drag the resulting Pd-wiringPi directory to the home/Pi directory, and that should be it. Despite what the ReadMe file says their is no need to compile anything. For further details see the "Bounce Theremin" article in the MagPi No70. Free download.

Thanks Mike!!!