Result. A second ESP32, straight out of the package (still running Espressif's 2017 factory firmware), now runs Asteroid Test: a Spacecavator-style asteroid on the Nextion, and a little yellow digger I steer with a joystick module, drilling through rock and collecting blue and red gems. Clicking the stick makes a new asteroid. It works insanely well.
Setup (Asteroid Test project, 400-hole breadboard). The ESP32's pins sit in rows a and i, so row j is the only free row, the same as on the LED board:
| From | To | ESP32 pin |
|---|---|---|
| j20 | joystick +5V | GPIO 25, set HIGH by the sketch (3.3 V) |
| j16 | joystick VRx | GPIO 34 |
| j17 | joystick VRy | GPIO 35 |
| j18 | joystick SW | GPIO 32 (internal pull-up) |
| j21 / j22 | Nextion RX / TX | GPIO 26 / 27 |
| j27 | Nextion 5V | VIN (USB 5 V) |
| j26 → − rail | joystick GND, Nextion GND | GND |
What I learned
1. The display's fonts don't survive turning it sideways. The Nextion Editor stores each font's letters pre-rotated for the orientation it compiles for. HASPone was compiled portrait, so after its orientation was flipped to landscape, the colour fills were fine but the text came out garbled. The fix: skip the fonts and draw letters as blocks with fill rectangles from the ESP32, a 5 × 7 pixel font. Everything on screen is now rectangles: letters, rock, gems, the digger. Turning the picture 180° for my stand is just mirroring each rectangle.
2. A joystick module is two potentiometers. Each axis is a 10 kΩ pot between +5V and GND, with the wiper on VRx or VRy, so the voltage follows the stick. Centred, mine read x = 1880, y = 1903 out of 4095, a bit under half (about 1.5 V), not the exact middle. That's why the sketch measures the centre at power-up (hands off!) and ignores small tilts around it.
3. Despite its "+5V" label, feed it 3.3 V on an ESP32. The wiper can reach whatever the supply is, and ESP32 analog pins read only up to 3.3 V. The 3V3 pin was covered by the board, so a GPIO set HIGH powers it instead. The two pots draw only about 0.7 mA, well within what a pin can supply.
4. Pick analog pins from ADC1 (GPIO 32–39). ADC2 stops working when Wi-Fi is on. GPIO 34 and 35 are input-only with no pull-ups, which is fine for VRx and VRy. The switch needs a pull-up, so it went on GPIO 32.
5. Every CP2102 board looks the same to the Mac. Both ESP32s show up as /dev/cu.usbserial-0001, because the USB chip reports the same serial number. I had to read the boot output to know which board was plugged in.
6. "Both directions reversed" wasn't the joystick. Left/right and up/down were both backwards, and the cause was the 180° screen flip: it mirrors the picture both ways, but the digger's movement hadn't been turned with it. Now the steering flips whenever the screen does.
7. Power-up order matters. When the ESP32 and the display power up together, the display is still booting and missed the one-time "switch to 115200 baud" command. The sketches now keep asking until the display answers.
Comments (0)