• HardwareSolved
  • Passing a variable from Bela (pd) to Raspberry Pi, Teensy etc.

Hi, I am planning an installation with both audio and visuals (pixel mapping on LED-strips). My audio is happening on a Bela (pd sketch). I want to pass on a single (or maybe two) float(s) from my Bela to a Pi from where I would run my visuals in order for them to be affected by variables from the Bela. How can I do this? I considered serial/midi but I can't figure out how that would work. I've looked around in this forum and while I find some things regarding interfacing different platforms I struggle to de-code how to apply it to my case.

I hope you can help!

Best,
Simon

    the two best options are probably MIDI or network. Over network, you'd use Pd's [tcpsend] or [udpsend]. For MIDI, if you were to plug Bela straight into the Pi via USB, it would show up also as a MIDI device, so you could use port hw:0,0,0 from the Bela side to send/receive MIDI to the Pi. Otherwise, you could use maybe two cheap USB-to-5-pin MIDI devices (one on each computer) interfaced together.

    If you are using a Teensy, then the best option would be to configure the Teensy as a USB MIDI device and then you'd access it from Pd on Bela the way you access MIDI devices normally.

      a year later

      giuliomoro rostami
      Hello there.
      I'm tussling to get the Bela to send commands to a Raspberry Pi via MIDI. However the devices aren't seeing each other (I used amidi -l to check on the Bela). I've tested them both independently with an old MIDI keyboard (using a USB-to-5-pin-MIDI cable), and this shows up fine in both cases. I'm currently using a USB cable straight from the USB-A of the Bela to a USB-A on the Pi, while I've been basing my efforts on instructions from here https://howchoo.com/pi/raspberry-pi-midi-keyboard-synthesizer as a starting point, but no joy. Any thoughts as to what I should do?

      It seems like you have a host to host USB connection, which is not supported by the standard, is that right? You'll need to plug the Bela into the Pi, or the Pi into the Bela, assuming in the latter case that your Pi can be configured to show up as a USB Midi device

        giuliomoro
        As things stand, both remain blissfully unaware of the other - the whole question of configuring of a Pi as a USB Midi device does seem to be something of a conundrum, from what I can gather. Would your suggestion

        giuliomoro you could use maybe two cheap USB-to-5-pin MIDI devices (one on each computer) interfaced together

        circumvent those difficulties? I'm wondering this because both Pi and Bela seem happy to acknowledge the old midi keyboard through a USB-to-Midi connector. I'm thinking two MIDI-USB cables with the MIDI outs and ins of both cables connected. I don't mind kludgy if it gets me where I want to go!

        sorry I still don't understand how these boards are connected to each other, could you please explain?

          giuliomoro At the moment the machines are connected as follows: Bela's USB-A - as in, the USB host port - to a USB-A 2.0 on the Raspberry Pi 4B, with a standard USB cable.

          As context, what I'm hoping to do is this: have Bela running a Pd patch which responds to incoming sensor data, while it passes that sensor data on to the Raspberry Pi; the RPi would use that sensor data to run a Pd patch of its own, which features the Ofelia external to output realtime responsive visuals. My idea is to spread the load according to priority - the Bela with its nifty low latency handles the audio response, while the RPi can follow along and do the interactive visuals - the RPi will generally be more laggy anyway, but I'm less concerned about that - for now at least - when it comes to the visual side.

          I guess I thought MIDI would be a handy way of going about it, as it's something I'm familiar with. If it came to it, I know I could instead pursue sending the sensor data directly to the RPi as well as to the Bela, but I'd rather have the Bela sending data to the Pi, if possible, as this would open up other avenues.

            Tractor giuliomoro At the moment the machines are connected as follows: Bela's USB-A - as in, the USB host port - to a USB-A 2.0 on the Raspberry Pi 4B, with a standard USB cable.

            Still confused by the USB-A to USB-A connection. Can you show a picture?

              yeah, this will not work. one of the two has to be the client, in order to send/reveive midi. so for example plug the client usb port of the BELA (the mini usb) into one of the host-ports of the RPi

                lokki Thanks lokki. I'll have a go at that when I finally get back to the bench...

                3 years later

                giuliomoro Over network, you'd use Pd's [tcpsend] or [udpsend]

                Hello, I'm quite new to Bela and linux embedded systems in general (have a little experience with RPi OS (desktop version) though) and curious if it's possible to establish direct connection between RPi (or any other computer) and Bela using ethernet cable (without a router)?
                I have a similar idea of communication between RPi (doing some openCV things) and Bela responding to it. Usage of OSC is obviously preferable over MIDI protocol..

                At the moment I am trying to establish/test connect between Bela and my old MacBook via the cable without luck: trying to "ping bela.local" from terminal give no results, so I can't figure out how to find ip.
                I also found this thread
                https://forum.bela.io/d/31-connecting-via-ethernet/11
                and was trying to power up Bela with cable plugged but I doesn't help

                I also read these instructions
                https://github.com/BelaPlatform/Bela/wiki/Interact-with-Bela-using-the-Bela-scripts#changing-defaults
                but not sure if it relates somehow to my situation connecting directly without a router.

                Would be grateful for any help!

                to connect directly without a router the easiest approach is to set both endpoints to a static IP address. On Bela, that's achieved by editing /etc/network/interfaces and replace the entry

                allow-hotplug eth0
                iface eth0 inet dhcp

                with something like:

                allow-hotplug eth0
                iface eth0 inet static
                    address 192.168.8.2
                    netmask 255.255.255.0
                    network 192.168.8.0

                and then reboot. This will put it on a 192.168.8.x network with IP address 192.168.8.2. The other endpoint should be on the same network with a different address.

                On the Pi you should be able to do:

                sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.8.3/24 ipv4.method manual
                sudo nmcli con up "Wired connection 1"

                this will put it on the 192.168.8.x network with IP address 192.168.8.3.

                  giuliomoro thank you so much!
                  Everything works fine as for now. I am communicating via ethernet cable from Mac.
                  Hope to setup RPi soon.

                  4 days later