Hi all, I’m back to doing imp development after about a year hiatus. I’ve never tried doing an i2c device before, but the docs page explained things pretty well. It seems like it should be pretty straightforward, but I can’t get anything working.
I’m using a CAP1188 breakout from Adafruit, and I’m pretty much trying to port some basic functionality from that library.
Here’s my imp code
`// Configure the Adafruit/CAP1188 Capacitive Touch Sensor
// Note: Imp I2C command values are strings with
// the \x escape character to indicate a hex value
const CAP1188_SENINPUTSTATUS = “\x03”;
const CAP1188_MTBLK = “\x2A”;
const CAP1188_LEDLINK = “\x72”;
const CAP1188_PRODID = “\xFD”;
const CAP1188_MANUID = “\xFE”;
const CAP1188_STANDBYCFG = “\x41”;
const CAP1188_REV = “\xFF”;
const CAP1188_MAIN = “\x00”;
const CAP1188_MAIN_INT = “\x01”;
const CAP1188_LEDPOL = “\x73”;
// Note: Imp I2C address values are integers
const CAP1188_I2CADDR = 0x29; // ADDR pin ground
function touched(i2c)
{
local word = i2c.read(i2c_addr, CAP1188_SENINPUTSTATUS, 1);
return word;
}
// PROGRAM START POINT
// Set up alias for i2c and set bus to 100kHz
i2c <- hardware.i2c12;
i2c.configure(CLOCK_SPEED_100_KHZ);
// Set sensor’s address by shifting 7-bit address 1 bit leftward as per imp I2C spec
i2c_addr <- CAP1188_I2CADDR << 1;
// Check the product ID as a test for I2C comms: this will return 0x50 if comms are working
local result = i2c.read(i2c_addr, CAP1188_PRODID, 1);
server.log("Product ID: "+ result[0]);
`
I don’t have it trying to do much right now, as I can’t get past even returning the product ID over i2c. This should be a pretty simple port from the adafruit library:
Serial.print("Product ID: 0x"); Serial.println(readRegister(CAP1188_PRODID), HEX);
I’ve tested the breakout board with an arduino, so I know it’s not a bad chip.
I’m seeing nothing at all in the device log. I’m scoping the SDA and SCL pins, and they’re both just remaining high, and I have no idea why. I set up the i2c on pins 1 and 2 just as in the example in the docs page, and I can’t see the clock or data pins doing anything. What am I doing wrong?
Thanks