I'd like to communicate with the Bela wirelessly and with low latency. My idea is to use and ESP32 and ESP-NOW, which I can observe less than 5ms latency. From the ESP32 to the I was thinking I2C or SPI. I'm learning towards SPI since it's full duplex. Any thoughts on this approach? Anybody tested the difference in latency between SPI and I2C?
SPI vs i2c with regards to latency
I2c is a slower bus with. It has a bit clock up to 400kHz and some extra overhead that reduce the useful data rate further. SPI can be faster (up to 48MHz on the BBB). However, if the amount of data to be transmitted is not particularly high you may just go with whichever seems easier (e.g.: whichever the Linux library you will be using for your device (assuming there is one that works already) ). Also another note: on the BBB (Bela) there is no spare SPI bus available, as the only one available is already in use by the Bela analog I/O, so you'd be forced to use I2C unless you can run without the analog I/O. On the PB (BelaMini), there is one SPI bus available. There are 2 I2C busses on each of Bela and BelaMini
Thanks giuliomoro, I have the BelaMini and I'm using C++. A simple example is that input on the ESP32 would cause a sound to play on the BelaMini. Data will flow back to the ESP32, but that latency is not as important in that direction. I suppose I could use 2 I2C to get full duplex. Overall the path looks like this:
ESP32 <--- ESP-NOW ---> ESP32 <-- SPI/I2C ---> BelaMini
How about overall latency from SPI/I2C to the C++ interface? Any ideas of the difference there? I'm guessing the software stack is also a factor?
And for the complexity of the libraries, and ideas on which is easier? I saw SPI libraries mentioned in the forums and some code checked into git. Is there a major difference in complexity from C++?
Thanks, Paul
- Edited
PaulELong How about overall latency from SPI/I2C to the C++ interface?
there wouldn't be much difference there. The SPI library on Bela tends to be easier to use but that's not because it's particularly better than the I2C one, rather because the I2C way of combining transmit and receive in the same transaction is intrinsically more flexible and complicated.
Another idea: if latency is a big concern and you have relatively few data to transmit (e.g.: a few triggers), you could use the ESP32's GPIO outputs into Bela's digital inputs, 16 of which are sampled at audio rate at low latency.
Thanks so much giuliomoro, I think the using GPIO is a good solution for me. I would still need the data transfer, but I think the number of triggers will be really small, one to start I will go the SPI route and test latency with it and GPIO.