t07 - olikraus/m2tklib GitHub Wiki
Tutorial 7: User Interface Simulation with the Arduino Serial Monitor
This tutorial will explain how to simulate button input and/or display output.
Theory
M2tklib can use the Arduino Serial Monitor as event source and/or graphics handler (Since version 1.08 of M2tklib).
m2_es_arduino_serial
: Use the serial monitor as event source. Buttons do not need to be connected to the Arduino board.m2_gh_arduino_serial
: Use the serial monitor to simulate a 4x20 display. M2tklib can be tested without any physical display..
The event source and the graphics handler are independent from each other. One of them can be used, but also the combined use of m2_es_arduino_serial
and m2_gh_arduino_serial
is possible.
Example
Reference: Serial example.
Simulation of Button Events
The constructor for a LiquidCrystal
display will look like this:
M2tk m2(&top_el, m2_es_arduino, m2_eh_4bs, m2_gh_lc);
To use the serial monitor as replacement for the hardware button events, replace the second argument with m2_es_arduino_serial
:
M2tk m2(&top_el, m2_es_arduino_serial, m2_eh_4bs, m2_gh_lc);
A setup of the pins is not required:
m2.setPin(M2_KEY_SELECT, uiKeySelectPin); // not required for the serial monitor
m2_es_arduino_serial
simulates six buttons. This means that all event handler
are supported:
Event Handler |
---|
m2_eh_2bs |
m2_eh_4bs |
m2_eh_4bd |
m2_eh_6bs |
OLED display controlled by events from the serial monitor: Use 's' to select an element and 'n' to jump to the next element.
Simulation of a 4x20 Character Display
To use the serial monitor as replacement for a display, replace the last argument with m2_gh_arduino_serial
:
M2tk m2(&top_el, m2_es_arduino_serial, m2_eh_4bs, m2_gh_arduino_serial);
No further setup is required. The content of the simulated display will be shown on the serial monitor.
Note: Menu definitions for a character display are not always portable to graphics displays:
- Character displays do not support additional styles (
f
option) - Character displays have different interpretation of the arguments for the
x
,y
,w
andh
options.
Full simulation of M2tklib with no hardware:
Conclusion
- It is possible to use and simulate menues without additional hardware (just a plain Arduino board)
- Use
m2_es_arduino_serial
in the M2tk constructor to simulate button events - Use
m2_es_arduino_serial
in the M2tk constructor to simulate a 4x20 character display
Links
- Previous Tutorial: Low Level Graphics GLCD U8g
- Next Tutorial: User Forms (PWM Pin List)
- Wiki Start Page