├── misc
├── pcb.jpg
└── FRITZING-esp32-oled.fzz
├── images
├── menu.jpg
└── project.png
├── libraries_used.zip
├── README.md
├── oldVersion.ino
├── oled.ino
└── LICENSE
/misc/pcb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanesq/BasicOLEDMenu/HEAD/misc/pcb.jpg
--------------------------------------------------------------------------------
/images/menu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanesq/BasicOLEDMenu/HEAD/images/menu.jpg
--------------------------------------------------------------------------------
/images/project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanesq/BasicOLEDMenu/HEAD/images/project.png
--------------------------------------------------------------------------------
/libraries_used.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanesq/BasicOLEDMenu/HEAD/libraries_used.zip
--------------------------------------------------------------------------------
/misc/FRITZING-esp32-oled.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanesq/BasicOLEDMenu/HEAD/misc/FRITZING-esp32-oled.fzz
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Basic OLED with rotary encoder Menu for ESP8266/ESP32/Probably others
2 |
3 | For either Arduino IDE or PlatformIO.
4 |
5 | Note: This is a completely different sketch as of Nov21 as I decided to start again and create a version which is none blocking.
6 | The old version oldVersion.ino is easier to use but will stop everything else whilst waiting for user input etc.
7 |
8 |
9 |  |
10 |  |
11 |
12 |
13 |
A simple to use, cheap to build and simple to wire menu system using a small oled display and a rotary encoder.
14 | I created it so I can quickly and easily add an oLed menu to any new projects, as you can see it only requires 5 wires (plus power).
15 |
Uses libraries: Adafruit_SSD1306 and Adafruit_GFX_Library
16 |
17 |
It gives basic menus, the ability to enter a numerical value or choose from a list.
18 |
19 |
The sketch uses the cheap 128x64 oled displays but the settings can be changed to work with different size displays.
20 |
I am very impressed with these displays, they are cheap, easy to use and despite being small they are still easy to read.
21 |
Note: I have seen reports of them being easily damaged by static and I have had one fail which could have been for this reason, I think it best to be careful of this when using one on a breadboard etc, they seem ok once installed in a project.
22 |
If you have any poor connections (especially to the rotary encoder) this can result in garbage being displayed which can make you think there is a fault with the display.
23 |
24 |
If you are new to the esp8266 using one of these OLED displays would be a very good project for you to try.
25 |
earch ebay for "SSD1306 i2c" and you should be able to pick up an oled display like the one in the picture above for around £3. Search for "ky-040" for a rotary encoder for around £1.
26 |
27 |
You can try it out on this online emulation: https://wokwi.com/arduino/projects/323967017900048980
28 |
29 |
BTW - I have incorporated all this in to my basicWebserver starting point sketch which may be of interest: https://github.com/alanesq/BasicWebserver
30 |
Even if you do not use BasicWebserver, this version may be easier to include in your own projects as you just have to include oled.h and add a single line to your setup and loop.
31 |
32 |
for more oled info see: https://randomnerdtutorials.com/guide-for-oled-display-with-arduino/
33 |
34 |
Note: I had a lot of trouble finding some code which would work reliably with a rotary encoder (i.e. the interupt section) but find this to be very good although this may not be the case with all encoders?
35 |
See these videos for more info: https://www.youtube.com/watch?v=b2uUYiGrS5Y
36 |
37 |
If you have a cnc router there is a Fritzing file in the MISC folder I use for making PCBs which may be of interest. It is in a format which is very basic but it allows me to modify it and create a PCB as quickly as possible.
38 |
39 |
40 |
41 |
42 | https://github.com/alanesq/BasicOLEDMenu
43 |
--------------------------------------------------------------------------------
/oldVersion.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************************
2 | *
3 | * OLED display Menu System - i2c version SSD1306 - 31Aug21
4 | *
5 | * https://github.com/alanesq/BasicOLEDMenu
6 | *
7 | *
8 | **************************************************************************************************
9 |
10 | oled pins: esp8266: sda=d2, scl=d1
11 | esp32: sda=21, scl=22
12 | Uno: sda=A4 , scl=A5
13 | oled address = 3C
14 | rotary encoder pins:
15 | esp8266: d5, d6, d7 (button)
16 | esp32: 13, 14, 15
17 | Uno: 2, 3, 4
18 | Note: on esp8266 you can change the button from d7 to d3 instead leaving d7 and d8 free to use
19 |
20 |
21 | The sketch displays a menu on the oled and when an item is selected it sets a
22 | flag and waits until the event is acted upon. Max menu items on a 128x64 oled
23 | is four.
24 |
25 | See the section "customise the menus below" for how to create custom menus inclusing selecting a value,
26 | choose from a list or display a message.
27 |
28 |
29 | for more oled info see: https://randomnerdtutorials.com/guide-for-oled-display-with-arduino/
30 | or: https://lastminuteengineers.com/oled-display-esp32-tutorial/
31 |
32 |
33 |
34 | **************************************************************************************************/
35 |
36 | // settings
37 |
38 | const String stitle = "simple_menu"; // script title
39 | const String sversion = "07Dec20"; // script version
40 |
41 | bool serialDebug = 1; // enable debug info on serial port
42 |
43 | int OLEDDisplayTimeout = 10; // oled menu display timeout (seconds)
44 |
45 | int itemTrigger = 1; // rotary encoder - counts per click
46 |
47 | #define OLED_ADDR 0x3C // OLED i2c address
48 |
49 | #if defined(ESP8266)
50 | // esp8266
51 | const String boardType="ESP8266";
52 | #define I2C_SDA D2 // i2c pins
53 | #define I2C_SCL D1
54 | #define encoder0PinA D5
55 | #define encoder0PinB D6
56 | #define encoder0Press D7 // button - Note: on esp8266 you can change this from d7 to d3 leaving d7 and d8 free to use
57 |
58 | #elif defined(ESP32)
59 | // esp32
60 | const String boardType="ESP32";
61 | #define I2C_SDA 21 // i2c pins
62 | #define I2C_SCL 22
63 | #define encoder0PinA 13
64 | #define encoder0PinB 14
65 | #define encoder0Press 15 // button
66 |
67 | #elif defined (__AVR_ATmega328P__)
68 | // Arduino Uno
69 | const String boardType="Uno";
70 | #define I2C_SDA A4 // i2c pins
71 | #define I2C_SCL A5
72 | #define encoder0PinA 2
73 | #define encoder0PinB 3
74 | #define encoder0Press 4 // button
75 | #else
76 | #error Unsupported board - must be esp32, esp8266 or Arduino Uno
77 | #endif
78 |
79 |
80 | // -------------------------------------------------------------------------------------------------
81 |
82 |
83 | //#include // used to display free memory on Arduino (useful as it can be very limited)
84 | #include
85 | #include
86 |
87 | // rotary encoder
88 | volatile int16_t encoder0Pos = 0; // current value selected with rotary encoder (updated in interrupt routine)
89 | volatile bool encoderPrevA = 0; // used to debounced rotary encoder
90 | volatile bool encoderPrevB = 0; // used to debounced rotary encoder
91 | bool reButtonState = 0; // current debounced state of the button
92 | uint32_t reButtonTimer = millis(); // time button state last changed
93 | int reButtonMinTime = 500; // minimum milliseconds between allowed button status changes
94 |
95 | // oled menu
96 | const byte menuMax = 5; // max number of menu items
97 | const byte lineSpace1 = 9; // line spacing (6 lines)
98 | const byte lineSpace2 = 16; // line spacing (4 lines)
99 | String menuOption[menuMax]; // options displayed in menu
100 | byte menuCount = 0; // which menu item is curently highlighted
101 | String menuTitle = ""; // current menu ID number (blank = none)
102 | byte menuItemClicked = 100; // menu item has been clicked flag (100=none)
103 | uint32_t lastREActivity = 0; // time last activity was seen on rotary encoder
104 |
105 | // oled SSD1306 display connected to I2C (SDA, SCL pins)
106 | #define SCREEN_WIDTH 128 // OLED display width, in pixels
107 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels
108 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
109 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
110 |
111 |
112 |
113 | // -------------------------------------------------------------------------------------------------
114 | // customise the menus below
115 | // -------------------------------------------------------------------------------------------------
116 |
117 | // Useful commands:
118 | // void reWaitKeypress(20000); = wait for the button to be pressed on the rotary encoder (timeout in 20 seconds if not)
119 | // chooseFromList(8, "TestList", q); = choose from the list of 8 items in a string array 'q'
120 | // enterValue("Testval", 15, 0, 30); = enter a value between 0 and 30 (with a starting value of 15)
121 |
122 |
123 | // Available Menus
124 |
125 | // main menu
126 | void Main_Menu() {
127 | menuTitle = "Main Menu"; // set the menu title
128 | setMenu(0,""); // clear all menu items
129 | setMenu(0,"list"); // choose from a list
130 | setMenu(1,"enter a value"); // enter a value
131 | setMenu(2,"message"); // display a message
132 | setMenu(3,"MENU 2"); // change menu
133 | }
134 |
135 |
136 | // menu 2
137 | void menu2() {
138 | menuTitle = "Menu 2";
139 | setMenu(0,"");
140 | setMenu(0,"menu off");
141 | setMenu(1,"RETURN");
142 | }
143 |
144 |
145 | // -------------------------------------------------------------------------------------------------
146 |
147 |
148 |
149 | // menu action procedures
150 | // check if menu item has been selected with: if (menuTitle == "