What would be the easiest, quickiest and dirtiest way to communicate both? In two scenarios

1- unidirectional. Sending data from arduino to the Bela (just to send a number of "data channels" and their values, from data captured through an arduino analog&digital pins)
2- bidirectionally

I would eventually do it with the multiplexer capelet, but some sensors do require switching the analog inputs to voltage sources (for example, for resistive touch screens) and I don't think that could be done.

    Have you tried what @dr.offig suggested in the other thread ? That should satisfy your 1-.
    As for 2-, building on top of that example it should be easy to write to the serial port.

    jeppius You may find that using I2C is easier than serial, especially for bi-directional communication.

    You can use the Arduino Wire library to configure the Arduino as a slave device, then use the Bela_I2C library to write bytes to and request bytes from the Arduino. I've done this before and it works well.

    Note that the Bela_I2C library is still under development, you need to update to the dev-i2c branch in the repo and look at examples/06-Sensors/i2c-accelerometer to see how to use it. It is not yet documented properly, and can still occasionally cause mode switches if you write or request too many messages at once (though this is unlikely to be a problem in your case).

    Alternatively you can use the regular linux API to access Bela's I2C port from an auxiliary task.

    You might also need to use a level shifter because the BeagleBone's I2C is at 3.3v while the Arduino's is at 5V by default...

    I think I'll try this as a way of getting an OLED to work with an AVR instead of the Bela. I'm having no luck finding a working C++ library for LCDs for BBB.

    10 months later

    Hi, just resurrecting an old thread. I do need to send data from a 3.3 arduino to Bela, what would be the advantages and disadvantages of using either Serial or I2c?
    In case I resort to I2C, is there any working example with this specific scenario? I know the accelerometer and capacitive examples but they are specifically tailored to those ic's. So what should be done to receive data from an Arduino?

      I think serial would be easier to set up: just load the appropriate device tree overlay to enable one of the serial ports of the beaglebone(e.g.: UART4 gives you RX on P9_11 and TX on P9_13) and you are ready to communicate back and forth asynchronously.

      If you were to implement an I2C communication, you would have to make one device the master, the other the slave, assign an address to the slave and then have the master initiate each transmission. However, you may get higher throughput with the I2C, so I would only go I2C if you need to transmit lots of data.

      jeppius capacitive examples but they are specifically tailored to those ic's.

      In your case, you would have to implement the communication protocol on the two devices, so it would be entirely up to you, you can make it as complex as you want and need.

        5 days later
        10 months later

        Hello, I'm also trying to send data from Arduino to Bela.

        For serial communication, you mentioned loading the appropriate device tree overlay - and suggested UART4 - how is this done? Will this disable Bela's analog inputs?

        Also, I'm using Arduino Uno, will I need a level shifter, or is that just for I2C?
        And do I need to consider anything else to get this to work within a pd patch?

        Thanks!

          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?