Trill Visual Raw
This example visualises the reading from a Trill Craft sensor and it is largely the same as the general-settings example.
The Trill sensor is scanned on an auxiliary task running in parallel to the audio thread.
Once the project is running click the GUI button to see the reading on each channel. From this GUI you can also adjust the setting of the Craft sensor to best suit your needs.
There are two important sensor settings that you may want to adjust when working with the Trill Craft: the threshold
and the prescaler
.
The threshold
setting is simply the threshold above which to read and is for ignoring any noise that might be present in the lowest regions of the sensor reading. This only applies to DIFF
mode and is a float between 0.0 and 1.0. Typically values would stay below 0.1.
The prescaler
setting equates to the sensitivity of the sensor. Technically, this value is a divider for the clock on the cypress chip and so it decides how long the chip charges the connected material for before taking a reading. There are 8 different settings for the prescaler.
The rule of thumb when adjusting these values is:
- A higher value prescaler (i.e. longer charging time as it is a divider of the clock) is better for more resistive materials and larger conductive objects connected.
- A lower value prescaler is better for proximity sensing.
When connecting different materials to Trill Craft we recommend experimenting with the settings using this example. This example allows you to experiment with different settings from within the GUI which you can then hard code in your project once you're happy with the behaviour of the sensors.
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
#include <libraries/Pipe/Pipe.h>
unsigned int gTaskSleepTime = 12000;
float gTimePeriod = 0.015;
int bitResolution = 12;
int gButtonValue = 0;
typedef enum {
kPrescaler,
kBaseline,
kNoiseThreshold,
kNumBits,
kMode,
} ids_t;
ids_t id;
float value;
};
#include <tuple>
std::vector<std::pair<std::wstring, ids_t>> gKeys =
{
{L"prescaler", kPrescaler},
{L"baseline", kBaseline},
{L"noiseThreshold", kNoiseThreshold},
{L"numBits", kNumBits},
{L"mode", kMode},
};
bool guiCallback(JSONObject& json, void*)
{
for(auto& k : gKeys)
{
if(json.find(k.first) != json.end() && json[k.first]->IsNumber())
{
command.value = json[k.first]->AsNumber();
}
}
return false;
}
void loop(void*)
{
int numBits;
int speed = 0;
{
while(1 == gPipe.
readRt(command))
{
float value = command.
value;
switch(command.id)
{
case kPrescaler:
printf("setting prescaler to %.0f\n", value);
break;
case kBaseline:
printf("reset baseline\n");
break;
case kNoiseThreshold:
printf("setting noiseThreshold to %f\n", value);
break;
case kNumBits:
numBits = value;
printf("setting number of bits to %d\n", numBits);
break;
case kMode:
printf("setting mode to %.0f\n", value);
break;
}
}
usleep(50000);
}
}
{
fprintf(stderr, "Unable to initialise Trill Craft\n");
return false;
}
gPipe.
setup(
"guiToLoop");
return true;
}
{
static unsigned int count = 0;
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
{
count = 0;
}
count++;
}
}
{
}