letscontrolit / ESPEasy

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

P062_MPR121_KeyPad sensitivity setting #3309

Closed smotek closed 3 years ago

smotek commented 4 years ago

Requirement to add the ability to set the sensitivity of the touchpads. The MPR121 chip enables this setting. See Adafruit Library.

Add the ability to set a master touch. If the main touch is set, touching it will deactivate the others. Multiple touch treatment.

Thank you

tonhuisman commented 4 years ago

As you seem to know what you are talking about, can you create a pull request yourself, containing the changes? Instructions when using PlatformIO (suggested dev environment): https://espeasy.readthedocs.io/en/latest/Participate/PlatformIO.html Instructions when using Arduino IDE: https://espeasy.readthedocs.io/en/latest/Participate/ArduinoIDE.html

smotek commented 4 years ago

Unfortunately, I do not have such abilities.

I was just looking to see if the chip allowed it. I found various tips in the forums.

However, I am not able to make an adjustment.

tonhuisman commented 4 years ago

I've constructed 2 sensitivity settings, is this what you have in mind?

MPR_121_Sensitivity2

NB: The defaults come directly from the Adafruit_MPR161 source. NB2: Value 0 is seen as invalid, so the defaults are then applied. NB3: As I don't own this touchpad I'm unable to actually test it...

TD-er commented 4 years ago

Maybe it is also nice to show the current, max and minimal seen values (in logs or on the config page) For example the ADC plugin does show the "current" value at load time of the page, which is a great help for the calibration.

smotek commented 4 years ago

I can test. But I would need a .bin Question, does the library allow you to make settings for individual touches or just for all?

Proposal TD-er is good, It will help with calibration.

tonhuisman commented 4 years ago

Maybe it is also nice to show the current, max and minimal seen values

Well, the library does not supply those values, AFAICS, so I wouldn't know what to report there... The log already shows the key or scancode at Info log-level, so, setting a value, pressing submit, and touching a button would give an expected feedback when touched soft/hard enough?

I haven't investigated the possible readable values from the controller (and something like that isn't implemented yet in the library), would that be feasible for a 'phase 2' development effort?

Question, does the library allow you to make settings for individual touches or just for all?

Currently it's applying this to all touch buttons at once (library default feature). Are you implying you would want to set a different sensitivity per button?, as that would take some more time to code (the settings will have to be stored differently).

TD-er commented 4 years ago

Well if it needs an overhaul of the library, then it is indeed a completely different feature request. Let's not try to do it all at once :)

smotek commented 4 years ago

Somewhere I read that they used reading readings for calibration, but probably a different library.

For now, just set the sensitivity for testing. Calibration is performed experimentally.

The question about the possibility of setting a different sensitivity for the touch, is that if one area is large and the other small, then I expect that another sensitivity will be needed. For example, one area 2x2cm and 6pcs 1x1cm.

TD-er commented 4 years ago

For capacitive touch there are several parameters that may affect the read values.

And I'm probably missing some.

tonhuisman commented 4 years ago

I'll keep the common setting, but add 12 settings for each separate touch-area, ignored when the values are 0.

Reading the actual touch values and keep previous values I'll skip for now.

tonhuisman commented 4 years ago

I haven't investigated the possible readable values from the controller (and something like that isn't implemented yet in the library),

After reading up on the datasheet of the mpr121, I now recognize the filteredData(uint8_t t) function as the way to get the touch 'value', so that means it shouldn't be that difficult to add this data to the data structure and UI. It does involve small modifications to the library, but that's already required for enabling the setting of the tresholds for each separate touch object.

tonhuisman commented 4 years ago

@smotek what version of ESPEasy are you using? (filename of the .bin file please, that has the most interesting info)

smotek commented 4 years ago

@tonhuisman currently ESP_Easy_mega_20200929_test_beta_ESP8266_4M1M

smotek commented 3 years ago

Today I created touchpads and the result is for default values:

tonhuisman commented 3 years ago

I'm nearly done with my adjustments, including the calibration data, but I'll need a few more hours for testing. I'll make a PR tomorrow night (CET), if all goes according to plan.

smotek commented 3 years ago

Thank you for the info.

tonhuisman commented 3 years ago

I made a PR with the changes, but I don't have the stuff needed to make a complete build zipfile. I am able to provide a single .bin if you want that (assume the same config you mentioned earlier), but I'd have to make some arrangements for that.

smotek commented 3 years ago

It is enough if in .bin it will be with ESPeasy with plugin 062 for testing. I use a Wemos D1 board.

tonhuisman commented 3 years ago

I've made a single build for ESP8266 like you mentioned above, and put it in a zip file:

ESP_Easy_mega_20201014_test_beta_ESP8266_4M1M-PR#3316.zip

Please let me know if this runs as expected, as, without the hardware connected and the plugin enabled, it constantly reboots my ESP8266 (and hangs the ESP32 I tested on).

smotek commented 3 years ago

Test 1 flood settings 12/6 result: 2x touch and restart log: 265466: ScanCode=0x1 265466: P062 touch current: 371 min: 371 max: 371 265479: EVENT: mpr#SC=1.00 265566: ScanCode=0x0 265603: EVENT: mpr#SC=0.00 267366: ScanCode=0x1 267366: P062 touch current: 371 min: 371 max: 371 267402: EVENT: mpr#SC=1.00 267566: ScanCode=0x0 267602: EVENT: mpr#SC=0.00

Test2: Change setting image

Touches react the same way. The log always has the same value.

Test3: Set for all 150/100 then 250/200 the sensitivity did not change.

It always prints the same value in the log. P062 touch current: 371 min: 371 max: 371 With a small big touch. Sometimes it restarts even when the HW is connected. I can't identify when he'll come. It's not regular.

smotek commented 3 years ago

I came after it restarts. When touching the surface 12. It always happens.

It is interesting that if I make a touch on area 1, the values ​​will be displayed at area 2.

When HW is not connected, it will not start ESP.

tonhuisman commented 3 years ago

When HW is not connected, it will not start ESP.

Would it start with the original build with no hardware connected? If so then I must have broken something...

smotek commented 3 years ago

It is interesting both versions behave the same

  1. I disconnect the HW, it also does not start.
  2. if HW is connected but 3.3V disconnected, it starts
  3. if I enter device enable false then it will start.

It is enough for the module to be connected GND, SCL, SDA and ESP start.

TD-er commented 3 years ago

Well, SDA and SCL are pulled up to 3v3, so most of the time they will be high. Maybe the module does have enough internal capacitance to keep running as long as the I2C lines are low.

smotek commented 3 years ago

It is possible that it can respond to ESPeasy when it is powered via pollup. If I disconnect the HW while working. ESPeasy restarts in about 10 seconds, starts and sets Device enabled to false. You can then connect to ESPeasy via the web.

TD-er commented 3 years ago

If the task is disabled after reboot, then ESPEasy already crashed at least 10 times. After 10 incomplete reboots, it starts disabling tasks until it can complete a boot.

tonhuisman commented 3 years ago

if I make a touch on area 1, the values ​​will be displayed at area 2.

I fixed that, classic off-by-1 mistake. Also added the touchobject nr to the log message.

smotek commented 3 years ago

@tonhuisman Didn't you make a new version?

tonhuisman commented 3 years ago

I've been milling on that source a bit, and fixed another issue related to the calibration log, plus the fact that the previous commit was a bit cramped in time, so I didn't get to posting a test-build. This is an updated build, same config as before: ESP_Easy_mega_20201020_test_beta_ESP8266_4M1M-PR#3316.zip

smotek commented 3 years ago

@tonhuisman I tested the new version. Displays calibration values. Even on the right lines. I don't understand their range when there is 343. I have set a default of 12/6, the chip measures e.g. 110 and evaluates it as a touch. Changing the suction values does not change the sensitivity. I will try to do the connection with arduino and test how it works there.

tonhuisman commented 3 years ago

I tested the new version.

Thank you.

Displays calibration values. Even on the right lines.

Great

I don't understand their range when there is 343. I have set a default of 12/6, the chip measures e.g. 110 and evaluates it as a touch.

All I'm doing here is set the treshold from the configured values, and present the data that is available from the driver, I don't know how interpret it, nor can I validate the correctness of any data, as I don't have the hardware available for testing, sorry.

Changing the suction values does not change the sensitivity. I will try to do the connection with arduino and test how it works there.

I'd be interested in your findings there.