Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » MultiIO abstraction and Encoder setup

Author: FS
19/03/2021 13:50:22
Hello,
being struggeling with the use of multiIO-abstraction and encoder.

Encoder is wired to an 8574 Expander, the expander INT-Pin is connected to Pin 2 of an ESP 8266 to get an interrupt.

Doing now some tests with this combination but running into problems.

i.) Operating the expander without multiIo using ioFrom8574 makes the expander work without any problems
ii.) Changing to multiIo doesn't let me allow to use the rotaries.
A test to define the PinA +PinB as switch using multiIO shows that both are operational.
iii.) Defining multiIo as reference in TCMenu has as effect the Encoder doesn't allow to change menu items. Also here: Push button switch works fine.

Do i have to define somehow Interrupts ? My understanding is the IvAbstraction does provide that service.

Attached the actual code.

#include <IoAbstraction.h>
#include <IoAbstractionWire.h>
#include <TaskManagerIO.h>
#include <Wire.h>



// to make life easier, probably define each expander
    #define EXPANDER1 100

// Multi IO generieren mit Pin 0 - 99 für ESP8266
    MultiIoAbstractionRef multiIo = multiIoExpander(EXPANDER1);


//Encoder
    const uint8_t encoderAPin = 101;
    const uint8_t encoderBPin = 102;
    
    // the maximum value (starting from 0) that we want the encoder to represent. This range is inclusive.
    const int maximumEncoderValue = 1000;
    


// Each time the encoder value changes, this function runs, as we registered it as a callback
//
void onEncoderChange(int newValue) {
    Serial.print("Encoder change ");
    Serial.println(newValue);
}


void onSwitchPressed(uint8_t key, bool held) 
  {
    
    ioDeviceSync(multiIo); // force another sync
  
    Serial.print("Switch "); 
    Serial.print(key);
    Serial.println(held ? " Held down" : " Pressed");
  }



class RepeatButtonListener : public SwitchListener {
private:
    int counter;
public:
    void onPressed(pinid_t pin, bool held) override {
        ++counter;
        Serial.print("Repeat button pressed ");
        Serial.println(counter);
    }

    void onReleased(pinid_t pin, bool held) override {
        Serial.print("Released after presses ");
        Serial.println(counter);
        counter = 0;
    }
} repeatListener;




void setup() 
  {
          Wire.begin();

          //Serielle Sxchnittstelle und Monitor
          Serial.begin(9600);
          Serial.println(" Start Setup");

       

          //8574 Expander added, 10 Pin 100 - 109
          multiIoAddExpander ( multiIo, ioFrom8574(0x20), 10);          
          Serial.println("expander 8574:  Pin 100 bis 109 hinzu über multiIoAddExpander");

          
          // Pin 8574 definition of Pins
          
                ioDevicePinMode(multiIo, EXPANDER1,   INPUT);  //P0
                ioDevicePinMode(multiIo, EXPANDER1+0, INPUT);  //P1 Pin 100 ( P0 auf 8574) Taster
                ioDevicePinMode(multiIo, EXPANDER1+1, INPUT);  //P2 Pin 101 Encoder Pin A
                ioDevicePinMode(multiIo, EXPANDER1+2, INPUT);  //P3 Pin 102 Encoder Pin B
                ioDevicePinMode(multiIo, EXPANDER1+3, INPUT);  //P4 Pin 103 ( P3 auf 8574) Taster Drehimpulsgeber
                
              
        Serial.println("ioDevicePinMode für Pin 100 + 103 hinzu");
        Serial.println("Multi IoExpander example");
        Serial.println("Io is setup, adding switch");
                
                
                switches.initialise(multiIo, true);
                switches.addSwitch(EXPANDER1 +0, onSwitchPressed);
                switches.addSwitch(EXPANDER1 +3, onSwitchPressed);  
                /*
                switches.addSwitch(EXPANDER1 +1, onSwitchPressed); //Test CLK / PinA as switch
                switches.addSwitch(EXPANDER1 +2, onSwitchPressed); //Test DT / PinB
                */

    
    setupRotaryEncoderWithInterrupt(encoderAPin, encoderBPin, onEncoderChange, HWACCEL_REGULAR);
    
    switches.changeEncoderPrecision(0, 0);


        
       Serial.println("setup is done!");
  }





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


Author: FS
19/03/2021 14:08:42
Sorry,
as always: Testing three-four days, reading a lot, doing notes before something gets addressed to a forum.
And just after the announcement the bug got found:

multiIoAddExpander ( multiIo, ioFrom8574(0x20, 2), 10);

means the interrupt pin of the ESP 8266 wasn't addressed properly.


Author: davetcc
19/03/2021 16:11:16
No problem, are you all good with it now?

Author: FS
21/03/2021 11:38:05
All good now - further fighting ongoing as coding is not really my profession....last time it was Fortran77 tow decades before. But I really wanna say thanks for your work and all the fantastic functions of the framework.




Register / Login  |  Desktop view  |  Jump to top of page