Created
November 29, 2018 18:10
-
-
Save dtex/b0e22a8058ec95b24ea82d5fd875ed7a to your computer and use it in GitHub Desktop.
Teting the MPR121. It's not reading from the correct register.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const five = require("johnny-five"); | |
const board = new five.Board(); | |
const REGISTER = require("./node_modules/johnny-five/lib/definitions/mpr121.js"); | |
const Fn = require("./node_modules/johnny-five/lib/fn.js"); | |
const scale = Fn.scale; | |
const toFixed = Fn.toFixed; | |
board.on("ready", function() { | |
const address = 0x5a; | |
this.on("string", string => { | |
console.log(string); | |
}) | |
const getRawValues = () => { | |
this.io.i2cRead(address, 0x04, 0x1c, function(bytes) { | |
let result = []; | |
for (let i = 0; i < 12; i++) { | |
result.push(five.Fn.uint16(bytes[i*2+1], bytes[i*2])); | |
} | |
console.log(result); | |
}); | |
}; | |
const init = () => { | |
this.io.i2cConfig({ address: address }); | |
this.io.i2cWrite(address, REGISTER.MPR121_SOFTRESET, 0x63); | |
this.io.i2cWrite(address, REGISTER.MHD_RISING, 0x01); | |
this.io.i2cWrite(address, REGISTER.NHD_AMOUNT_RISING, 0x01); | |
this.io.i2cWrite(address, REGISTER.NCL_RISING, 0x00); | |
this.io.i2cWrite(address, REGISTER.FDL_RISING, 0x00); | |
this.io.i2cWrite(address, REGISTER.MHD_FALLING, 0x01); | |
this.io.i2cWrite(address, REGISTER.NHD_AMOUNT_FALLING, 0x01); | |
this.io.i2cWrite(address, REGISTER.NCL_FALLING, 0xFF); | |
this.io.i2cWrite(address, REGISTER.FDL_FALLING, 0x02); | |
for (var i = 0; i < 12; i++) { | |
this.io.i2cWrite( | |
address, | |
REGISTER.ELE0_TOUCH_THRESHOLD + (i << 1), | |
scale(toFixed(1 - 0.95, 3), 0, 1, 0, 255) | |
); | |
this.io.i2cWrite( | |
address, | |
REGISTER.ELE0_RELEASE_THRESHOLD + (i << 1), | |
scale(toFixed(1 - 0.975, 3), 0, 1, 0, 255) | |
); | |
} | |
this.io.i2cWrite(address, REGISTER.FILTER_CONFIG, 0x13); | |
this.io.i2cWrite(address, REGISTER.AFE_CONFIGURATION, 0x80); | |
this.io.i2cWrite(address, REGISTER.AUTO_CONFIG_CONTROL_0, 0x8F); | |
this.io.i2cWrite(address, REGISTER.AUTO_CONFIG_USL, 0xE4); | |
this.io.i2cWrite(address, REGISTER.AUTO_CONFIG_LSL, 0x94); | |
this.io.i2cWrite(address, REGISTER.AUTO_CONFIG_TARGET_LEVEL, 0xCD); | |
this.io.i2cWrite(address, REGISTER.ELECTRODE_CONFIG, 0xCC); | |
} | |
init(); | |
getRawValues(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment