- Wed Jan 04, 2017 11:13 pm
#192773
Hi,
I followed the example on https://www.youtube.com/watch?v=PJJmQwqGQDM where the mpr121 is used as a liquid level sensor. I soldered all 12 wires from the mpr121 to a copper tape. When i touch the copper plates, i see the correct values returned, however when i taped the copper plates to a plastic bottle and filled it with water, none of the sensor is activated.
Any help will be great.
Here is the config used fro the mpr121:
My Arduino code:
I followed the example on https://www.youtube.com/watch?v=PJJmQwqGQDM where the mpr121 is used as a liquid level sensor. I soldered all 12 wires from the mpr121 to a copper tape. When i touch the copper plates, i see the correct values returned, however when i taped the copper plates to a plastic bottle and filled it with water, none of the sensor is activated.
Any help will be great.
Here is the config used fro the mpr121:
Code: Select all
void MPR121::begin(void){
// STOP
mpwrite(ELE_CFG, 0x00);
mpwrite(RES_CF, 0X63);
delay(10);
// Section A
// This group controls filtering when data is > baseline.
mpwrite(MHD_R, 0x01);
mpwrite(NHD_R, 0x01);
mpwrite(NCL_R, 0x00);
mpwrite(FDL_R, 0x00);
// Section B
// This group controls filtering when data is < baseline.
mpwrite(MHD_F, 0x01);
mpwrite(NHD_F, 0x01);
mpwrite(NCL_F, 0xFF);
mpwrite(FDL_F, 0x02);
// Section C
// This group sets touch and release thresholds for each electrode
mpwrite(ELE0_T, TOU_THRESH);
mpwrite(ELE0_R, REL_THRESH);
mpwrite(ELE1_T, TOU_THRESH);
mpwrite(ELE1_R, REL_THRESH);
mpwrite(ELE2_T, TOU_THRESH);
mpwrite(ELE2_R, REL_THRESH);
mpwrite(ELE3_T, TOU_THRESH);
mpwrite(ELE3_R, REL_THRESH);
mpwrite(ELE4_T, TOU_THRESH);
mpwrite(ELE4_R, REL_THRESH);
mpwrite(ELE5_T, TOU_THRESH);
mpwrite(ELE5_R, REL_THRESH);
mpwrite(ELE6_T, TOU_THRESH);
mpwrite(ELE6_R, REL_THRESH);
mpwrite(ELE7_T, TOU_THRESH);
mpwrite(ELE7_R, REL_THRESH);
mpwrite(ELE8_T, TOU_THRESH);
mpwrite(ELE8_R, REL_THRESH);
mpwrite(ELE9_T, TOU_THRESH);
mpwrite(ELE9_R, REL_THRESH);
mpwrite(ELE10_T, TOU_THRESH);
mpwrite(ELE10_R, REL_THRESH);
mpwrite(ELE11_T, TOU_THRESH);
mpwrite(ELE11_R, REL_THRESH);
// Section D
// Set the Filter Configuration
// Set ESI2
mpwrite(AFE1_CFG, 0x10);
//AFE配置1 (默认=0x10)
// 一级采样FFI:00-6次
// 充放电电流CDC:100000 - 32uA
mpwrite(AFE2_CFG, 0x04);
//AFE配置2 (默认=0x24)
// 充电时间CDT:010 - 1us
// 二级采样SFI:00 - 4次
// 二级采样间隔ESI:100 - 16ms
// Section E
// Electrode Configuration
// Enable 6 Electrodes and set to run mode
// Set ELE_CFG to 0x00 to return to standby mode
mpwrite(ELE_CFG, 0x8C); // Enables all 12 Electrodes
//AFE配置1
// CL
// ELEPROX
// ELE:
// Section F
// Enable Auto Config and auto Reconfig
/*mpwrite(ATO_CFG0, 0x0B);
mpwrite(ATO_CFGU, 0xC9); // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V mpwrite(ATO_CFGL, 0x82); // LSL = 0.65*USL = 0x82 @3.3V
mpwrite(ATO_CFGT, 0xB5);*/ // Target = 0.9*USL = 0xB5 @3.3V
}
int MPR121::touch(void)
{
Wire.requestFrom((uint8_t)MPR121_ADDR,(uint8_t)2);
uint8_t a,b;
if(Wire.available()>=2) // slave may send less than requested
{
#if defined(ARDUINO) && ARDUINO >= 100
a = Wire.read(); // receive a byte as character
b = Wire.read();
#else
a = Wire.receive(); // receive a byte as character
b = Wire.receive();
#endif
return (a | (int)(b<<8));
}else
{
return 0;
}
}
My Arduino code:
Code: Select all
void loop()
{
int var = CapaTouch.touch(); // this calls the touch method() defined above
int num = GetSensorNumber(var);
if(num != -1 && num != prev)
{
Serial.print("Num: ");
Serial.println(num);
prev = num;
}
}
int GetSensorNumber(int var)
{
if ((var&0x0800) >0) return 12;
if ((var&0x0400) >0) return 11;
if ((var&0x0200) >0) return 10;
if ((var&0x0100) >0) return 9;
if ((var&0x0080) >0) return 8;
if ((var&0x0040) >0) return 7;
if ((var&0x0020) >0) return 6;
if ((var&0x0010) >0) return 5;
if ((var&0x0008) >0) return 4;
if ((var&0x0004) >0) return 3;
if ((var&0x0002) >0) return 2;
if ((var&0x0001) >0) return 1;
return -1;
}