Rotary Encoder - turn to change pages

I’m trying to use a simple rotary encoder to allow me to changes information “pages” on an OLED display by turning. I’ve tried to implement some code to allow me to do so but it’s giving me an issue with the “feedgps”.

Before I tried to add the encoder I had the code working fine. having the “pages” change based on time.

I’m using the following:

  • Teensy 4.0
  • GPS Module GPS NEO-6M
  • BME 280
  • 0.96" Inch White I2c IIC Serial 128x64 OLED LCD LED
  • KY-040 360 Degree Rotary Encoder

The error message I’m receiving on compiling is the following:
‘feedgps’ was not declared in this scope

The code is too large to post so I have attached it.

Thank you for your help.

122620_GPS_Vangon_Fonts_HarwareSerial_Encoder.ino (9.13 KB)

Where does the gpsdump() function end ?

If you Auto Format the code in the IDE you will see that the feedgps() function does not start on the left margin as it should

BTW - I have recently been using one of those oleds along with a rotary encoder myself and I had a lot of trouble finding a reliable way of reading the rotary encoder (i.e. with it reliably moving one step at a time without jumping about etc.)
If you find you have similar issues take a look at the "rotary encoder interrupt routine" at the bottom of this sketch as whilst not very elegant I am really pleased with how well it works.

UKHeliBob:
Where does the gpsdump() function end ?

If you Auto Format the code in the IDE you will see that the feedgps() function does not start on the left margin as it should

Hello, thanks for responding. I tried the AutoFormat and didn't see anything change. Still received the same error.

dport7:
Hello, thanks for responding. I tried the AutoFormat and didn't see anything change. Still received the same error.

AutoFormat only adjusts the text to a standard layout, it does not fix any errors or mistakes. By aligning the text certain typing errors/omissions can become more obvious.

If necessary, go through the sketch line by line and verify that every grouping character - "{ } ( ) " - has a mate.

Thanks for the suggestions. I was able to sort that out.

I now have the encoder working to rotate through the cases.

One of the issues I’m having is the encoder jumping or bouncing. Turning it very slowly the encoder value tends to jump all over the place.

The other issue is that some of my texts jump after the first second of display. (see video)
Jumping Text Video

The lastest code attached below

Thanks for your help.

122720_GPS_Vangon_Fonts_HarwareSerial_Encoder.ino (10.6 KB)

dport7:
One of the issues I'm having is the encoder jumping or bouncing. Turning it very slowly the encoder value tends to jump all over the place.

This is the problem I was having myself and why I suggested you look at my code (post #2 above)
I have found that using this method resolves all this and it now moves one position per click every time.

alanesq:
This is the problem I was having myself and why I suggested you look at my code (post #2 above)
I have found that using this method resolves all this and it now moves one position per click every time.

Yes, I have looked at that.
I was having trouble picking apart the pieces I needed to implement in my code.
Any hints where to start there?
I have to apologise I'm very new to this.
Thanks for your help.

Hi,
I have had a try at modifying your sketch but I can’t test it as I don’t have all the required hardware etc. set up but hopefully it will at least demonstrate how it could be included in your code if it doesn’t work?
Basically it just replaces the code in your “Encoder_san()”
It works by systematically going through each valid change in the rotary encoder pins and rejects any triggers which are not valid.

122720_GPS_Vangon_Fonts_HarwareSerial_Encoder-modified.ino (11.5 KB)

alanesq:
Hi,
I have had a try at modifying your sketch but I can't test it as I don't have all the required hardware etc. set up but hopefully it will at least demonstrate how it could be included in your code if it doesn't work?
Basically it just replaces the code in your "Encoder_san()"
It works by systematically going through each valid change in the rotary encoder pins and rejects any triggers which are not valid.

Thank you so much! It's very kind of you to put it together for me!!
I'm getting a Compiling error to the Teensy

 else if Serial.println ("Error: invalid rotary encoder pin state - prev=" + String(encoderPrevA) + ","
                         + String(encoderPrevB) + " new=" + String(pinA) + "," + String(pinB));

It appears that the Serial.println is causeing the issue. When I take that out of the code it will compile and load. Although it's still acting in a similar way, and without that I can't see how the encoder is behaving.
Any thoughts?
Thank you!!!!

By far, the best rotary encoder technique I've come across is based on using state transition tables. If properly implemented, you get debouncing for free. See: Buxtronix: Rotary encoders, done properly.

You're welcome to try an implementation of this algorithm that I wrote. I've recently updated it with Teensey 4.x support: GitHub - gfvalvo/NewEncoder: Rotary Encoder Library

gfvalvo:
By far, the best rotary encoder technique I’ve come across is based on using state transition tables. If properly implemented, you get debouncing for free. See: Buxtronix: Rotary encoders, done properly.

You’re welcome to try an implementation of this algorithm that I wrote. I’ve recently updated it with Teensey 4.x support: GitHub - gfvalvo/NewEncoder: Rotary Encoder Library

Hello gfvalvo!
Believe it or not (considering my lack of skill) I got your encoder library to work with my sketch!!
I looked at one of your examples and the encoder ran very fast and accurately.
When I implemented it into my sketch things slow down quite a bit.
Do you have any suggestions that might help it run a bit smoother?
See my updated sketch attached.
Thanks again!!

122720_GPS_Vangon_Fonts_HarwareSerial_Encoder_Using_NewEncoder_.ino (10.6 KB)

dport7:
When I implemented it into my sketch things slow down quite a bit.

Right here is a huge (although perhaps not the only problem):

while (millis() - start < 1000) {  // Every 1 seconds we print an update
    if (feedgps())
      newdata = true;
  }

That code will block execution of your application for up to one second while doing nothing but checking the GPS. The encoder library will still update because it runs on interrupts. But, your main application code will become totally unresponsive.

There are many examples and tutorials about how to achieve a multi-tasking environment on Arduino. A few are:
Arduino IDE: File → Examples → 0.2Digital → BlinkWithoutDelay