Bela Trill on Arduino

Hello everyone.
I'm working on a modular synthesizer controller project with Bela Trill sensors and I'm having some trouble using multiple sensors.

My goal is to use multiple trill sensors, hook it up to Arduino Uno to control separate PWM output values. For example, Trill Bar sensor to control anlalog output 9's PWM value and Trill Circle sensor to control analog output 10's PWM value. I'm using Trill Hub to connect multiple sensors into Arduino Uno.

So far, I got one output working but I'm having trouble running multiple sensors simultaneously and outputting separate values.

Below is the code I put together. I'm relatively new so I'm not even sure if it's achievable with Arduino Uno.

Thank you in advance for the help.

#include <Trill.h>

Trill trillSensor;
boolean touchActive = false;

void setup() {
  // Initialise serial and touch sensor
  Serial.begin(115200);
  int ret = trillSensor.setup(Trill::TRILL_BAR);
  if(ret != 0) {
    Serial.println("failed to initialise trillSensor");
    Serial.print("Error code: ");
    Serial.println(ret);
     pinMode(9, OUTPUT);
  }
  //int ret1 = trillSensor.setup(Trill::TRILL_RING);
  //if(ret1 != 0) {
    //Serial.println("failed to initialise trillSensor");
    //Serial.print("Error code: ");
    //Serial.println(ret1);
    // pinMode(10, OUTPUT);
    //}
}


void loop() {

  {
  // Read 20 times per second
  delay(50);
  trillSensor.read();
int touchValue = trillSensor.touchLocation(0)/255;
int brightness = map(touchValue, 0, 255, 0, 255);
analogWrite(9, brightness);
  }

 { 
  //delay(50);
  //trillSensor.read();
//int touchValue2 = trillSensor.touchLocation(0)/255;
//int brightness2 = map(touchValue, 0, 255, 0, 255);
//analogWrite(10, brightness);
 }

  if(trillSensor.getNumTouches() > 0) {
    for(int i = 0; i < trillSensor.getNumTouches(); i++) {
        Serial.print(trillSensor.touchLocation(i));
        Serial.print(" ");
        Serial.print(trillSensor.touchSize(i));
        Serial.print(" ");
    }

    //if(trillSensor.getNumTouches() > 0) {
    //for(int i = 0; i < trillSensor.getNumTouches2(); i++) {
        //Serial.print(trillSensor.touchLocation2(i));
        //Serial.print(" ");
        //Serial.print(trillSensor.touchSize2(i));
        //Serial.print(" ");
    }
{
    Serial.println("");
    touchActive = true;
  }
  
// else if(touchActive) {
    // Print a single line when touch goes off
    Serial.println("0 0");
    touchActive = false;
  }

If you are using two different Trill sensors don't they have to have different I2C addresses?

From https://learn.bela.io/using-trill/trill-and-arduino/

"The second optional argument to setup() will define the address of the sensor. This is useful for cases in which you have changed the default address of a sensor via the solder bridge because you are using multiple sensors of the same type at once. If not provided, the default address for the specified device type will be used instead."

EDIT***

Never mind. I see that different types have different addresses. You need to declare two different instances of trill sensor. Something like this:

Trill trillSensor1;
Trill trillSensor2;

Wow it works!! Thank you so much!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.