mpr121_int

MPR121 Capacitive Touch Sensor (I2C). Tested with: https://www.adafruit.com/product/1982 The touch output is the 0/1 status of the touch plates (bits 0..11) Note: This object requires a single instance of the factory/gpio/i2c/config object. This allows multiple mpr121 devices (each with a unique i2c address) to work concurrently. Tested with I2C1, SCL=PB8, SDA=PB9 (these are the config defaults)
Author: Jason Harris
License: BSD
Github: deadsy/mpr121/mpr121_int.axo

Inlets

None

Outlets

int32 touch

Attributes

combo adr

Declaration
// Register values are tuned for electrode geometry.
// Here are some reasonable defaults, but you may need
// to tune these values for your specific application.
// See: https://www.nxp.com/docs/en/data-sheet/MPR121.pdf

const struct mpr121_cfg config[34] = {
    {MPR121_TOUCH_THRESHOLD(0), 6},
    {MPR121_TOUCH_THRESHOLD(1), 6},
    {MPR121_TOUCH_THRESHOLD(2), 6},
    {MPR121_TOUCH_THRESHOLD(3), 6},
    {MPR121_TOUCH_THRESHOLD(4), 6},
    {MPR121_TOUCH_THRESHOLD(5), 6},
    {MPR121_TOUCH_THRESHOLD(6), 6},
    {MPR121_TOUCH_THRESHOLD(7), 6},
    {MPR121_TOUCH_THRESHOLD(8), 6},
    {MPR121_TOUCH_THRESHOLD(9), 6},
    {MPR121_TOUCH_THRESHOLD(10), 6},
    {MPR121_TOUCH_THRESHOLD(11), 6},

    {MPR121_RELEASE_THRESHOLD(0), 12},
    {MPR121_RELEASE_THRESHOLD(1), 12},
    {MPR121_RELEASE_THRESHOLD(2), 12},
    {MPR121_RELEASE_THRESHOLD(3), 12},
    {MPR121_RELEASE_THRESHOLD(4), 12},
    {MPR121_RELEASE_THRESHOLD(5), 12},
    {MPR121_RELEASE_THRESHOLD(6), 12},
    {MPR121_RELEASE_THRESHOLD(7), 12},
    {MPR121_RELEASE_THRESHOLD(8), 12},
    {MPR121_RELEASE_THRESHOLD(9), 12},
    {MPR121_RELEASE_THRESHOLD(10), 12},
    {MPR121_RELEASE_THRESHOLD(11), 12},

    {MPR121_MHD_RISING, 0x01},
    {MPR121_NHD_RISING, 0x01},
    {MPR121_NCL_RISING, 0x0E},
    {MPR121_MHD_FALLING, 0x01},
    {MPR121_NHD_FALLING, 0x05},
    {MPR121_NCL_FALLING, 0x01},
    {MPR121_CDC_CONFIG, 0x10}, // default, 16uA charge current
    {MPR121_CDT_CONFIG, 0x20}, // 0.5uS encoding, 1ms period
    {MPR121_ELECTRODE_CONFIG,
     0x8F},   // start with first 5 bits of baseline tracking
    {0xff, 0} // end-of-list
};

struct mpr121_state state;
Init
mpr121_init(&state, &config[0], attr_adr);
Control Rate
mpr121_krate_int(&state, &outlet_touch);
Dispose
mpr121_dispose(&state);

Privacy

© 2024 Zrna Research