0% found this document useful (0 votes)
61 views4 pages

Rotary Encoder Box Documentation: The Hardware Components and Features

The document discusses the hardware components, firmware modules, and configuration of a rotary encoder box. The box uses an Arduino Pro Micro and five rotary encoders to control functions in a computer game. The encoders can be configured in pages and profiles to send unique virtual joystick button codes. The LCD display helps track encoder functions. Configuration involves defining encoder types, labels, and profiles in code files.

Uploaded by

Md Mansoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views4 pages

Rotary Encoder Box Documentation: The Hardware Components and Features

The document discusses the hardware components, firmware modules, and configuration of a rotary encoder box. The box uses an Arduino Pro Micro and five rotary encoders to control functions in a computer game. The encoders can be configured in pages and profiles to send unique virtual joystick button codes. The LCD display helps track encoder functions. Configuration involves defining encoder types, labels, and profiles in code files.

Uploaded by

Md Mansoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Rotary Encoder Box Documentation

The Hardware Components and Features


The Arduino Pro Micro is chosen for this project because it is simple to operate as a HID-
class device.
There are five KY-040 encoders, one is for the Page Selector. Turning the knob cycle
through the operation pages. Short press of the push button jumps back to Page 1, long
press puts the box into sleep mode.
The four Function encoders are numbered 1 to 4. It is possible to have up to 12 pages,
thus giving you 48 programmable encoders. Each turn or push of the encoder will send
a unique “Virtual Joystick Button” number to the host computer. For example, turning
the knob counter-clockwise on the first encoder sends out VJB #1, clockwise sends out
VJB #2. The maximum number of VJBs is likely limited by the number recognizable in
your particular computer game. Pushing the button will then send VJB #3. Encoder may
be configured to respond to “Long-press”: holding the button down longer than 0.6
seconds will send yet a different VJB #. There’s more: an encoder may be configured to
have up to four rotary functions; to fire off an even larger number of different VJB #s.
For example, a triple-op rotary will emit 6 different VJB #s (3 CCWs, 3 CWs). Quick push
of the button, in this case, will be occupied instead for cycling through the triple
functions.
Virtual joystick button codes are automatically assigned. There is a build option to
either reserved 20 codes for every four encoders, or be continuously assigned.
Reserving code number is intended to leave a gap between, thereby attempting to keep
code assignments unchanged when minor modifications are made in configuration.
The 4-row LCD display will help you to keep track of what all those rotaries and
pushbuttons are good for. You decide what functions in your game you will want to
control, then sit back and design the layout of the box (via the Configuration.h code file).
It’s also up to you what labels to be displayed on the LCD. Finally, you use the control
assignment menu within your game to make the association, i.e. binding the Virtual
Joystick Buttons to the game’s operations.
Firmware Modules
(Top layer sketches)
RotaryBox.ino – The main code file with the requisite setup() and loop() functions.
Manages encoder scanning, sending out button code, page selection and the sleep
timer.
SupportSrves.ino – Extension of the above file. Mainly includes handling of the top
layer functionalities for the LCD, and power-down mode.
SetupSrvs.ino – Another extension file. Includes the UI routines for the Settings page.
Profile selection is the only setting at this time.

RotaryBox Library Modules


(In the libraries\RotaryBox folder)
CBoxConfig – Contains the configuration database, initialization, and interface to the
main program. The definitions for each of the operation page and rotary encoder on
the box are defined in the Configuration.h file. Setup() calls a function to assign virtual
joystick button numbers associated with the encoders. The main process loop() will rely
on this class to provide information on the characteristics of individual encoders.
CEncoderPlus – Responsible for the debouncing and interpretation of the rotary
movement and the pushbutton events. One object is assigned for each encoder. Loop()
needs to call into the desired encoder’s object once per loop to allow it to scan its
encoder.
CVirtualButton – Oversees that the button codes are sent to the host. This class has an
internal FIFO to channel button commands to the Joystick library class. Main loop to call
this object once per loop to allow its state machine to run. Having a FIFO enables the
caller to initiate as many button events as needed—similar to the auto-repeat feature of
a keyboard. This repeat feature is also utilized by the main loop.
Two public Arduino libraries are required, they are available to download from the web:
JoystickLibrary-version-2.0
LiquidCrystal_I2C-master.
How to configure the Pages and the Encoders - Configuration.h
There are four steps in defining/adding an encoder to the feature set. We’ll go over an
example of adding a knob to control the two wipers for the Zibo Mod Profile. The
procedure is admittedly convoluted, but is necessary in order to locate the label strings
into flash memory (saving precious RAM). Refer to the existing Configuration.h.
1. What type of encoder do you want?
There are two wipers (left and right), so let’s choose a double function rotary knob.
There’s no need for a Long-press function, so we add an EC_DOUBLE. Every knob
needs a description label to go with, we make up a name for it, for now: ELI_Wipers
(ELI stands for Encoder Label Index):
const sEncoderDef ENC_ZIBO[] =
{
… … … …
EC_DOUBLE, ELI_Wipers,
… … … …
};

2. Characterize the display label string


Finish the description label. First list the operations for each of the rotary operation, it
has operations for Wiper L and Wiper R; each separated by a ‘,’. It followed by the
merged descriptions for the short and long presses. We actually don’t have any, as the
short-press is taken as the cycler between the dual rotary functions. Use a ‘~’ to
designate the cycler option. Note the name given to the string ELS_Wipers (ELS stands
for Encoder Label String):
const char ELS_Wipers[] PROGMEM = "Wiper L,Wiper R,~";

See the source code comments for additional info and examples.

3. Add a pointer for string


Link the above string with a pointer, by adding a pointer in the following array. We
need to use the same exact name defined above. The ordering is not matter here, you
may append the pointer at the end.
const char* const ENC_pLABELS[] PROGMEM =
{
… … … …
ELS_Wipers,
};

4. Add the corresponding enum


Go back to near the top of the file and add an enum to be used by the encoder
definition. This name, and every name in here as well, must: a) follow the exact
corresponding order as defined in the array in step 3 above. b) Spell identically as it is
referenced back in step 1.
enum tEncLabelIndex
{
… … … …
ELI_Wipers,
};

Remember there are four encoders to a page. To leave a slot empty, use the
EC_RESERVED tag.

Managing Profiles
You’ll need to (1) add a structure for the new profile, and (2) add the name of the new
structure in the database. Here again, is an example from the Configuration.h file:
1. The definition below—an array of encoders, constitutes a profile, since it defines all
its encoders in all the pages:
const sEncoderDef ENC_ZIBO{} =
{
EC_SINGLE_LONG, ELI_Airspeed,
EC_SINGLE_LONG, ELI_Heading,
… … … …
ENC_TRAILER
};

2. The definition below gives the profile a name, allowing it to appear and be selectable
in the Rotary Box Settings UI.
const sProfile profiles[] =
{
"Zibo B738", ENC_ZIBO,
… … … …
"" // End marker
};

You might also like