sure, can we have a look?
Documentation on I2C ?
Hey all, I'm again in the (painful) process of interfacing Bela via i2c to some devices, in this case the NeoTrellis board from Adafruit. Last time I was working with i2c on Bela there was a better-i2c branch in development that seemed very nice. With that I was even able to get the data straight into PD and bypass completely the custom render.
I see though that it never made it to the master branch!
giuliomoro, what would be the easiest way to adapt the latest branch to have the same functionality?
Thanks for everything!
ah that branch brings so many headaches to my memory! It was abandoned because it was under tested and then everything else moved further, leaving it lagging behind, so that now it would be fairly convoluted to backport those changes ... Also, many i2c devices have a complicated communication protocol that is best deal with through a dedicated C++ library, than trying to do it from Pd...
Is there a Linux library available for your device? That would be the first thing to know.
In the case of our new Trill sensors, I integrated into the default_libpd_render.cpp
a way to interface to a C++ library from Pd. All the TRILL-related code is included by the ENABLE_TRILL
. That gives you an idea of the extent of work that would be required to integrate other similar features.
An alternative to integrating it in the render file as done above, would be through an OSC layer. I have done that for Trill, too (to support people who do not use Bela, or those who use something else than Pd or C++ on Bela), so it's another example of what it would take to turn an existing, working library into an OSC-compatible one (see here).
giuliomoro Hey Giulio, thanks for answering!
Unfortunately the NeoTrellis (based on the Adafruit Seesaw) do not have a linux library. Its Arduino library seems too big to be ported, at least for my skills.
Maybe with the I2c utility functions that HjalteBestedMoeller was talking about it would be easier to start making a stripped version of it. I found the basic i2c class to lack the utilities to read and write i2c commands.
Do you know if there is a i2c library similar to the Arduino Wire library for Bela/BeagleBone?
Or if you know some better approaches, let me know!
Sindel I found the basic i2c class to lack the utilities to read and write i2c commands.
Yes, that was a design choice: while most I2c devices work the same way in terms of reading and writing, that is not part of the i2c protocol itself. However, in the better-i2c
branch I had indeed added such functions.
Sindel Unfortunately the NeoTrellis (based on the Adafruit Seesaw) do not have a linux library. Its Arduino library seems too big to be ported, at least for my skills.
link to the library? I'd be happy to have a look.
Sure, here it is: https://github.com/adafruit/Adafruit_Seesaw
And thanks for taking a look!
In the meantime I'll try to port back the functions from the better-i2c
branch and see where it takes me.
It would seem that this "seesaw" board only requires I2C. It is definitely adaptable, but it requires some time. There are only a handful of Wire functions in use, and all should be fairly easy to emulate:
Adafruit_seesaw.cpp:764: _i2cbus->begin();
Adafruit_seesaw.cpp:787: _i2cbus->beginTransmission((uint8_t)_i2caddr);
Adafruit_seesaw.cpp:788: _i2cbus->write((uint8_t)regHigh);
Adafruit_seesaw.cpp:789: _i2cbus->write((uint8_t)regLow);
Adafruit_seesaw.cpp:799: _i2cbus->endTransmission();
Adafruit_seesaw.cpp:807: _i2cbus->requestFrom((uint8_t)_i2caddr, read_now);
Adafruit_seesaw.cpp:810: buf[pos] = _i2cbus->read();
Adafruit_seesaw.cpp:836: _i2cbus->beginTransmission((uint8_t)_i2caddr);
Adafruit_seesaw.cpp:837: _i2cbus->write((uint8_t)regHigh);
Adafruit_seesaw.cpp:838: _i2cbus->write((uint8_t)regLow);
Adafruit_seesaw.cpp:839: _i2cbus->write((uint8_t *)buf, num);
Adafruit_seesaw.cpp:855: _i2cbus->endTransmission();
Adafruit_seesaw.cpp:910: _i2cbus->beginTransmission((uint8_t)_i2caddr);
Adafruit_seesaw.cpp:911: _i2cbus->write((uint8_t)regHigh);
Adafruit_seesaw.cpp:912: _i2cbus->write((uint8_t)regLow);
Adafruit_seesaw.cpp:916: _i2cbus->endTransmission();
I would be surprised if no one already implemented the methods in Wire.h
on Linux, e.g.: for a Raspberry Pi ...
Thanks for the summary of the i2c functions!
In any case I could find only one implementation of the Wire library for BeagleBone, here [https://github.com/AbhraneelBera/wiringBone/]. If you tell me that it won't conflict with the other pin setting in Bela I will give it a try!
giuliomoro Sure, I was simply thinking about read/write utilities along what I implemented in I2cFunctions in this project:
https://github.com/HjalteBested/BelaMPU9150
I just thought that many people would write some very similar code, so it would be nice with a more streamlined approach.... Function for readByte, writeByte ,. readBytes, writeBytes to handle consecutive addresses.... could also have writeReg16, readReg16 etc..
readBit, writeBit.
- Edited
A couple of us over here have been using the Neotrellis with Bela/PEPPER using Adafruit's Python library.
Audio processes written in C talk to an OSC server written in Python which drives the Neotrellis. With this decoupling, the Neotrellis can be connected to the Bela or to a remote host (eg I glued a Pi Zero to it once).
Performance is poor, we are more interested in having the Neotrellis hooked up to the Bela directly now, and we are not interested in using Python for this aspect of things anymore. So just putting this here. Poking around regarding Seesaw support in Rust or C; will review what's posted here.
plate-of-shrimp Hi! I'm also interested in connecting NeoTrellis directly to Bela using I2C. Did you have any success doing this? Thanks!
- Edited
Hi @Lia !
On the C front, Adafruit's Seesaw/NeoTrellis library is on top of Arduino, so I have tried to skim off the non-Arduino bits and replace the pure I2C bits by talking to i2c-dev as exposed by the Linux kernel. I can get a plausible hardware ID from the NeoKeys but can't light up a NeoPixel yet.
On the Rust front, cross-compilation seems to reveal a possible library-version-skew problem wrt linux-embedded-hal
, which I hoped I could use to leverage stuff in embedded-hal
that supports Seesaw (and hence NeoTrellis). Upshot is I can't cross compile. So I tried native compiling and things never finish, it looks like I just run out of memory. Well, there were reasons people were cross-compiling in the first place.
(if we get any further with this we should break it out to a new topic.)