[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 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

Rotary encoder for menu navigation on 8574 expander? RSS feed
Forum Index » tcMenu Arduinio library
Author Message
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
Is it possible to setup the navigation rotary encoder (slot 0) on pins of an 8574 expander?

I don't seem to see this as an example and I don't know what I would pass as the last 3 arguments to menuMgr.initForEncoder() to make this work. I wasn't able to get 2 encoders to work on my SAMD21 Arduino Zero Knockoff board so now I'm trying to use a Seeedstudio Xiao with a PCF8574 expander. It didn't occur to me that this might not be possible until I wired it all up, generated the tcMenu code, setup the Adafruit GFX using SPI and then went to edit the 3 pins for the main encoder. Once again I think im confusing code examples from different examples. Before I spend another weekend trying can you provide a sanity check?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
I wasn't able to get 2 encoders to work on my SAMD21 Arduino Zero


Did you try the simple example sketch that I sent to you? That just printed to the console every time there was a callback? I ask because I tested that sketch on a couple of boards before I sent it to you? I think it is useful to know at this point if there is some kind of hardware integration problem with your SAMD board, or if the problem was elsewhere. It would be very useful for me if you could run that example sketch, you should only need to change the pins to match your situation, nothing more. I ask because there are many possible modes of failure here: pin not a pull-up pin, pin not available for interrupt input, a problem in IoAbstraction with that board etc.

Is it possible to setup the navigation rotary encoder (slot 0) on pins of an 8574 expander?


Yes, you would create a PCF8574 abstraction as per the example sketches that work with that I2C expander. For example https://github.com/davetcc/IoAbstraction/blob/master/examples/example8574/example8574.ino

You would then provide that variable name as the IO expander reference in tcMenu Designer rotary encoder configuration. At that point any pins you provide are the data pins on the I2C device you provided. EG 0-7.

I come back to the thing that concerns me here. We did not establish the cause of the problem on the other board, we don't know if it's a problem in the sketch, a hardware issue, or a bug in IoAbstraction somewhere.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
The above reference to a previous thread was: https://www.thecoderscorner.com/jforum/posts/list/70.page
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
I just responded to the other post so there is some closure and a demarcation between that issue and this one. Since I'm now using an expander and a different board entirely I had thought this issue was different enough to warrant a new post. Sorry if doing so just made this more confusing. That's not what I was going for. I think my issue was from using a knockoff of an arduino m0 that is supposed to use the "Arduino Zero" board type but now that I dug around that board it is different. What I saved in dollars I lost in time.

You tied a lot of functionality together with these 3 libraries so maybe I'm expecting too much of myself that I'll understand it all. I really like how the tcMenu App makes building the menu so easy.

Without using the 8574 the only thing I had to do was setup the renderer and encoder pins and it pretty much worked right away. I think I'm confused now because when I used use the tcMenu app to tell IoAbstraction to use IoFrom8574 but then got errors because it didn't exist. My major malfunction is that the examples you provided before (to demonstrate that both encoders could work) and the example8574 here don't use tcMenu, and it wasn't clear to me that I had to create that IOAbstraction (object/interface/variable) for the 8574 and then use the 0 through 7 pins on the encoder. For some reason I thought the TcMenu app would generate that too. I kept looking for something to tie it all together and I just wasn't finding it because clearly I don't fully grasp how "switches" knows how to do what it does.

I guess despite being motivated I'm terribly challenged and am kind of a glutton for failure. When I have time this weekend I'll see if I can get the main encoder working on the 8574 using your feedback.

Thanks again for your responsiveness.


davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
and it wasn't clear to me that I had to create that IOAbstraction (object/interface/variable) for the 8574 and then use the 0 through 7 pins on the encoder. For some reason I thought the TcMenu app would generate that too. I kept looking for something to tie it all together and I just wasn't finding it because clearly I don't fully grasp how "switches" knows how to do what it does.


Agreed, there's probably some middle ground where the simplest of IoExpanders can be created automatically during code generation. But at the moment, we haven't got that sorted out. For now, you do have to create the IoAbstractionRef in your main source file, with the same name as you enter into the IoAbstraction Reference field in the UI. It's not particularly intuitive.

We have shifted focus recently to stability and usability, instead of building out any more large features. The libraries are already fully-featured and the feedback is always, they have all the features people could ever use, but they are not well enough documented, and usability has traditionally been a bit off for new users, and this has to be the priority.

This will mean that the documentation will get better quite quickly and that some small usability features will be forthcoming.

If you had any ideas on how we could improve the experience for users using an IO expander that would be great to hear.
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
I got the screen working with the new board but still no rotary encoder function.

This is the board I'm using - https://wiki.seeedstudio.com/Wio-Lite-MG126/
Here is the schematic (download) - https://files.seeedstudio.com/wiki/Wio-Lite-MG126/res/Wio%20Lite%20MG126.zip

Expander interrupt pin is pin D9
SDA/SCL is connected to expander
pins 7,6,5,4,3,2 are connected to the encoders

#include "Menu5_menu.h"
#include <IoAbstraction.h>
#include <IoAbstractionWire.h>
#include <TaskManagerIO.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

#include <Wire.h>

#define GFX_DC 13
#define GFX_CS 12
//#define GFX_RST 7
//#define GFX_MOSI 11
//#define GFX_MISO 12
//#define GFX_CLK 8 //sck

#define PWM_OUT1  5
#define PWM_OUT2 6


//#define ENABLE_DISABLE_BUTTON PIN_WIRE_SCL

//#define ROTARY2_CLK 7
//#define ROTARY2_DT 9
//#define ROTARY2_SW PIN_WIRE_SDA

IoAbstractionRef ioExpander = ioFrom8574(0x20);

// remember the last state of the IO expander switch so we can log any changes later
//uint8_t lastSwitchIoExp = 0;

//#define MAX_ROTARY_MODES 1

Adafruit_ST7735 gfx = Adafruit_ST7735(GFX_CS, GFX_DC, -1);
AdaColorGfxMenuConfig colorConfig;

void setup() {
    //SerialUSB.begin(9600)
    pinMode(PWM_OUT1,OUTPUT); // First output PWM
    pinMode(PWM_OUT2,OUTPUT); // Second output PWM
    ioDevicePinMode(ioExpander, 7, INPUT); //Slot 0 CLK
    ioDevicePinMode(ioExpander, 6, INPUT); //Slot 0 DT
    ioDevicePinMode(ioExpander, 5, INPUT); //Slot 0 SW
    ioDevicePinMode(ioExpander, 4, INPUT); //Slot 1 CLK
    ioDevicePinMode(ioExpander, 3, INPUT); //Slot 1 DT
    ioDevicePinMode(ioExpander, 2, INPUT); //Slot 1 SW

    prepareAdaMonoGfxConfigLoRes(&colorConfig);
    gfx.initR(INITR_144GREENTAB); //Adafruit 1.44"
    gfx.setRotation(1);
    
    switches.initialiseInterrupt(ioFrom8754(0x20, 9), true);
    Wire.begin();

    setupMenu();

}

void loop() {
    taskManager.runLoop();

}


In the menu file the setupMenu() looks like this

void setupMenu() {
  menuPWMOut.setReadOnly(true);
  menuResonanceSweep.setReadOnly(true);
  menuPWMOutByPulseWidthOutput1.setReadOnly(true);
  menuPWMOutByPulseWidthOutput2.setReadOnly(true);

  renderer.setGraphicsDevice(&gfx, &colorConfig);
  switches.initialiseInterrupt(ioExpander, true);
  menuMgr.initForEncoder(&renderer, &menuPWMOut, 7, 6, 5);
  remoteServer.begin(&SerialUSB, &applicationInfo);
}


I verified continuity on the expander pins. I know this encoder chip is active low but I don't understand how that ties into "switches.initialiseInterrupt(ioFrom8754(0x20, 9), true);" and the setting of the expander pins via ioDevicePinMode.

Still struggling here. Can I get another set of eyes on this please?
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
Also forgot to mention that the 3 address pins on the expander are low so I the adress should be 0x20 from what I understand.

This is the expander board I'm using - https://www.amazon.com/gp/product/B07XD2K4GH/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline

* The expander configured on line 29 is the one that will be used, as it's the one you set up in tcMenu Designer. But you need to add the interrupt line as the 2nd parameter - see *1
* lines 43-49 setting pin mode will be done on your behalf in by the rotary encoder class. It actually needs input pull-up but again, these are not needed but don't do harm, as settings will be overridden during setupMenu.
* line 54 in the setup method, not needed and indeed redundant resulting in a memory leak of the created IoAbstraction object. This is because setupMenu reinitialises switches given the ioexpander you created.

*1
IoAbstractionRef ioExpander = ioFrom8574(0x20, pinConnecting8574Interrupt);


I can't see there being problems with a commercial expander board, the most probable issue is that the actual expander being used is not configured with an interrupt pin. If my above steps do not fix the situation, I would get a scope on the A and B pins of the encoder and check that you see both lines are at Vcc until the encoder is turned, in which case they drop to low and with A / B slightly out of step.
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
I didn't orphan this. Some other things in life haven't been going the way I'd like. I'm sure this is true for everyone right now. Your feedback is not for naught.
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
Made the above changes.... still not working...

I verified that:
-the 8574 is connected to and getting 3.3v and Gnd on VCC and Gnd respectively
-SDA/SCL have continuity to boards SDA/SCL and not accidentally reversed
-main encoder connects to 8574 on pins 7,6,5 corresponding to CLK, DT, SW respectively
-rotary encoder A/Clk and B/DT do indeed toggle in quadrature as the dial is indexed on the scope.... oh wait.... no they don't!

Encoder power was going to Gnd instead of 3.3V because the rail labeling is reversed compared to the elegoo power module pins connected to my protoboard. It's SO easy to get something wrong.

I'll be a sonovabitch!

Dave... the control encoder works!

I must say that even if this wiring was right I still wouldn't be able to move forward.

Did you ever know this?

As far as support for a free library goes thank you for not being the kind of arrogant personality that discourages people from asking for help.

In all seriousness.... aside from the connection issue do you think you understand why I was so confused and mixing up the tutorials?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
rotary encoder A/Clk and B/DT do indeed toggle in quadrature as the dial is indexed on the scope.... oh wait.... no they don't!


Ah OK that makes sense. At least it is working now.

aside from the connection issue do you think you understand why I was so confused and mixing up the tutorials?


We do, a company level decision has been taken that no new functionality will be added unless it's prioritised by a customer. We need to focus as much effort as possible on getting the documentation right. It's admittedly some way off. On that front, if you had any suggestions on what could be improved, we'd be glad to hear them.
kritischer


Joined: Oct 4, 2020
Messages: 25
Offline
I'll think about this and let you know. I'd like to provide good feedback and not rush it and cause more confusion.
 
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.