The Ultimate Thinking Cap
by jackmmaker in Circuits > Raspberry Pi
33 Views, 0 Favorites, 0 Comments
The Ultimate Thinking Cap



This project will show you how to code and build a hat with the power of locally run AI that helps you enhance your ideas. Not only is it usefule, it's fashionable (if you like cubes)! We will use Ollama to pull the AI model tinyllama, then use vosk and a python script to take voice input and feed it to the AI. Finally, pyttsx3 will speak out the AI's result. The original code I found was created by iotstation on github, but I have modified the code a heavy amount because the original code wasn't working for me.
Supplies
Electronics
1x Raspberry Pi and Raspberry Pi power cord
1x. MicroSD Card (16 GB and above)
1x Tiny USB Microphone (found here)
1x USB Speaker (found here)
3D Printed Parts (Designed in Tinkercad)
1x Cover.stl
1x Speaker Holder.stl
1x Bottom.stl
You will also need a string of some kind, preferably an elastic band.
Set Up the Pi

Download the Raspberry Pi Imager and open it. You will need to flash your Raspberry Pi with Raspberry Pi OS 64-bit. Put your microSD card in your computer then select it from the choose storage menu. Make sure to apply OS customization settings and edit them to include a password and your wifi network information. Click Next and then Write. Once it's done, put the microSD card in your raspberry pi.
Download the Code and Prerequisites

Once your RPI is plugged in, SSH into it using your terminal. Once you are in, run the command:
git clone https://github.com/jgame123/aionahat
Now we have to make a virtual environment. To do this, run the commands:
cd aionahat
python -m venv ai
source ai/bin/activate
Then create a folder called models using the command
mkdir models
For our AI to understand our voice, we need to download a vosk model. To do that, cd into the models directory then run the following commands:
wget https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
mv vosk-model-small-en-us-0.15.zip vosk-model-small-en-us.zip
unzip vosk-model-small-en-us-0.15.zip
rm vosk-model-small-en-us-0.15.zip
This will rename the vosk model then unzip the vosk zip and then delete the no longer needed zip. To install the rest of the prerequisites, cd back into the aionahat directory then run
pip install -r requirements.txt
sudo apt install espeak-ng libespeak1
That's all you need (except for the AI itself).
Create the AI

For our AI assistant we will be using Ollama, a tool that makes it unbelievably easy to run a number of AI models. First, install Ollama using the following command
curl -fsSL https://ollama.com/install.sh | sh
We will be using one of the smallest AI models because of our hardware limitations on the Rpi. One of these small models is called tinyllama. To install it run
ollama pull tinyllama
This will take a little bit, but once its done, the AI is up and ready to go. If you want to test it out, just run
ollama run tinyllama
This will open a chatbot in your terminal!
Make It Run on Start
We want our AI assistant to be ready as soon as we plug our hat in. To do this, we need to make a bash script then run it at system start. Make sure you are in the home directory, then start by making the script:
nano myscript.sh
Then you want to copy this text into the terminal:
#!/bin/bash
cd aionahat
source ai/bin/activate
python main.py
Then press control and x and the same time, then the y button, then enter. This will save it, but to make it executable run this:
chmod +x myscript.sh
Now lets make this script run at system start up. To do this, type
sudo nano /home/pi/.bashrc
Next, use the down arrow key to scroll all the way to the bottom of the file. Press enter a few times then type
/home/pi/myscript.sh
Finally, press control and x together, then y, then enter to save it. Now let's begin building the hat! Run the following command to shut down the Pi, then unplug it.
sudo shutdown now
Assemble the Hat


Begin by plugging in the speaker and microphone, then placing the Raspberry Pi into the holder. The USB ports will line up with the front, and the power port will line up with the hole on the side. Apply glue to the sides of the cover, then place it over the Raspberry Pi. It will fit snuggly, and once the glue dries it will be pretty stable. Take the speaker holder and glue it onto the top of the cover. Make sure that the slit for the cord is facing the USB ports. Once the glue is dry, take the Raspberry Pi power cord (make sure it's unplugged) and put it through the hole in the cover and into the Raspberry Pi. Next, place the speaker onto the box, letting the cord rest on the slit. You might need to wind the cord around the box a couple times for a tight fit. Finally, take your string and feed it through the two slots on either side of the Raspberry Pi holder and tie them in place.
Power Up the Hat!

Put on the hat and plug it in! The hat will ask you for a prompt, then you can ask it whatever you want. Let your imagination loose, and you ideas flow with the help of the ultimate thinking cap!