You can turn a Seeed Studio XIAO ESP32C3 into a handheld text adventure console that sends your typed commands to Google Gemini and prints the story back on a small display, because the board has Wi-Fi built in, enough flash for a sketch, and a USB-C port that handles both power and serial input. Nothing you do here is plug-and-play: you write a small program that talks to the Gemini API, wire up a display and buttons, store your own API key, and add a serial or on-screen input method. The shortest working path is board plus USB cable plus an Arduino sketch that sends your command to the Gemini model and shows the reply on the Serial Monitor first, then on a screen once that works.
What You'll Need
- A Seeed Studio XIAO ESP32C3 board and a USB-C data cable (many charge-only cables will not enumerate the serial port).
- A computer with the Arduino IDE 2.x or the Arduino CLI, plus the ESP32 board package installed.
- A Google AI Studio account with a Gemini API key issued for your own project.
- A 2.4 GHz Wi-Fi network with the SSID and password. The ESP32C3 is a 2.4 GHz-only radio, so a 5 GHz-only network will not work.
- Optional but expected for a real handheld: a small I2C OLED (SSD1306) or a TFT display, a few tactile buttons, and a breadboard with jumper wires.
- A note of your board's pinout from Seeed's wiki, because the XIAO footprint labels pins differently from a full-size ESP32 dev board.
Step-by-Step
- Install the board support. Open the Arduino IDE, go to the Boards Manager, search for the ESP32 package by Espressif and install it. In the board selector choose the XIAO ESP32C3 entry. If it is missing, the package version is too old; update it.
- Confirm the board talks to your PC. Plug in the board, open Tools > Port and pick the new port that appears. If no port appears, try another cable and another USB port before touching anything else. Upload the stock Blink sketch to prove the toolchain works.
- Put your credentials in one place. Create a small header file in the sketch folder (for example
secrets.h) holding your Wi-Fi SSID, Wi-Fi password and Gemini API key as string constants. Keep this file out of any public repository. Never hard-code the key into a sketch you share. - Connect to Wi-Fi first. Write a sketch that joins the network and prints the assigned IP address to the Serial Monitor at 115200 baud. Do not add the API call until this prints an address. This isolated step saves you from debugging two problems at once.
- Make one HTTPS request to Gemini. Use the board's secure Wi-Fi client to POST to the Gemini model endpoint, with your key passed as a query parameter and a JSON body containing a contents array with a single user part holding your text. This is the same request shape the REST documentation shows for a plain text prompt. Print the entire response to the Serial Monitor, including the HTTP status code.
- Parse only the text field you need. The reply arrives as JSON with a candidates array; the story text sits inside the first candidate's content parts. Extract that string rather than printing the whole payload. Keep the raw response printed too while you are developing, so a parsing failure is obvious.
- Keep a running story. A text adventure only works if the model remembers the room you are in. Append each player command and each model reply to a conversation history array and send the whole array with every request. Cap the history length, or trim the oldest turns, so the payload does not grow without limit and slow the board down.
- Write a system instruction. Send a system instruction that sets the role: you are the narrator of a text adventure, respond in short second-person paragraphs, describe the scene and end by asking what the player does, never break character. Without this, Gemini answers like a chatbot and the game feel disappears.
- Add input. For a first version, read a line from the Serial Monitor as the player's command. For a handheld, wire two or three buttons to free GPIO pins and build a simple command picker (look, go north, take item, talk) so you are not typing on a device with no keyboard.
- Add the display. Wire an I2C OLED to the board's I2C pins and print the narrator's text with word wrapping. Long replies will not fit on a small screen, so either request shorter responses in the system instruction or split the reply across pages with a button press to advance.
- Handle errors visibly. Check the HTTP status before parsing. On a non-200 response, print the status and a short error tag to the display instead of crashing or showing a blank screen. Add a timeout so a dropped Wi-Fi connection does not freeze the loop forever.
- Package it. Move the sketch into a small enclosure, power it from a USB power bank or a regulated supply, and label the buttons. Test it away from your desk on the same Wi-Fi network before you call it finished.
Common Mistakes
The most frequent failure is a 5 GHz network. The ESP32C3 radio is 2.4 GHz only, and the board will simply never associate. Second is a charge-only USB cable, which powers the board but produces no serial port. Third is committing the API key to a public repository, where it will be scraped and abused; treat the key like a password.
On the software side, people often forget the conversation history and then wonder why the narrator forgets the room after two turns, or they send the entire JSON response to the display and get a wall of braces. Others skip the system instruction and get a polite assistant instead of a game master. Finally, sending an unbounded history will eventually produce requests large enough to time out or be rejected; trim old turns.
Tips
Build in layers: Wi-Fi, then one API call, then parsing, then the display, then buttons. Each layer should be provably working before you add the next. Ask the model for a fixed response style in the system instruction, including a maximum length, so the display layout stays predictable. Cache the last scene on the board so a momentary Wi-Fi drop does not wipe the screen. Log every request and response to the Serial Monitor during development and keep the log on while you first playtest.
Keep the API key in a separate header, rotate it if it is ever exposed, and review your usage in Google AI Studio if you are on a metered plan. Test the finished device on the network you will actually use it on, not just your desk router.
Troubleshooting
No serial port appears. Change the cable first, then the USB port, then try holding the boot button while plugging in. Reinstall the ESP32 board package if the port shows but uploads fail.
Wi-Fi never connects. Confirm the SSID is 2.4 GHz and that the password has no stray spaces. Move closer to the access point; enterprise or captive-portal networks usually will not work.
Requests fail with an authentication error. The key is wrong, revoked, or the API is not enabled for that project. Generate a fresh key in Google AI Studio and retest with a single short prompt before touching the rest of the sketch.
Requests fail with a quota or rate error. You are sending too many calls too quickly, often because the loop retries without delay. Add a pause between requests and avoid resending on every button bounce.
You get a response but no text on screen. Parsing is failing. Print the raw body to the Serial Monitor and inspect the structure; the reply may be truncated or the field path may be wrong.
The board resets randomly. Power is the likely cause. Use a supply that can deliver stable current and avoid long thin jumper wires on the power rails.
Frequently Asked Questions
Can the XIAO ESP32C3 call Gemini directly without a server?
Yes. The board makes HTTPS requests over its own Wi-Fi connection, so no separate computer is needed at play time. The API key lives on the device, which is why you should keep the sketch private.
Does this work on a 5 GHz network?
No. The radio is 2.4 GHz only. Use a 2.4 GHz SSID or a router that offers both bands under separate names.
How do I give the player a keyboard?
You do not need one. Read commands from the Serial Monitor over USB, or use a small set of buttons that pick from common actions. A Bluetooth keyboard is not part of the standard setup.
Why does the story forget earlier events?
The model only sees what you send. Keep a history array of prior commands and replies and include it in each request, trimming the oldest entries to control size.
Can I use an OpenAI-compatible endpoint instead?
That depends entirely on whether the endpoint accepts the request format your sketch sends. This guide is written around Gemini's own API shape, so switching providers means rewriting the request and parsing code.