I have an Arduino uno here, which shows up as /dev/ttyACM0, the program runs and can successfully open the serial port.
Try the following:

  • your code is trying to open /dev/ttyUSB1, but the error dialog references ttyUSB0, so maybe you are addressing the wrong device?

  • check you are addressing the device with the correct name. From the console in the IDE, run
    ls /dev/ttyUSB* and see what is there. If nothing shows up, try
    lsusb to check that the USB device is actually recognized

  • I would not be surprised if the Arduino needed to be connected before you power up the BeagleBone. So make sure the Arduino is connected when you start the BeagleBone.

indeed, it was the wrong device.. it opens with ttyUSB0 🙂
thanks for checking!

So the next step is to squeeze in the checking-for-incoming-serial-data, parsing that and sending it to the pd-patch.

would that go into the render function?
Anyway, time to take a break; better to look at that tomorrow 😉

You would need a separate thread to monitor the serial port. You could then set a global variable from it. Then from the audio thread (e.g.: inside render) you would read the content of the global variable and send a message to a receiver in Pd, using a syntax like this:

	libpd_float("yourReceiver", state);

this would send to a [r yourReceiver] object in libpd.
In order to do this you'd need a Pd project with a custom render.cpp file. See the example 08-PureData/customRender.

On the other hand, the [serial] object is supported by libpd(though I have not tested it), so you may skip all you've done so far and simply try running your Pd patch with the [serial] object in it.

On the other hand again, I would ask you: why do you need Arduino for this application? Is there no way you could connect your device straight into Bela?

thanks!

the libpd-approach seems to make more sense then.
can't find the [serial] object though. Could it be [comport]?
I managed to install that on my mac, but can't figure out how to do that with bela...

but i can try to be patient and wait for the step-by-step guide 😉

The reason why I attempt it via the Arduino is composed of these parts:
- I'd like to use the same pedal (and other components) in multiple setups, depending on context; also with Max on my laptop, which works nicely plug-and-play via USB connection.
- I'd like to learn how to do that
- experimenting with other sensors that I know how to handle in arduino, incl. pre-cooking the data
- making it easier to experiment for students who have Arduino experience

The [serial] object exists in Pd 0.46. To be honest I am not sure what that does, I never used it and there is no help file for it. The little I understand by looking at its source code is that it may be a Win32 only object and may require the GUI and so I have to take back what I said earlier: I don't believe it will work on Bela.

Also had a look at the source of [comport] and it seems that it is polling the port in the audio thread which is especially evil on Bela.

You better keep going the custom-render.cpp route outlined above, also because it is the one you will learn the most from.

ok,that sounds like the best approach then!

is there anything else necessary to get the connection to pd working than

1) #include <libpd/z_libpd.h> , #include <libpd/s_stuff.h>
2) libpd_float("arduino", 440); // in render()
3) a receive object in pd called 'arduino'
?
Can't get it to work... Do I need to register anything?

your receiver object should be

 [r arduino] 

Check out this section of the libpd wiki

And the render.cpp file should live in the same folder as your project ( to make sure it is getting compiled and linked in, try to add a printf statement in setup() and make sure it shows up on the console).

alright so I misunderstood your previous question.
You DO need more than the 3 things you outlined above. Actually you need quite a lot more than that.
Your project currently does not use libpd at all, does not open a patch, does not feed data through it, does not process Pd messages.

You'll need to start from core/default_libpd_render.cpp or examples/08-PureData/customRender/render.cpp as a starting point and add your code to it.

This should be made clearer in the example and in the wiki.

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