Test bench with rotary encoder for AltSerialGraphicLCD version - Spirik/GEM GitHub Wiki
Support for AltSerialGraphicLCD library should be enabled first, see Configuration section of Readme for details.
The following basic configuration can be prepared in order to follow along with the examples provided with the library.
About
Test bench for AltSerialGraphicLCD version of library consists of 128x64 Graphic LCD screen with properly configured SparkFun Graphic LCD Serial Backpack and rotary encoder with built-in button used to navigate through the menu.
Test bench can be replicated using custom shields.
Parts List
- Arduino UNO or compatible
- Rotary encoder with built-in button (e.g.)
- 128x64 Graphic LCD based on KS0108B chipset or compatible (e.g.)
- SparkFun Graphic LCD Serial Backpack with updated firmware
Schematic
Schematic is simple. Three signal terminals of rotary encoder (two for rotation direction, one for button) are connected to the input pins of Arduino initilized with INPUT_PULLUP
mode with internal pullup resistors activated (alternatively it is possible to connect terminals using external pullup 10kOhm resistors and INPUT
mode). You may wish to implement additional debounce filtering to minify chances of false readings at the moment of button press (or try to increase value of the debounceDelay
parameter during KeyDetector initialization).
SparkFun Graphic LCD Serial Backpack is attached to LCD screen and connected to the 5V power source and to digital pins 8 and 9 of Arduino for serial communication via SoftwareSerial library.
Breadboard
Connect channel A output (also called channel 1, CLK, etc.) of encoder to Arduino input pin 2, channel B output (also called channel 2, DT, etc.) to pin 3, first button output (usually called SW) to pin 4. Connect second button output (if present) and ground terminals of encoder to ground. Connect power terminal (if present) to 5V or 3.3V (depending on Arduino board being used).
Note that it may be required to swap channel terminals of encoder if direction of rotation is determined incorrectly.
Connect LCD screen to SparkFun Graphic LCD Serial Backpack through its 20 control pins. Connect TX pin of backpack to digital pin 8 of Arduino, connect RX pin of backpack to digital pin 9 of Arduino. Connect backpack to 5V power source and to ground (through its Vin and GND pins respectively).
Use
This test bench is compatible with the rotary encoder based AltSerialGraphicLCD examples supplied with the GEM library (if not stated otherwise).
After compiling and uploading sketch to Arduino, wait while LCD screen boots and menu is being initialized and drawn to the screen. Then start rotating knob of the encoder and pressing its button to navigate and interact with the menu. The following control scheme is implemented.
Encoder | Key identifier | Action |
---|---|---|
Rotate CW | GEM_KEY_DOWN |
Navigate down through the menu items list, select previous value of the digit/char of editable variable, or next option in select |
Rotate CCW | GEM_KEY_UP |
Navigate up through the menu items list, select next value of the digit/char of editable variable, or previous option in select |
Rotate CW while pressed | GEM_KEY_RIGHT |
Navigate through the link to another (child) menu page, select next digit/char of editable variable, execute code associated with button |
Rotate CCW while pressed | GEM_KEY_LEFT |
Navigate through the Back button to the previous menu page, select previous digit/char of editable variable |
Short press | GEM_KEY_OK |
Toggle bool menu item, enter edit mode of the associated non-bool variable, exit edit mode with saving the variable, execute code associated with button |
Long press | GEM_KEY_CANCEL |
Navigate to the previous (parent) menu page, exit edit mode without saving the variable, exit context loop if allowed within context's settings |
See description of the specific example for details.