I’ve chased this critter for two days and now concede defeat. The attached sketch, comprising the menu navigation for my project, shows the most annoying erratic behavior. I deemed it rather long to put in code tags. If disabused of this notion I'll add a post with code tags used. Processor and development: Arduino Uno; Arduino IDE 1.8.2.
The menu has one level. After moving up or down to select a function/parameter the pushbutton on the encoder toggles a bool switch to allow you to manipulate that function or parameter. Pushing again toggles the menu back to up/down operation.
The part I’m having trouble with is the first two menu selections. Depending what code elsewhere is added/removed/modified, the display for these two can change. This can be as innocous as adding or commenting out a serial.print() statement. The second screen, “Mode” is usually well behaved, but not always. The first, “Current Position”, is the most problematic.
Depending what was changed, and there’s no rhyme or reason I can see, the second line of text will only print two, five, or some other incomplete number of characters. Sometimes the top line is also truncated, sometimes absent, sometimes correct. The various Serial.print were added to debug but they weren’t much help because whatever is sent to the LCD (1602) is duplicated on the serial monitor.
Along with this weirdness, traversing up and down through the options can be erratic or not. Erratic is defined as turning the rotary encoder CW, which is supposed to go ‘down’ the menu and having the selection - do nothing, go up, or go down. The reverse, CCW is also true. The encoder code is my own, proved correct, and rechecked, in a separate sketch. I have observed it operates much better with all Serial.print() statements out of the picture. Would driving this with an intrerrupt improve matters? Also, I’m using A0-A2 for the encoder inputs because the other side of the board was getting crowded.
An examination will show the code is very much a work in progress and there are functions yet to be added but I want to nail down the menu navigation before continuing.
Any clues to what is going on here are much appreciated.
turret_1.ino (10.2 KB)