I just made this, let me know if there is anything missing: https://github.com/BelaPlatform/Bela/wiki/Load-a-device-tree-overlay

emerson Also, I'm using Arduino Uno, will I need a level shifter, or is that just for I2C?

You surely need the digital signals going into Bela to be maximum 3.3V. You can probably do with just a passive resistor divider for the Arduino outputs and probably the Arduino inputs will be triggered just fine by a 3.3V signal from Bela (but I am not a 100% sure, as I don't have the specs handy and I have not tried this myself), so you may not need level shifter at all. Give it a try!

Great, thanks, will give this a try.

2 months later

Hello, finally had time to come back to this, but can't seem to get it to work.
So far I've:

  • Loaded the UART4 device tree overlay
  • Set up a simple sketch on an Arduino Uno which writes a single number to serial
  • Wired up the Arduino to send this data from D1 to Bela P09_11, via a logic level converter (https://www.sparkfun.com/products/12009), sharing common ground.
  • Set up a simple _main.pd patch which should receive the serial data through the [comport] object and print it to the console.

But so far, nothing. I know in this thread (https://forum.bela.io/d/620-bela-mini-midi-input-on-uart0) you mentioned not to use [comport] but said it may work if it uses pd's own functions. Thought I'd give it a try but not sure at what point it's failing.

I've looked at the other threads (eg. https://forum.bela.io/d/104-usb-serial-port-input-into-bela/11) and I can't really follow how to pick up serial in C++ first then send it to PD. Is there a simpler way to get serial data into PD?

    can you try to receive the bytes from the terminal using screen ?
    That would be

    screen /dev/ttyS4 115200

    assuming 115200 is the speed of the port.

    emerson But so far, nothing. I know in this thread (https://forum.bela.io/d/620-bela-mini-midi-input-on-uart0) you mentioned not to use [comport] but said it may work if it uses pd's own functions

    Did you compile [comport] for yourself ? Does it show an error message in the console like "couldn't find [comport]" ?

    5 days later
    a year later

    Hello, i want to setup i2c-communication (with bela as master and arduino uno as slave.) i followed this tutorial for doing this with raspberry pi + arduino : https://www.youtube.com/watch?v=me7mhrRbspk&t=1203s and succesfully controlled the arduino led from the bela using a python script. now i want to send some bytes to the arduino from a pd patch running on my bela. how can i tell pd to send something to a slave adress?

    How good is your C++? Looking at the Trill library should be a good starting point for your application. What sort of messages are you trying to send? Are you also receiving messages?

    My C++ is not that fantastic. I do want to receive messages back. right now i'm just trying to send some ints to the arduino and print them in the serial port (and send them back to pd); in the end i want to read out some sensor values and receive them on the bela. I tried loading the default_libpd_render.cpp, I2cRt.h and I2cRt.cpp from the better-i2c branch into my project, but i get the next error: variable type 'I2cRt' is an abstract class column: 7, line: 36
    /root/Bela/projects/Swept_Cap_Sensor_Project/render.cpp:36:7: error: variable type 'I2cRt' is an abstract class
    I2cRt i2c;
    ^
    ./include/I2c.h:33:14: note: unimplemented pure virtual method 'readI2C' in 'I2cRt'
    virtual int readI2C() = 0;
    ^
    1 error generated.
    make: *** [/root/Bela/projects/Swept_Cap_Sensor_Project/build/render.o] Error 1

    the better-i2c branch has a lot of good things that were almost working at the time, but won't necessarily easily work now. I tried to do a quick git rebase, but it's not so straightforward. As for the specific error you are getting you should also load the include/I2c.h file from the same branch.

      giuliomoro giuliomoro thanks, i got it working with the test values 🙂 i only get 1 warning at build: In file render.cpp: [warning] unused variable 'pd_that' [-Wunused-variable] column: 22, line: 407 ; but I noticed that in the latest default libpd render.cpp file (from the master branch) that te line t_pdinstance* pd_that = (t_pdinstance*)arg;, which is generating this warning is completely gone. I think it is from an old libpd version, but I'm not sure what it does. My test values are coming through, so I think i can just ignore the warning/ delete this line. (?)

      Yes you can delete it.. So are you using the code from the other branch in the end?

        giuliomoro yes i am using all code from the better-I2c branch; (libpd_default_render.cpp , i2C.cpp , i2c.h , i2cRt.ccp i2cRt.h , ringbuffer.c and ringbuffer.h) I just merged it with another project, and it's working fine.

        giuliomoro now everything works, I want to compile this project with hvcc; it compiled succesfully, but i don't receive messages from the slave device anymore, also it doesn't send the messages to the slave device. I am using the render.cpp from/better-i2c/scripts/hvresources/render.cpp . in the 'libpd version' i am sending a couple of messages from my pd patch to the receiver "bela_i2c" , and am receiving messages in pd with a receive object "bela_i2c_in". they are defined in the default_libpd_render.cpp from the better-i2c branch. (but i can't find any reference to these in the heavy version of the render.cpp ).. only thing i found is : // unlike libpd, no need here to bind the bela_digitalOut.. receivers
        // but make sure you do something like [send receiverName @hv_param]
        // when you want to send a message from Heavy to the wrapper.
        I figured i probably have to do something with this, but C++ is new to me. i'm able to understand code, and alter it a bit to do what i want, but if i'm writing /adding new code myself I don't know excactly what I am doing. Could you help me put this in the heavy version of the render.cpp?

        getting there ... I rebased that branch on top of the current dev (here), and everything seems to be working ok, although it surely could be optimized a bit. Next step: heavy!

        giuliomoro the compiler seems to have trouble with finding the "I2cRt.h" file . echo 'Building render.cpp...'
        Building render.cpp...
        g++ -I/root/Bela/projects/CapSens_HEAVY_2 -I./include/legacy -I./include -I./build/pru/ -I./ -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -march=armv7-a -mfpu=vfp3 -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ -D__COBALT_WRAP__ -DXENOMAI_SKIN_posix -DXENOMAI_MAJOR=3 -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize -ffast-math -DNDEBUG -DBELA_USE_RTDM -I/root/Bela/resources/stretch/include -save-temps=obj -std=c++11 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"/root/Bela/projects/CapSens_HEAVY_2/build/render.d" -o "/root/Bela/projects/CapSens_HEAVY_2/build/render.o" "/root/Bela/projects/CapSens_HEAVY_2/render.cpp"
        /root/Bela/projects/CapSens_HEAVY_2/render.cpp:45:19: fatal error: I2cRt.h: No such file or directory
        #include <I2cRt.h>
        ^
        compilation terminated.
        Makefile:459: recipe for target '/root/Bela/projects/CapSens_HEAVY/build/render.o' failed
        make: *** [/root/Bela/projects/CapSens_HEAVY/build/render.o] Error 1
        make: Leaving directory '/root/Bela'

        I tried compiling two different projects: one with files from the old better-i2c branch; (the libpd version builds and works fine) and the other one is the same project but with all files updated to those of the rebased better-i2c branch. they gave me excactly the same results.

        also, you might want to know: when i updated the default_libpd_render.cpp file to the rebased one, it gave me some errors:


        no matching member function for call to 'sendBuffer' column: 8, line: 202 and
        no matching member function for call to 'sendBuffer' column: 10, line: 214

        ./libraries/Gui/Gui.h:128:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, std::vector<T,A> & buffer)
        ^
        ./libraries/Gui/Gui.h:135:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, T (&buffer)[N])
        ^
        ./libraries/Gui/Gui.h:142:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, T value)
        ^
        /root/Bela/projects/I2c_Rebase/render.cpp:214:10: error: no matching member function for call to 'sendBuffer'
        gui.sendBuffer(bufNum, s, strlen(s));
        ~~~~^~~~~~~~~~
        ./libraries/Gui/Gui.h:128:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, std::vector<T,A> & buffer)
        ^
        ./libraries/Gui/Gui.h:135:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, T (&buffer)[N])
        ^
        ./libraries/Gui/Gui.h:142:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
        int Gui::sendBuffer(unsigned int bufferId, T value)
        . because it said: requires 2 arguments but 3 were provided, i removed the second argument in the corresponding functions: removed "buf"in gui.sendBuffer(bufNum, buf, argc - 1); (line 202) and "s" in gui.sendBuffer(bufNum, s, strlen(s)); (line 214) Again, i do not know excactly what this is doing; but only after removing these arguments the project built and the libpd version worked with no problems.

        It seems like you are just copying files in from one branch to another. That is a recipe for disaster, as you find yourself in a situation where a file (e.g.: core/default_libpd_render.cpp) relies on the version of libraries/Gui/Gui.h that is available on both the dev and better-i2c-rebased branches. Similarly, the render.cpp file for heavy that you are using relies on I2cRt.h to be present in the include/ folder, as it is in the better-i2c-rebased branch. To try out a branch properly, you have to update all the codebase at the same time. This procedure is explained here.

          giuliomoro Thanks, that did the job! i feel a bit stupid for not reading that myself to begin with 😛 the project now compiled to heavy succesfully; only one problem left; I think the Trill library isn't working correctly on this branch : the other project that i wanted to merge it with now doesn't want to build anymore, I get the error: In file libraries/Trill/Trill.cpp: use of undeclared identifier 'i2C_file'; did you mean 'i2cFile'? column: 33, line: 92 libraries/Trill/Trill.cpp:92:33: error: use of undeclared identifier 'i2C_file'; did you mean 'i2cFile'?
          if(int writtenValue = (::write(i2C_file, buf, bytesToWrite)) != bytesToWrite)
          ^~~~~~~~
          i2cFile
          /root/Bela/include/I2c.h:27:6: note: 'i2cFile' declared here
          int i2cFile = 0;


          and 12 more errors similar to this on other lines. they all refer to "i2c_file".
          (i tried altering the Trill.cpp file in my downloaded "better-i2c-rebased" folder on my pc accordingly, rezip it and update the board with the altered branch, but that didn't work, it even showed the exact same errors. probably not at all the way to do this but at least i wanted to give that a try before i did another post)