Pure coincidence but I was working with an MRP121 keyboard on an Espruino MDBT42Q using the interrupt method. The interrupt is actually active low and hence needs a falling edge detection on the setwatch() function. Also the direct connection of the interrupt to an Espruino pin needs the internal pullup resistor enabling. Here is a working snipet to see the approach.
// Setup pins and interface to MPR121
const sclPin = D15;
const sdaPin = D14;
const irqPin = D16; // interrupt from MRP121
I2C1.setup({scl:sclPin,sda:sdaPin});
// IRQ is Active Low, open Drain (ref datasheet) - make use of internal pullup
pinMode(irqPin,'input_pullup');
// connect to MRP121 via Espruino MRP121 library
function mprConnected() {console.log ("MPR121 Connected");}
var mpr = require("MPR121").connect(I2C1, mprConnected , { address: 0x5B});
// define function for interrupt (fires on touch AND release)
function touchedIRQ() {
//console.log ("debug - interrupt received");
var keys = mpr.touched();
if (keys != 0) {console.log("Touched: " + keys);}
}
// watch the irqPin and fire the interrupt function on capacitance change
// IRQ is active low, so trigger the interrupt on a 'falling edge'
if (setWatch(touchedIRQ,irqPin,{repeat:true, edge: 'falling'}) === 1) {
console.log( "MPR Interrupt Enabled" );
}
else {console.log ("error - set watch on interrput pin NOT enabled"); }
Also Note the MPR121 keyboard im using does not have pullup resistors for the I2C: SCL and SDA, so I have added a 4.7 K resistor on my prototype board between each of: sclPin and 3.3v and sdaPin and 3.3v , I believe some MRP121 breakout boards already have these.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Pure coincidence but I was working with an MRP121 keyboard on an Espruino MDBT42Q using the interrupt method. The interrupt is actually active low and hence needs a falling edge detection on the setwatch() function. Also the direct connection of the interrupt to an Espruino pin needs the internal pullup resistor enabling. Here is a working snipet to see the approach.
Also Note the MPR121 keyboard im using does not have pullup resistors for the I2C: SCL and SDA, so I have added a 4.7 K resistor on my prototype board between each of: sclPin and 3.3v and sdaPin and 3.3v , I believe some MRP121 breakout boards already have these.
1 Attachment