a year later

dr-offig looks nice, by the way, what wold be the next step? I mean, would you have a sample render.cpp file which makes actual use of the Serial port, sending and receiving formatted data?

7 months later

Hello. Sorry for bringing back an old request. I actually would like to do exactly what jeppius is doing. Taking Midi Data from Arduino Uno USB to my Bela running a Pd patch. Unfortunately I am really new to Bela and I can't get to do the custom render project to work even after updating the render.cpp file. Is there any chance I can have the some further guidance or (if its not too much) ask for the complete project with the _main.pd and render.cpp file included?

What do you mean MIDI data from the Arduino ?can you tell us a bit more about your setup?

I have an Arduino that produces midi notes and sends them to a DIN output through its TX port in a circuit.
This is based on the MIDISprout code and circuit found on "https://github.com/electricityforprogress/MIDIsprout"

I would like to send those notes either through USB or the DIN port to Bela running a PD patch.
I prefer PD since I am not much of a C++ coder.
Eventually I would need to send the audio produced from the PD patch
through multiple outputs of an audio expander capelet.

I believe I am doing something wrong with the PD patch. So I have [r arduino] inside but I only get 0 after I print it in the console. Does this mean that it receives nothing or is it something that needs to be processed more in order to have a midi note format?

If you receive a 0, it means that a message is actually coming through, although perhaps not in the format you expect. Can you post your render.cpp and _main.pd? (maybe use https://pastebin.com/ if they are large)

    10 days later

    giuliomoro hello giuliomoro. I managed to solve this with extra hardware. I bought a cheap midi interface which should do the job for now. I hope I can get to my solution after my exhibition

    a year later

    So I've run into, hopefully, one problem with the USB device input.
    I've looked over the discussion here and worked through the code examples, compiled them and run them.
    However, I'm not getting any input.
    The read() seems to block.
    If I do > "screen /dev/ttyAMC0 115200" I don't see anything either.
    It works on my Mac with the appropriate device though.

    I'm running the BB Black with the Bela audio cape.
    I've plugged the USB cable into the A device on the Black and the external device is a Teensy 3.2

    Has anyone an example serial code that works with the USB A connector on the Black?

      Alistair screen /dev/ttyAMC0 115200

      is that definitely the right device number? What does ls /dev/tty/AMC0 return?

      Do you mean /dev/ttyACM0?

      0 crw-rw---- 1 root dialout 166, 0 Oct 16 05:58 /dev/ttyACM0

      It appears associated with the USB Type A connector on the BB Black.

      I can open the device but it hangs.
      Am I missing something here?
      Any ideas much appreciated.

        Alistair Do you mean /dev/ttyACM0?

        I mean whatever you were using in screen. According to your previous post, it was

        Alistair "screen /dev/ttyAMC0 115200"

        but maybe that was a typo?

        Do you get anything helpful in dmesg?

        @dr-offig's example linked above should work, because it was reading from a Arduino connected over USB as far as I can tell.

        Looking more closely at the device type it is different from other tty devices.
        It is the only device with those major and minor numbers but that may not be an issue.

        0 crw--w---- 1 root tty     240,  0 Oct 16 05:58 /dev/ttyGS0

        This is interesting also.
        It appears to be a character device though.

        And some more info:

          File: /dev/ttyACM0
          Size: 0         	Blocks: 0          IO Block: 4096   character special file
        Device: 6h/6d	Inode: 14407       Links: 1     Device type: a6,0
        Access: (0660/crw-rw----)  Uid: (    0/    root)   Gid: (   20/ dialout)
        Access: 2019-10-16 05:58:29.736796001 +0000
        Modify: 2019-10-16 05:58:29.736796001 +0000
        Change: 2019-10-16 05:58:29.736796001 +0000
         Birth: -

        dr-offig's code hangs. I've tinkered with that for ages.
        I don't know what

        #include <rtdk.h>

        is. So I commented it out.
        It compiles and runs but nothing happens.

        Actually, no it doesn't compile as is:

        /root/Bela/projects/Serial3/render.cpp:148:15: error: no matching function for call to 'Bela_createAuxiliaryTask'    ttyTask = Bela_createAuxiliaryTask(readSerialPort, 50, "bela-arduino-comms");

        Is there any code simpler than this?

        are you sending anything from the teensy? The port is open as "blocking" (i.e.: O_NONBLOCK is not set in the flags to open()), so it's normal for read() to hang until data is received. If you want to wait with a timeout you will need to use poll() or select() before reading.

        Many thanks it compiles and runs.
        Yes, the Teensy sends data from sensors to trigger audio file playback.

        Thanks again.