Thanks, @Gordon.
I am getting a response from the following code using your code snippet.
I am just logging out the ouput of each MPR121 sensor pin as I run my finger over them.
Two observations: 1) the filteredData output seem to indicate which pins were touched as 2^pin. If pin 0 and pin 2 are touched, I get 2^0+2^2 = 5. I was expecting to get a value indicating the capacitance. 2) the baselineData output is 4 x the filteredData output, but not consistently.
// set up I2C
var i2c = new I2C();
i2c.setup({ scl : D28, sda: D29 });
// Setup pins and interface to MPR121
const sclPin = D28;
const sdaPin = D29;
const irqPin = D30; // 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(i2c, mprConnected , { address: 0x5A});
// define function for interrupt (fires on touch AND release)
function readValues() {
for(let i=0; i<12;i++)
console.log(mpr.filteredData(i) + ", " + mpr.baselineData(i));
}
mpr.readWord = function(reg) {
this.write(reg);
var data = this.read(2);
return (data[1] << 8) || data[0];
};
mpr.readByte = function(reg) {
this.write(reg);
return this.read(1)[0];
};
mpr.filteredData = function(pin) {
if (pin<0 || pin>=12) throw new Error("Invalid pin");
return this.readWord(0x04 + pin*2);
};
mpr.baselineData = function(pin) {
if (pin<0 || pin>=12) throw new Error("Invalid pin");
return this.readByte(0x1E + pin)<<2;
};
setInterval(function(){
readValues();
console.log(" " +"\n");
}, 5000);
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.
Thanks, @Gordon.
I am getting a response from the following code using your code snippet.
I am just logging out the ouput of each MPR121 sensor pin as I run my finger over them.
Two observations: 1) the filteredData output seem to indicate which pins were touched as 2^pin. If pin 0 and pin 2 are touched, I get 2^0+2^2 = 5. I was expecting to get a value indicating the capacitance. 2) the baselineData output is 4 x the filteredData output, but not consistently.
2 Attachments