Hi all,

I'm working on a project where I need to send messages from Puredata to Arduino. My goal is to generate control messages within PD, and drive 4 spark plugs which are driven by 4 Arduinos through pwm outs.

I'm using Arduino because when I drive the spark plugs through Bela, it crashes even I'm using optocouplers for isolation. The coils are generating thousands of volts and kicking back some voltages that affects my audio and video monitors as well. However, Arduino does it without getting affected.

So, I will use Arduinos as spark plug drivers, and I want to use Bela as the base, where it sends control messages(frequency, trigger, boolean) to 4 Arduinos at the same time. What would be the best option for this communication. I searched the forum but couldn't find PD to Bela serial communication. If I could compile pd-extended, would it be possible to use comport object and send data to Arduino's TX pin?

Any ideas?

    why not use midi? if you want to send the same message stream to all 4 arduinos, you can get away with one midi output on the BELA. probably easiest to buy a usb to midi converter that you connect to the BELA usb port.

      lokki actually i need separate communication with each Arduino. would it be possible with MIDI?

        bleenisgrue

        sure.

        midi is a protocol that allows up to 16 channels (good old serial midi) on one "line".

        limitations of midi are resolution (a standard midi cc message only has 128 different values, and speed. midi works at 31250 baudrate, hence a message takes roughly 1ms to be sent.

        the resolution thing can be overcome by packing a value into two cc messages, giving you a 14bit value, which should be plenty of resolution.

        boolean should not be a problem (use note on and note off for example).
        trigger, the same note on and note off.

        the questions are:

        -how many different messages do you want to send to each arduino?
        -do you mind the small latency of (serial) MIDI?

        as for the midi connection itself i see two options:

        1) use a usb to serial midi converter and connect the serial midi out to all arduinos, probably you want to build a small midi splitter. i used this schematic once, and it worked great:

        https://moroccodave.com/2017/10/04/diy-midi-thru-box-version-2/

        or you buy one.

        2) program the arduinos in such a way that they represent themselves as usb-midi devices when connected to a pc (or BELA). that way you buy a usb-hub and simply plug-in all arduinos into the host port of BELA. depending on the arduino this reprogramming is easier or harder, but it should work on most arduino boards.
        while this method is "easier" on paper and also faster (usb midi is faster then serial) there is no electrical insulation between bela and the arduinos and hence it could introduce noise as you observed when you only used BELA to drive the plugs. with serial midi you have an optocoupler in the serial line, that should take care of all noises.

          bleenisgrue I'm using Arduino because when I drive the spark plugs through Bela, it crashes even I'm using optocouplers for isolation.

          that sounds weird. how are you powering everything?
          most importantly, are you running bela off the same PSU as some of the other components?

          i'm just asking because i've had Bela crash on me while running it from an old ATX supply's 5v line, with a display (driven by Bela) on it's 12v line. my guess is the startup current peak from the display made the whole thing go unstable for a moment, causing the crash. running everything off its own dedicated supply solved everything.

            lokki

            thanks for the detail explanation!

            lokki -how many different messages do you want to send to each arduino?
            -do you mind the small latency of (serial) MIDI?

            frequency, decay, note on/off. actually midi is perfect match for this task.

            lokki 1) use a usb to serial midi converter and connect the serial midi out to all arduinos, probably you want to build a small midi splitter. i used this schematic once, and it worked great:

            https://moroccodave.com/2017/10/04/diy-midi-thru-box-version-2/

            i will consider this solution but not sure whether the signals will be affected.

            i will do some tests and let you also know the results. thanks a lot!

            Remork

            the spark plug is powered through a seperate 12v adapter, and the arduino's trigger pin is isolated. bela takes power from the computers usb port, but I also tried it with a power bank and it still crashes. Besides, I think arduino generates a better square wave that you can follow from the brightness of the sparks and amplitude of sound.

            o i am ok with using arduinos as spark plug drivers. it's solid. on the other hand, there should be a way of doing the same with BELA but I don't have that much electrical knowledge and experience. so i stick with my current solution.