Display with rotary encoder

Rotary (or quadrature) encoders are those little knobs found on many devices to set the speaker volume. They can also have a push button built in.

Although I am aware of many DIY projects that drive a display for use with LCDproc that use keys as well, I didn't know about one using a rotary encoder. So I decided to build my own ...

AVR implementation

Currently I am using a myAVR Board light, a simple development board with an ATmega8 running at 3.6864 MHz clock speed, which is connected to my PC using a USB-to-serial bridge.

It should run on ATmega48/88/168/328 or at other clock speeds, but I have not tested this. Have a look at the Readme.txt file supplied with the download package.

My project - named "myLoS" for now - uses code from the following sources:

I chose the LoS-panel device's protocol because it is already supported by LCDproc. Unfortunately the original code is in Assembler which I don't use for my own projects. Therefore I took two other well known libraries written in C by Peter Fleury to drive the display and for interrupt based serial communication.

The mikrocontroller.net site is the equivalent to avrfreaks.net but in German language and contains many good examples for programming microcontrollers like the AVR ones. The rotary encoder example uses a timer based interrupt to poll the encoder. I modified the example to work with my ATmega8.


myLoS schematic

(Click image to enlarge.)

Configuring LCDproc

Currently two patches are required. One patch for LCDproc's menu system and one to tell the hd44780-serial driver about the adjustable backlight. The patch files are supplied in the download file (see below). An example configuration file is provided, too.


myLoS-0.7.tar.gz (contains source files, patches, and example configuration file)


Version 0.7 (2014-01-27):

  • Update the UART library to the latest version (fix compilation with newer versions of AVR Libc / AVR GCC (some signal names have been deprecated).

Version 0.6 (2013-02-23):

  • Fix build with AVR Libc 1.8 (prog_char has been deprecated)

Version 0.5 (2012-06-09):

  • Change control lines and PWM for LCD to match with myAVR LCD Add-On 2.5
  • Change encoder pins to free up TWI
  • Enhance state machine and add an escape sequence (new patch for hd44780-serial.h required).

Version 0.4 (2012-05-17):

  • Changed PWM mode to phase correct (mode 1). This fixes the problem that the backlight did not turn off completely with some displays.

Version 0.3 (2012-03-17):

  • Added PWM for the backlight (requires current LCDproc version).
  • Better internal state tracking.

Version 0.2 (2012-03-01):

  • Initial release


Q: Why are you using that odd frequency (3.6864 MHz)?
A: These 'odd' frequencies (like 3.6864 or 7.3728 MHz) divide to the standard baud rates without remainder and therefore are more suitable for use with USART operation (see ATmega8 datasheet, sect. 19.11).
Q: Why is there no resistor for the LCD backlight?
For this particular circuit it is not necessary as the voltage drop across the transistor results in a voltage level suitable for my backlight (~4.2V). You should check which voltage is required for driving the backlight of your display and add a resistor between the transistor and VCC if necessary.