As with the previous tutorials, here are a few more examples that should help you to solve any questions and problems you may have.
The goal of this tutorial is to use a joystick to move a crosshair on a screen. The respective XY position and the status of the button should also be displayed.
- mandatory SPI OLED display (SH1106 Waveshare)
- mandatory 1x joystick
- few cables
- optional breadboard
Here you can see the respective wiring for the circuit.
| Device | Device Pin | ESP Pin |
|---|---|---|
| OLED | VCC | 3V3 |
| OLED | GND | GND |
| OLED | NC | - |
| OLED | DIN | 23 |
| OLED | CLK | 18 |
| OLED | CS | 2 |
| OLED | DC | 5 |
| OLED | RES | 4 |
| Joystick | +5V | 3V3 |
| Joystick | GND | GND |
| Joystick | X | 32 |
| Joystick | Y | 33 |
| Joystick | BUT | 35 |
Actually the code is very simple. Correct wiring without creating a short circuit is a bit more difficult in this example.
Source Code for example
joystick_displaySource Code for module
sh1106.py
Check your circuit and copy all files to the microcontroller.
# connect via rshel
(venv) $ rshell -p [SERIAL-PORT]
# copy all files to esp32
/your/current/path> cp lib/sh1106.py /pyboard/lib/
/your/current/path> cp examples/user_input/joystick_display.py /pyboard/main.py
# start repl
/your/current/path> replStart with keys Control + d or press reset key. To stop the loop press keys Control+ c, to leave the REPL, press keys Control + x.