[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 

MultiIo abstraction // TCMenu // Encoder setup RSS feed
Forum Index » IoAbstraction & TaskManagerIO
Author Message
FS


Joined: Mar 19, 2021
Messages: 6
Offline
Hello,
struggling since a while with following effect.

An encoder is connected to an 8574 Expander connected by I2C, the interrupt pin from the Expander is connected to Pin 2 from an ESP8266 board.

void setup() {
    setupMenu();
    Serial.begin(9600);
    Wire.begin();


          multiIoAddExpander ( multiIo, ioFrom8574(0x20, 2), 10);  //Expander pins

                ioDevicePinMode(multiIo, EXPANDER1+0, INPUT);  //P0 Pin 100 ( P0 auf 8574) Switch
                ioDevicePinMode(multiIo, EXPANDER1+1, INPUT_PULLUP);  //P1 Pin 101 Encoder Pin A
                ioDevicePinMode(multiIo, EXPANDER1+2, INPUT_PULLUP);  //P2 Pin 102 Encoder Pin B
                ioDevicePinMode(multiIo, EXPANDER1+3, INPUT);  //P3 Pin 103 ( P3 auf 8574) Clickwheel Encoder                

                ioDevicePinMode(multiIo, EXPANDER1+7, OUTPUT); //P7 Pin 107 Test mit LED

                
                switches.initialise(multiIo, true);
                switches.addSwitchListener(EXPANDER1 +0,  &keyListenerExpander);  
                switches.addSwitchListener(EXPANDER1 +3,  &keyListenerExpander);  


    
    //setupRotaryEncoderWithInterrupt(encoderAPin, encoderBPin, onEncoderChange, HWACCEL_REGULAR);


}


Additional is defined:
#define EXPANDER1 100
    MultiIoAbstractionRef multiIo = multiIoExpander(EXPANDER1);
    
  IoAbstractionRef multiIoENC = ioFrom8754(0x20, 2);  //2 for Interrupt Pin ESP8266


TcMenu i can only operate if i do not use setupRotaryEncoderWithInterrupt(encoderAPin, encoderBPin, onEncoderChange, HWACCEL_REGULAR);
Using that setup of the Encoder does have as consequence the Encoder does not react in TcMenu.
The click wheel button does react.
Strange: This effect has exception: Test Codes do run using setupRotaryEncoderWithInterrupt, others not - without a visible change comparing the codes.

IoAbstractionRef multiIoENC = ioFrom8754(0x20, 2); i need for TcMenu, without there's no reaction in the Menu, with it does run like a charm.
Being confused a bit as i cannot get an idea how the pins are defined then.

The other strange thing is:
I can leave TcMenu by takeOverDisplay, work with the encoder in a text based human interface i need to see numbers better ( Bigger smilie ) and to work with
hotkeys by click wheel click, doubleclick, tripleclick.
Encoder does work.
Giving back the display to TcMenu using giveBackDisplay has as effect that the encoder does not work in TcMenu anymore. I can see in the serial monitor that
the Encoder is in operation.


It looks the multiIoAbstraction i cannot define in TcMenu, therefore is use IoAbstractionRef.

How to setup the Encoder in an multiIoAbstraction for TcMenu and another Renderer as e.g. using an standard 1366 library ( E.g. Adafruit ) ?

If somebody has an idea what i am doing wrong pls. advice

Frank

davetcc


Joined: Jan 19, 2019
Messages: 350
Offline
I think I can see what's wrong, you are setting up the multiIO AFTER setupMenu(). However the switches and rotary encoder initialisation happens in setupMenu. Try moving it just after Wire.begin(). In fact for safety setupMenu should be after Wire.begin too.


TcMenu i can only operate if i do not use setupRotaryEncoderWithInterrupt(encoderAPin, encoderBPin, onEncoderChange, HWACCEL_REGULAR);
Using that setup of the Encoder does have as consequence the Encoder does not react in TcMenu.


I suspect this is the above. However, I'm not really sure what you mean by you can't use that function? Can you not use the function because it doesn't work, or for some other reason?

IoAbstractionRef multiIoENC = ioFrom8754(0x20, 2); i need for TcMenu, without there's no reaction in the Menu, with it does run like a charm.
Being confused a bit as i cannot get an idea how the pins are defined then.


The code you provided in the orginal post looks right to me in terms of setup but just in the wrong place. Try moving before setupMenu.

How to setup the Encoder in an multiIoAbstraction for TcMenu


As above.

and another Renderer as e.g. using an standard 1366 library ( E.g. Adafruit ) ?


You can use any library that's compatible with Adafruit_GFX or you can use U8G2. When 2.0 comes out, we'll also support TFT_eSPI and LTDC frame buffer. You'd just use the custom Adafruit_GFX renderer option. In that case you create the variable yourself and just tell tcMenu the variable name you've created, and the class / include header name.

davetcc


Joined: Jan 19, 2019
Messages: 350
Offline
Also in terms of having to take over the display just to get better fonts and drawing. That shouldn't be needed from 2.0 onwards, the UI is completely skinnable, and can even be re-skinned while it's running, or custom per submenu or item.
davetcc


Joined: Jan 19, 2019
Messages: 350
Offline
Also, one last thing, you shouldn't need to set the pin modes on the encoder and switches yourself, the library will do it for you. Also you can't take a listener on the switch that is on the encoder, it's used by tcMenu internally, and a switch can only have one listener.

There are two ways you can get around this.

1/ in the takeOverDisplay rendering callback, the two parameters are the position of the encoder, and the button press state is one of the following values:

RPRESS_NONE = 0,
RPRESS_PRESSED = 1,
RPRESS_HELD = 2

2/ You could handle the button yourself, in that case I'd recommend setting up the encoder and switch in your own code and following the section on setting up the menu control manually in this guide: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/
FS


Joined: Mar 19, 2021
Messages: 6
Offline
Good afternoon Dave,
stripped down the code to a minimum to follow your advice.
#include "TCMenuTest_dr_menu.h"
#include <TaskManagerIO.h>
#include <IoAbstraction.h>
#include <IoAbstractionWire.h> 
#include <wire.h>

#define EXPANDER1 100
MultiIoAbstractionRef multiIo = multiIoExpander(EXPANDER1);
IoAbstractionRef multiIoENC = ioFrom8754(0x20, 2);  //2 is Interrupt Pin of ESP8266

#define   Button1       100
#define   EncoderPinA   101
#define   EncoderPinB   102
#define   EncoderButton 103

class keyListenerExpander : public SwitchListener {
  public:  
    
      void onPressed(uint8_t pin, bool held) override {
        Serial.println("Pressed " );
      }
  
      void onReleased(uint8_t pin, bool held) override {
         Serial.println("Released ");
      }  
  private:
} keyListenerExpander;



void onEncoderChange(int newValue) 
  {
    Serial.println("Encoder Change");
  }

 
void setup() {
    Serial.begin(9600);
    Wire.begin();
    multiIoAddExpander ( multiIo, ioFrom8574(0x20, 2), 10);  //Add Expander pins 100 - 109 
    setupMenu(); 
    switches.initialise(multiIo, true);
    switches.addSwitchListener(Button1,  &keyListenerExpander); 
    setupRotaryEncoderWithInterrupt(EncoderPinA, EncoderPinB, onEncoderChange, HWACCEL_REGULAR);    
}

void loop() {
    taskManager.runLoop();
}

void CALLBACK_FUNCTION LeaveMenu(int id) {
    // TODO - your menu change code
    Serial.println("Leave Menu");
}


The issue doesn´t get fixed doing that as shown here.

Serial monitor does show me that an test button and the encoder does work perfect.
Listener and Callback-function do print to the serial monitor.

The issue is: Using the Encoder to operate the menu does not work: The display shows no move of the cursor to submenus or similar, a test using the Encoder Button for a callback also failed.

Tested with automatic generated Code from TCMenu V1.7.5 also playing with the option Interrupt Switches choosen / not choosen in TCMenu

Thanks for your fantastic support !

Frank
davetcc


Joined: Jan 19, 2019
Messages: 350
Offline
The issue is: Using the Encoder to operate the menu does not work: The display shows no move of the cursor to submenus or similar, a test using the Encoder Button for a callback also failed.


Ah, I think I see how you're using it now. I assume you've told the designer UI not to automatically create any rotary encoder or input device on your behalf, and instead you've created them manually yourself in the main setup method.

edit - If this is the case just make sure that you have "no input" selected in the designer.

If that is the case, you just need to ensure that when the rotary encoder changes that you tell menuMgr about it, by calling the following from your encoder change callback when the menu is active:

void onEncoderChange(int newValue) 
{
   menuMgr.valueChanged(newValue);  // as you are managing things manually, you need to let menu manager know when this changes, unless you've taken over display
}


I see you're also managing the button yourself too, same applies here. When the menu is active and the button is released, call:

void onReleased(uint8_t pin, bool held) override {
         Serial.println("Released ");
         menuMgr.onMenuSelect(wasHeld);  // as you are managing things manually, you need to let menu manager know when this changes, unless you've taken over display
      }


This will allow you to keep control of the rotary encoder and select button, but at the same time allow the menu manager to handle the events when it's active.
FS


Joined: Mar 19, 2021
Messages: 6
Offline
Hello Dave,
that advice made it work, thanks a lot !

....made it in the morning in a manner to define the Encoder Pins as switches and wrote some
functions for left and right direction, a sequence check ( click, doubleclick, tripleclick ) and acceleration as
some Sundays got lost trying to find my bug . Being afraid not very efficient but it worked.

As i know the examples are reference No. 1 starting with TCMenu (....even the class documentation is perfect but at 1st
you need to get an idea how it works. )

That told parameter "wasHeld" i didn't find in the documentation and the button didn't reac, using "held" gave (me) the right reaction.
What is the reason for "washeld" ?

Frank
davetcc


Joined: Jan 19, 2019
Messages: 350
Offline
Yep it was held, just a typo on my part copying and pasting.
 
Forum Index » IoAbstraction & TaskManagerIO
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer