[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 

Using touch pad sensors RSS feed
Forum Index » tcMenu Arduinio library
Author Message
chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
Hi, everyone.

In my project, I have touch sensors instead of mechanical switches to control tcMenu. I have used the ESP32 built in touch sensors. There are five: UP; DOWN; LEFT; RIGHT and OK (ENTER)
I've developed a PoC wich receive in a FreeRTOS task an int representing in every bit if a key has been pressed. This is the receiving task:
void receiveKeys (void *unused) {
    uint32_t keysStatus = 0;
    while(1)
    {
        if(xQueueReceive(qh, &keysStatus, 10)) {
            log_v("rx keys: %x", keysStatus);
            mustUpdate = true;
            vTaskDelay(125 / portTICK_PERIOD_MS);
            touch_pad_clear_status();              
            touch_pad_intr_enable();
            }
    }


I have two questions:
1. Can I adapt these touch sensors in tcMenu? Could anyone recommend me something to read in order to be able to write the code?
2. Can I use FreeRTOS at the same time that tcMenu, or tcMenu uses some kind of RTOS jet?

Thanks.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
It would most certainly be quite easy to integrate, I would imagine there would be many ways to do it, but the easiest may be to make a simple IoAbstraction implementation around the touch sensors.

If you did this you would then not need an RTOS task, instead you'd just pass your new IoAbstraction to switches instead of the regular one. If you did this you'd get all the debouncing and everything else for free. However, you could just service the keyboard yourself and just tell tcMenu when changes occur, again with the caveat that this must happen on the right thread, see the execute example below for that. All the methods to move around menu items are on menuMgr: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/

An IoAbstraction is a simple interface that exposes methods similar to the Arduino pin functions. So you would need to implement the setup of each numbered sensor and the acquisition of data, you could skip anything to do with writing.

For example a starting point to look at would be: https://github.com/davetcc/IoAbstraction/blob/master/src/DfRobotInputAbstraction.h

The base class BasicIoAbstraction is implemented in https://github.com/davetcc/IoAbstraction/blob/master/src/BasicIoAbstraction.h

On the subject of RTOS, yes you can use RTOS and taskmanager / tcMenu at the same time, yes with a few limitations. You can create as many threads as you like, you can schedule work to be done from those tasks by using any task manager scheduling function. You can raise any events against task manager either from an interrupt or another thread. However, and this applies generally to all multithreaded software, you need to be very careful about object state. Currently, menu items are not thread-safe, you should only interact with them from taskManager.

However, if you have another thread, and you wanted to update a menu item you either create an event, or do something like

void runningOnAnotherThread() {
   taskManager.execute(someTaskToExecuteOnTaskManagerThread);
}


Think of tcMenu like you would a desktop UI, it has a compositing thread, and you should honour that when working with menu items. I recommend you read the task manager documentation thoroughly around creating events and muli-threading before proceeding.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
If you can give me a sample program that deals with the touch sensors, I'll turn it into an IoAbstraction so you can use it with tcMenu. I have an ESP32 board as one of my main development boards, so testing should be easy.

What I'd need to avoid needing to read the docs:

* How to set up a pin as a touch sensor and prepare it for use.
* How to read the current value of a touch sensor.
* Anything else specific to the touch sensor support.
* Any circuit that I'd need to build in order to test at least one pin.
chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
It would be very helpful. Thanks a lot Dave.

Attached is a PlatformIO project that was working. It reads values form a temperature sensor and displays in an SSD1306. Also prints in the serial port the keys detected by the touch sensors. If the key is "GPIO13-Touch4" the display is cleared (mustErase = true smilie

Also I attach the hardware schematics. There you can see the pis of the touch sensors (cuadrant D1)

* How to set up a pin as a touch sensor and prepare it for use.

In the source code is all detailed. This is based on an example from Espressif (https://github.com/espressif/esp-idf/blob/master/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c). I added the queue (maybe is a bad idea). It send the value detected by the interrpt routine (touchpad.c - tp_rtc_intr) to a receiving task (main.cpp - receiveKeys)
* How to read the current value of a touch sensor.

It is interrpt-driven, so you don't need to read. Only set a threshold which is set to 2/3 of the initial value (nobody has to touch any sensor at boot time).
* Anything else specific to the touch sensor support.

Additional info in https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/touch_pad.html#touch-triggered-interrupts
* Any circuit that I'd need to build in order to test at least one pin.

You can solder a small coin or similar to cables connecting the touch sensor pins, this is the only hardware needed. This is an example https://hackaday.com/wp-content/uploads/2019/04/esp32clock_detail.jpg
 Filename thermostat_sch.pdf [Disk] Download
 Description Hardware
 Filesize 116 Kbytes
 Downloaded:  60807 time(s)

 Filename thermostat_v0.2.tar.bz2 [Disk] Download
 Description Source code for PlatformIO
 Filesize 12 Kbytes
 Downloaded:  50597 time(s)

davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
Thanks for the information, I'll try and get something done later today or tomorrow.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
Sorry, we've got really behind with stuff this past week.

I'll honestly try and do this in the next few days. It's near the top of my task list.
chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
Don't worry, I know you are doing your best.
I've tried to understand your code, but honestly objects are not my strong point.
Good weekend.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
Hi there, I finally think I have something that works. Was quite complex to understand to be honest.

It will be fully integrated into TcMenu V2.0 and the code generator will do this for you, however here are some simple steps to be able to use it right now (and hopefully give me some feedback on how it works for you).

Step 1. Copy the files from this directory into your project: https://github.com/davetcc/tcMenuXmlPlugins/tree/master/core-display/esp32Touch

Step 2. Add the new encoder in your sketch, where threshold is the point below which a button is considered pressed, the other parameters are straight from the ESP32 IDF guide on touch pad:

ESP32TouchKeysAbstraction* esp32Touch = new ESP32TouchKeysAbstraction(threshold, TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V);


Step3: Choose up/down button encoder from code generator as the input type, set the IoExpander reference to esp32Touch. Set the up/down/select buttons to the touch sensor number (not gpio). They are not pull up so ensure that is turned off, you can interrupt mode.

Step 4 (if you are using interrupts only)

After the setupMenu() call in your sketch do the following:

esp32Touch->ensureInterruptRegistered();


Also see this documentation, but it is very much in flight at the moment: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/touch-pad-sensor-plugin/
[Thumb - coin-touch-sensor.jpg]
 Filename coin-touch-sensor.jpg [Disk] Download
 Description No description given
 Filesize 36 Kbytes
 Downloaded:  52494 time(s)

chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
Thnaks a lot Dave.

I'm afraid I'm going to need some time. After trying to install the 2.0.0 version of the generator the app does not work any more (I mean 1.7.0)

Now I cannot generate the structure to test.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
I recommend that you completely remove the designer build and rebuild from the last 1.7 tag which was 1.7.0 : https://github.com/davetcc/tcMenu/tree/1.7.0

We'll be building our first linux image in the next week or so, we have a Linux VM with graphics.

For now:

git checkout 1.7.0
mvn clean install
then try and run it again.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
I have a package built now on my 64-bit ubuntu distro, for 2.0.0-SNAPSHOT, it works properly and all tests pass, it should be fully compatible with library version 1.7 too.

I'm trying to build a native package that can go in the store, but at the absolute minimum I'll put out an image for 64 bit Ubuntu later today.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
I have now prepared a ready-made build of tcmenu designer on Linux that should need no additional dependencies. It is based on the 2.0 beta, but it is compatible with the 1.7 plugins and library. I have tested it myself considerably on Windows, and now on Linux. Only the documentation links don't appear to work for some reason. It is packaged as a deb file.

See the linux section on https://www.thecoderscorner.com/products/apps/tcmenu-designer/

I'll announce this more widely, as it is probably good news for many.
chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
Dear Dave.

I have been a bit busy lately and couldn't test your solution.
Just to be sure... In the Rotary Encoder configuration I must write "esp32Touch" in the cell marked in the picture.

The code is as follow (modified after the code generation)

void setupMenu() {
    prepareBasicU8x8Config(gfxConfig);
    gfx.begin();
    renderer.setGraphicsDevice(&gfx, &gfxConfig);
    ESP32TouchKeysAbstraction* esp32Touch = \
        new ESP32TouchKeysAbstraction(TOUCH_threshold, TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V);
    switches.initialise(esp32Touch, false);
    menuMgr.initForEncoder(&renderer, &menuCalefaccion, 6, 8, 4);
}


The numbers 6, 8 and 4 in the last line are the touch sensors (not pins numbers)


Thanks for your support!!!
[Thumb - RotaryEncoderMenu2.jpg]
 Filename RotaryEncoderMenu2.jpg [Disk] Download
 Description No description given
 Filesize 78 Kbytes
 Downloaded:  49591 time(s)

chirrindulari


Joined: Jan 23, 2021
Messages: 22
Offline
I have understood that the correct election is the <<Control menu with UP/DOWN buttons>>. All is working as expected, I think.

The only problem I've found is that the up and down buttons seems to be interchanged. If I push UP, the little arrow in the menu goes DOWN.

Maybe another issue... In the desginer, when you select ESP WIFI as a remote capability, the limit of the listen port is 65355. I think it shuld be the maximum 16 bit value (65535, 2^16-1)

Thanks for your work.
davetcc


Joined: Jan 19, 2019
Messages: 628
Offline
In the desginer, when you select ESP WIFI as a remote capability, the limit of the listen port is 65355. I think it shuld be the maximum 16 bit value (65535, 2^16-1)


Thanks, that is a bug, I will fix that typo for the next version.

I have understood that the correct election is the <>. All is working as expected, I think.


So in your sketch you'd create the touch Io expander EG

ESP32TouchKeysAbstraction* esp32Touch = new ESP32TouchKeysAbstraction(TOUCH_threshold, TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V);


Then choose "Control menu with UP/DOWN buttons" and in the IoExpander provide 'esp32Touch', the buttons numbers are 0..9 for each touch-capable pin.

The only problem I've found is that the up and down buttons seems to be interchanged. If I push UP, the little arrow in the menu goes DOWN.


From Arduino / pio library manager Make sure you are on tcMenu 1.7.1 and the IoAbstraction 1.7.3 too, these have a fix for joystick navigation to make it more natural.
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.