AI Storyteller with Raspberry Pi

Build Your Own AI Storyteller with a Raspberry Pi

Remember the magic of bedtime stories? What if you could build a device that generates unique, new stories for your kids with just the tap of a card? In this project, we’ll show you how to create your very own AI-powered Storyteller using a Raspberry Pi, an RFID reader, and a bit of Python magic.

This device lets children choose the heroes of their next adventure by placing RFID cards—each representing an animal—onto a reader. A locally-run AI then crafts a unique, child-friendly story featuring the selected animals, which instantly appears in a simple web interface. It’s a wonderful blend of tangible interaction and creative technology.

How the Storyteller Works

The concept is simple and intuitive, making it perfect for kids:

  1. Pick an Animal: The child selects one or more cards, each with an animal sticker on it.
  2. Tap the Reader: They place the cards on the RFID reader. The Storyteller recognizes the animals.
  3. Watch the Lights: A ring of LEDs starts to glow, showing that the AI is “thinking” and crafting a new tale.
  4. Read the Story: A few seconds later, a brand-new story featuring the chosen animals appears on the screen of a tablet, phone, ore computer.

The Technology in Detail

The AI-Storyteller is an interplay of several components:

  • Raspberry Pi 5: The Heart of the Project The Raspberry Pi 5 serves as the brain of the entire system. It processes inputs from the RFID reader, controls the LED ring, let’s the AI generate stories, and hosts the web server through which the stories are presented.
  • RC522 RFID Reader: The Magical Animal Cards The RFID reader is the interface between the physical animal card and the digital world of the Raspberry Pi. When an RFID card, adorned with an animal sticker, is held up to the reader, it reads a unique identifier (UID). Communication between the reader and the Raspberry Pi takes place via the SPI interface.
  • Ollama and Gemma: The AI that Writes Stories Once one or more animal cards are recognized, the most exciting part begins: Artificial intelligence generates a story. We use Ollama, a platform that allows large language models to be run locally on the Raspberry Pi. The model used is gemma3:1b.
  • LED Ring: Visual Feedback An LED ring provides visual feedback. When a card is detected, it briefly lights up. While the AI generates the story, a “thinking animation” indicates that something is in progress. Upon success, the ring lights up green; in case of an error, it turns red.
  • Flask Webserver: The Interface for Reading and Managing All generated stories and card management are handled via a simple yet effective web interface built with Flask. index.html displays the current story, while manage.html allows new RFID cards to be linked with animal names or existing assignments to be deleted. The website automatically updates to show the current card selection status and the generated story.

The Hardware

You’ll need a few common electronics components:

  • A Raspberry Pi 5 with 8GB or 16GB RAM
  • An RC522 RFID Reader module
  • A NeoPixel LED Ring (with 12 LEDs)
  • Jumper wires
  • Several RFID Cards
  • Animal stickers that you can apply to the cards
  • (optional, but recommended) An enclosure for the hardware. We used a simple night light.

The Wiring

Connect the components to your Raspberry Pi’s GPIO pins as shown below.

How to setup and wire the AI Storyteller with the Raspberry Pi, RC522 module, and NeoPixel

How to connect the RC522 RFID Reader

RC522Raspberry Pi PinGPIO
SDA248
MOSI1910
SCK2311
MISO219
RST2225
GNDAny GND Pin
3.3VAny 3.3 Pin

How to connect the NeoPixel LED Ring

NeoPixelRaspberry Pi PinGPIO
Data In (DI)19 (use the RC522’s MOSI Pin)10
VCC / 5VAny 5V Pin
GNDAny GND Pin

After putting all parts together your project might look like this. Here the bottom of the enclosure is already installed.

The parts of the AI storyteller wired together

A library for the RC522 RFID Reader

To enable the RC522 to communicate with the Raspberry Pi 5, you need a library. Unfortunately, the MFRC522 library does not work with the Pi 5 model, which is why we have developed our own. You can find it for download, along with further information about the library, in this tutorial or further down here together with the other project files.

The Software Setup

To get the AI Storyteller up and running, only a few steps are necessary. For this, you can connect your Raspberry Pi to a monitor and execute the commands in a terminal. Alternatively, you can connect to your Raspberry Pi via SSH and execute them remotely.

Step 1: Enable SPI

If you haven’t already, enable the SPI interface on your Raspberry Pi:

sudo raspi-config 

Navigate to 3 Interface Options -> I4 SPI and enable the interface.

Step 2: Install Software Dependencies

Update System and Install Core Libraries:

sudo apt update
sudo apt upgrade -y
sudo apt install python3-spidev python3-libgpiod python3-venv -y 

python3-spidev and python3-libgpiod are essential for SPI communication and GPIO control on the Raspberry Pi 5. python3-venv is needed for virtual environments.

Set up Ollama and Download Model:

The project uses Ollama to run the Gemma AI model.

Install Ollama: Follow the official Ollama installation instructions for ARM64 on Linux. Typically, it’s a single command:

curl -fsSL https://ollama.com/install.sh | sh

Download the Gemma Model: After installing Ollama, download the gemma3:1b model that the storyteller script uses:

ollama pull gemma3:1b 

Step 3: Download and Place Project Files & Set up Virtual Environment

Create a Project Directory:

mkdir raspi_storytellercd raspi_storyteller

___STEADY_PAYWALL___

Download Project Files: You need to download the project files and place them into this raspi_storyteller directory:

Create and Activate a Python Virtual Environment: It’s good practice to install Python dependencies in a virtual environment to avoid conflicts with system-wide packages.

python3 -m venv venvsource venv/bin/activate

You’ll see (venv) prepended to your terminal prompt, indicating the virtual environment is active.

Install Python Dependencies from requirements.txt: With your virtual environment activated, install the required Python libraries:

pip install -r requirements.txt 

This will install flask, pi5neo, ollama, gpiod, and spidev into your virtual environment.

Step 4: Run the Raspi Storyteller

Start the Storyteller Script: Ensure your virtual environment is still active (you should see (venv) in your prompt). In your raspi_storyteller directory, run the main Python script:

python3 raspi-storyteller.py 

This will start the Flask web server on port 5000 and the RFID reading loop.

Find Your Raspberry Pi’s IP Address : Before accessing the web interface, you’ll need the IP address of your Raspberry Pi. You can find this by opening a new terminal window (don’t close the one running the storyteller script) and typing:

hostname -I 

This command will usually output your Pi’s IP address.

Access the Web Interface: Open a web browser on a device connected to the same network as your Raspberry Pi.

To manage cards: Go to http://<YOUR_RASPI_IP_ADDRESS>:5000/manage

Hold an unknown RFID card to the reader. Its UID will appear in the “Card UID” field on the webpage.

Enter an animal name (e.g., “a brave lion” or “a curious squirrel”) and click “Save Card” to link the UID to the animal.

To generate stories: Go to http://<YOUR_RASPI_IP_ADDRESS>:5000/

Hold one or more of your registered animal cards to the reader. After a short delay (determined in the script), a story featuring these animals will appear on the page:

The Story is visible on a website

We don't track you. No ads, no unnecessary cookies, no Facebook pixel stuff. Consider becoming a member instead to support Pollux Labs.