letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.28k stars 2.22k forks source link

MPR121 Plugin - various sensitivities #2608

Closed gitgrube closed 5 years ago

gitgrube commented 5 years ago

Hello! When I use the MPR121 module on the Arduino (with MPR121test from the sample folder), with a custom library with higher sensitivity (to capture something through plastic), everything works as desired. However, once I run the whole thing on the ESP with the same library then a touch can no longer be detected. Unless I touch the electrode directly. Is there a certain difference between the example sketch and the plugin? Unfortunately, I can't get any further with my knowledge at this point.

TD-er commented 5 years ago

Can you give direct links to whatever sketch you tried?

gitgrube commented 5 years ago

example sketch: sketch

Adapted values of the library (Adafruit_MPR121.cpp) (as described here: adafruit forum (fourth answer on the second page)

-before: writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current -> after: writeRegister(MPR121_CONFIG1, 0x3F); -before: writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period -> after: writeRegister(MPR121_CONFIG2, 0x3A);

Domosapiens commented 5 years ago

@gitgrube

Unless I touch the electrode directly.

Arduino ..... 5V ESP8266 .....3.3V Could that make the sensitivity difference?

gitgrube commented 5 years ago

@Domosapiens Arduino ..... 5V ESP8266 .....3.3V Could that make the sensitivity difference?

Since the MPR121 chip works with 3.3V, this should not be the reason. Nevertheless I operated the breakout board with 5V as well as with 3.3V from the Arduino, each with the same result.

By the way: I use this module: MPR121 Breakout

mneuron commented 5 years ago

@gitgrube I use the MPR121 module with touch sensors behind a PLA frame. The adafruit sketch you mention reads the touch register in a very short loop. The MPR121_keypad-plugin 'only' ten times a second. I also noticed this in my project. In Adafruit_MPR121.cpp I had to change a lot of settings but after this a very light touch of the plastic is enough. If you change the ECR-register settings (see datasheet) to configure electrodes 0-1/0-3/0-11 for proximity detection AND lower the setThreshold(4,1); settings the MPR121_keypad plugin will detect proximity. Ideally these settings would be configurable within the plugin/webpage but there are way too much settings.

setThresholds(8, 1);  // most important !!!!
  // Section A - Controls filtering when data is > baseline.
  writeRegister(MPR121_MHDR, 0x01);
  writeRegister(MPR121_NHDR, 0x01);
  writeRegister(MPR121_NCLR, 0x00);
  writeRegister(MPR121_FDLR, 0x00);
// Section B - Controls filtering when data is < baseline.
  writeRegister(MPR121_MHDF, 0x01);
  writeRegister(MPR121_NHDF, 0x01);
  writeRegister(MPR121_NCLF, 0x00);
  writeRegister(MPR121_FDLF, 0x00);

  //writeRegister(MPR121_NHDT, 0x00);
  //writeRegister(MPR121_NCLT, 0x00);
  //writeRegister(MPR121_FDLT, 0x00);
// Set proximity sensing defaults
writeRegister(MHDPROXR, 0xFF);
writeRegister(NHDPROXR, 0xFF);
writeRegister(NCLPROXR, 0x00);
writeRegister(FDLPROXR, 0x00);
writeRegister(MHDPROXF, 0x01);
writeRegister(NHDPROXF, 0x01);
writeRegister(NCLPROXF, 0xFF);
writeRegister(FDLPROXF, 0xFF);
writeRegister(NHDPROXT, 0x00);
writeRegister(NCLPROXT, 0x00);
writeRegister(FDLPROXT, 0x00);

writeRegister(MPR121_CONFIG1, 0x10); // was 0x5C : default, 16uA charge current
//  writeRegister(MPR121_CONFIG2, 0x20); 
writeRegister(MPR121_CONFIG2, 0x24); //  was 0x5D:  0.5uS encoding, 1ms period
//  writeRegister(MPR121_AUTOCONFIG0, 0x8F);

//  writeRegister(MPR121_UPLIMIT, 150);
//  writeRegister(MPR121_TARGETLIMIT, 100); // should be ~400 (100 shifted)
//  writeRegister(MPR121_LOWLIMIT, 50);
  // enable all electrodes
  writeRegister(MPR121_ECR, 0xBC);  // was 0x8
gitgrube commented 5 years ago

I guess yesterday wasn't my day. I was using the finished Flash program all the time without realizing that it was already using finished builds. So the adapted library has no effect. Now I have compiled a firmware with the new library and see there, everything works as desired. So: Sorry for the confusion!

TD-er commented 5 years ago

@gitgrube Is there anything we should do to improve the plugin? (Maybe you can make a PR for this?)