ry this:
#include <Trill.h>
Trill trillSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
int ret = trillSensor.setup(Trill::TRILL_FLEX);
if(ret != 0) {
Serial.println("failed to initialise trillSensor");
Serial.print("Error code: ");
Serial.println(ret);
}
Serial.println("Inited");
delay(100);
trillSensor.setMode(Trill::RAW);
delay(100);
// when the slider is connected we increase the
// prescaler to deal with the increased baseline
// capacitance it brings
trillSensor.setPrescaler(3);
delay(100);
trillSensor.setNoiseThreshold(200);
delay(100);
trillSensor.setScanSettings(0, 16);
delay(100);
// after any prescaler change, it's always good to update
// the baseline, too.
trillSensor.updateBaseline();
}
void loop() {
// put your main code here, to run repeatedly:
delay(100);
trillSensor.requestRawData();
while(trillSensor.rawDataAvailable() > 0) {
unsigned int data = trillSensor.rawDataRead();
if(data < 10000)
Serial.print(0);
if(data < 1000)
Serial.print(0);
if(data < 100)
Serial.print(0);
if(data < 10)
Serial.print(0);
Serial.print(data);
Serial.print(" ");
}
Serial.println("");
}
Note the increased delay() times with respect to the usual 10ms: when increasing the bit depth the scan times also become longer ( see the table here https://learn.bela.io/using-trill/settings-and-sensitivity/#scan-settings ) and the delay interval between commands must allow for at least one scan to happen between successive commands. setScanSettings sets scan speed and bit depth. At 16 bits, Ultra fast (= 0) speed, that's 2800 µs (2.8 ms) per pad, or 30 * 2.8ms = 84 ms in total, so a sleep time of 100ms should be safe. If moving to "slow" (= 3) speed, that's 22000us (22ms) per pad, or 30 * 22 ms = 660ms int total, so the sleep time should go to about 700 ms.
When you see everything working as it should , you can switch to Trill::DIFF in setMode() to get differential readings.