Trill Craft: Spikes in raw data using a Raspberry Pi

My code is basically this:

#define VERBOSE


int main(int argc, char** argv)
{
  
    // Button (GPIO)
    if (gpioInitialise() < 0) {
        return 1;
    }
    gpioSetMode(GPIO_START_BUTTON, PI_INPUT);
    gpioSetPullUpDown(GPIO_START_BUTTON, PI_PUD_UP);

    gpioSetMode(GPIO_TRILL_RESET, PI_OUTPUT);
    gpioWrite(GPIO_TRILL_RESET, 1);
    usleep(1000);
    gpioWrite(GPIO_TRILL_RESET, 0);
    // Wait until Trill has finished booting
    usleep(600000);

    // Trill
    trill_Init(trillSensorTop,    0x30, 4); // is not applied. why??
    trill_Init(trillSensorBottom, 0x36, 3);
    trill_Init(trillSensorBase,   0x33, 3);


    while(!gShouldStop) 
    {
        trillSensorTop.readI2C();
        trillSensorBottom.readI2C();
        trillSensorBase.readI2C();
        
    }
    return 0;
}




int trill_Init(Trill& touchSensor, uint8_t address = 0x33, uint8_t prescaler = 3)
{
    std::string deviceName;
    int i2cBus = 1;
    Trill::Device device = Trill::CRAFT;
    Trill::Mode mode = Trill::RAW;
    unsigned int speed = 3;
    // unsigned int prescaler = 3;
    float threshold = 0.0;

    printf("Opening device %s on bus %d ", Trill::getNameFromDevice(device).c_str(), i2cBus);
    if(255 != address)
        printf("at address: %#4x(%d)", address, address);
    printf("\n");

    if(touchSensor.setup(i2cBus, device, address))
    {
        fprintf(stderr, "Error while initialising device\n");
        return 1;
    }


    if(touchSensor.setMode(mode) == 0) {
        #ifdef VERBOSE
        printf("Operation mode set to RAW.\n");
        #endif
    } else {
        fprintf(stderr, "Communication error\n");
        return 1;
    }

    if(touchSensor.setScanSettings(speed) == 0) {
        #ifdef VERBOSE
        printf("Scan speed set to %d.\n", speed);
        #endif
    } else {
        fprintf(stderr, "Communication error\n");
        return 1;
    }
    usleep(10000);
    if(touchSensor.setPrescaler(prescaler) == 0) {
        #ifdef VERBOSE
        printf("Prescaler set to %d.\n", prescaler);
        #endif
    } else {
        fprintf(stderr, "Communication error\n");
        return 1;
    }
    usleep(10000);
    if(touchSensor.setNoiseThreshold(threshold) == 0) {
        #ifdef VERBOSE
        printf("Threshold set to %d.\n", threshold);
        #endif
    } else {
        fprintf(stderr, "Communication error\n");
        return 1;
    }

    usleep(10000);
    if(touchSensor.updateBaseline() != 0) {
        fprintf(stderr, "Communication error\n");
        return 1;
    }

    #ifdef VERBOSE
    usleep(10000);
    touchSensor.printDetails();
    #endif

    return 0;
}

Read more here: Source link