Hello there,
For a project I am working with the Bela mini capelet in conjunction with Trill sensors. I am using SuperCollider and found the TrillCentroids and TrillRaw UGens on the github of Jonathan Reus - and this works great with the TrillSquare, TrillBar etcetera.
Right now I am trying to figure out how I can get the readings from the TrillFlex into SuperCollider. When I run the flex-default and flex-visual examples, everything works smoothly.
But when I run my SuperCollider code, I get a:

Unable to identify device
ERROR: Unable to initialize touch sensor```

Is it possible to use the Flex with the TrillCenroids or TrillRaw UGen? 
And if yes, am I doing something silly? 
I know that the i2c address of the flex is 0x48.

This is my SuperCollider code:

s = Server.default;

s.options.numAnalogInChannels = 8;
s.options.numAnalogOutChannels = 8;
s.options.numDigitalChannels = 16;

s.options.blockSize = 16;
s.options.numInputBusChannels = 2;
s.options.numOutputBusChannels = 2;

s.options.postln;

s.waitForBoot {

SynthDef(\sketch, {|t_recalibrate=0.0|
		var i2c_bus = 1;
		var i2c_address = 0x48;
		var thresh = 0.22; 
		var prescaler = 1;
		var touchsigs = DC.ar(0).dup(3);
		var centroids;
		var out, ping;
		
		centroids = TrillCentroids.kr(i2c_bus, i2c_address, thresh, prescaler);
		
		touchsigs[0] = CombC.ar( Pluck.ar(WhiteNoise.ar, (centroids[2] > 0 ), 0.2, centroids[1].linexp(0.0, 1.0, 70, 300).reciprocal, 5, 0.9), 0.5, centroids[1].linexp(0.0, 1.0, 0.01, 0.5), 3.0 );
		
		touchsigs[1] = PMOsc.ar((centroids[3]+0.001) * 2500, 500, centroids[4].linexp(0.0, 2000, 0.1, 12.0), 0.1, mul: 0.5) 
		* EnvGen.ar(Env.perc, (centroids[4] > 0.0), timeScale: centroids[4].linexp(50, 500, 0.3, 5.0));

	// touch3 another percussive plucky sound with pull-off behavior
		touchsigs[2] = Resonz.ar(
		Pluck.ar(PinkNoise.ar, (centroids[6] < 0.05), 0.2, centroids[5].linexp(0.0, 1.0, 80, 1000).reciprocal, 3, 0.5, mul: 6.0),
		centroids[5].linexp(0.0, 1.0, 800, 2400), 0.1, 4.0).tanh;
	
		out = Splay.ar(touchsigs);
		
		SendReply.kr(Impulse.kr(8), "/trillcentroiddata", centroids);
		
		ping = EnvGen.ar(Env.perc, t_recalibrate) * SinOsc.ar(440);
		
		Out.ar(0, out );
		//Out.ar(0, ping);
		
	}).add;
	
	s.sync;
	~tr = Synth(\sketch);
	OSCFunc(\trill, {|msg| msg[3..].postln }, "/trill");
	
	// Illustrates how to recalibrate the Trill sensor's baseline value if the touchpad configuration changes
	{
		loop {
			55.wait;
			"Reset baseline in 5s...".postln;
			5.wait;
			"Baseline reset!".postln;
			~tr.set(\t_recalibrate, 1);
		};
	}.fork;

};


Any advice very much appreciated. 

All the best,
Sjoerd

Hmm at a quick look at the source code, I'd expect this to work out of the box when built against a Trill library with Flex support. This is located within the Bela source tree.

Is it possible that you last built your Sc ugens with an older version of the Bela code that didn't have support for Trill Flex? Or even that you never had to build it because you were using the binaries that ship with it? Those binaries probably don't support Flex, because they were built before it was added to the library.

If you have ever built these ugens before, it should be "as easy as" rebuilding them with the newer Bela core code in place.

Thanks a lot for the suggestion, Giulio.

After building the UGens on the Bela, the Flex indeed gets recognized. Yet the readings of the Flex don't make any sense. I suspect that is because there goes something wrong with the shared library when I am building. When I add this last snippet (taken from Jonathan Reus' README file) to the CMakeLists.txt:

# Build the shared library
add_library(${PROJECT} MODULE
  ${FILENAME}
  ${BELA_PATH}/libraries/Trill/Trill.cpp
)

I get this error:

CMake Error at CMakeLists.txt:28 (add_library):
  add_library cannot create target "TrillCentroids" because another target
  with the same name already exists.  The existing target is a module library
  created in source directory "/root/Trill_SC/Bela_UGens/TrillCentroids".
  See documentation for policy CMP0002 for more details.

When I leave the snippet out, the building goes ok, but then the readings of the flex are static / don't react to my touches.
I suspect that the missing shared library snippet is the reason that the readings of the Flex don't make any sense?

Apologies, I don't build / CMake on a regular basis.

Kind regards,
Sjoerd

    minnowahaw but then the readings of the flex are static / don't react to my touches.

    You will need to change the prescaler value to 4 for Trill Flex to work . It looks like that's one of the arguments to the constructor: https://github.com/jreus/Trill_SC/blob/master/ext/Trill/TrillUGens.sc .

    minnowahaw When I add this last snippet (taken from Jonathan Reus' README file) to the CMakeLists.txt:
    ...
    I get this error:

    I think that documentation is outdated. I think the CMake files are ready to use as they are. Just use cmake and make with the stock files (I think).

      Good to know it works! This ugen probably needs to be refactored so that if no value is passed for prescaler it uses the one that is default for each sensor type (which is what the C++ library does).

        3 years later

        giuliomoro

        Hi Giulio,
        Because it seems the Bela Mini audio input is broken - I am trying to build the Trill Ugens for SuperCollider on another Bela (so I will be able to use some Trill Flexes and a Trill Craft). But the building process is not going as smooth as the last time.
        After doing:
        cmake -DSC_PATH=~/supercollider3.12.1/ -DBELA_PATH=~/Bela/ ..
        inside the build directory of the TrillCentroids it still seems to go allright:
        -- The C compiler identification is GNU 6.3.0
        -- The CXX compiler identification is GNU 6.3.0
        -- Check for working C compiler: /usr/bin/cc
        -- Check for working C compiler: /usr/bin/cc -- works
        -- Detecting C compiler ABI info
        -- Detecting C compiler ABI info - done
        -- Detecting C compile features
        -- Detecting C compile features - done
        -- Check for working CXX compiler: /usr/bin/c++
        -- Check for working CXX compiler: /usr/bin/c++ -- works
        -- Detecting CXX compiler ABI info
        -- Detecting CXX compiler ABI info - done
        -- Detecting CXX compile features
        -- Detecting CXX compile features - done
        -- Configuring done
        -- Generating done

        But after I hit make I get:

        Scanning dependencies of target TrillCentroids
        [ 33%] Building CXX object CMakeFiles/TrillCentroids.dir/TrillCentroids.cpp.o
        /root/Trill_SC/Bela_UGens/TrillCentroids/TrillCentroids.cpp:8:23: fatal error: SC_PlugIn.h: No such file or directory
        #include "SC_PlugIn.h"
        ^
        compilation terminated.
        CMakeFiles/TrillCentroids.dir/build.make:62: recipe for target 'CMakeFiles/TrillCentroids.dir/TrillCentroids.cpp.o' failed
        make[2]: *** [CMakeFiles/TrillCentroids.dir/TrillCentroids.cpp.o] Error 1
        CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/TrillCentroids.dir/all' failed
        make[1]: *** [CMakeFiles/TrillCentroids.dir/all] Error 2
        Makefile:83: recipe for target 'all' failed
        make: *** [all] Error 2

        It seems to have something to do with the supercollider source code I'm pointing to? Or am I seeing this wrong?

        I got the latest Trill_SC code from your github.

        All the best,
        Sjoerd

        is /root/supercollider3.12.1/ present on the board you are running this from?

        giuliomoro Thanks! I found out that scp -r on windows was leaving out some directories, like include, when copying the source code to the Bela. When I use scp -r on linux the full source directory is copied as expected. I just rebuilt the UGens and now all the flex sensors are working again. Great, thanks!