-
1Working with Gemini
I first signed up on Google AI studio and got an API key. Then, I went through the documentation and wrote a simple python script to check how the API works.
I asked Gemini for the weather for my current location. The answer tells us two things. Firstly, the output is in JSON format, and we need to extract the text from this section (see below image). Secondly, Gemini does not have access to real time information, we cannot ask it the weather. If it could, it would save us some coding effort.
Anyway, to solve this issue, we fetch the weather from a different API called Openweathermap. I have explained how to set it up in a previous Project. Once we have the weather, we extract the temperature, humidity, and condition and send this over to Gemini.
-
2Prompt engineering
After cleaning things up a bit, I was getting some pretty good results.
But, we still have a few kinks to work out. First off, the answer is way too long to fit on our little OLED display. Secondly, Gemini's adding some extra sentences at the beginning that we don't really need. We just want that humorous sentence. And third, it doesn't quite sound like something TARS would say.
So, to fix this, let's go on a little side quest and do some prompt engineering. Basically, we need to be a bit more specific with Gemini about what we're looking for.
First, let's tell it to keep the answer between 50 and 60 characters. That'll be the perfect length to fit on our OLED display. Next, we'll instruct it to imagine it's a humorous AI and describe how the weather feels. Finally, we'll tell it to reply only with the humorous sentence and nothing else.
Here's how the prompt looks like: "You're a humorous AI robot. Describe this weather in a hilarious way. Your answer should be between 50 and 60 characters. Respond with only the humorous sentence and nothing else: {weather_data}"
-
3Making the body
So, to make TARS's body, I found an awesome template on Reddit. I simply downloaded it, scaled it up just enough to fit a standard 0.96-inch OLED display, and printed it out on some nice, glossy poster paper. You can find the template PDF attached below. Make sure to print it on A3 size paper.
Next, I carefully cut out the different sections from the template and also cut a rectangular hole where the OLED display is going to sit.
Then, using a screwdriver, I scored along the edges to make it easier to fold, and carefully folded the paper along those lines.
-
43d printing
In case you are planning to take the 3D printing route, you can download the STL file from services like thingiverse (here's one example: https://www.thingiverse.com/thing:567688) and either print it yourself or use an online 3D printing service like Justway.
First, head over to https://www.justway.com and select 3D printing. You also have options like CNC machining, injection Molding and Urethane Casting. But for this project, we will use the 3D printing service.
Click on "upload your design". A new page will appear. Here, you need to click on "Select CAD files" and upload the STL file.
After that, select the Quantity, Material (I recommend PLA or ABS for this project). In the color section, you can either select white and paint it later, or select the color you like directly in the 3D print. This will save time later.
Finally, after selecting all the options, you can enter your email and submit the request to get a quote.
Another way to do it is to use the resin 3D printing option. In this, you'll find surface finish options like Matt spray-painting, which will be perfect for this project. This will eliminate the rough finish of a standard PLA/ABS 3D printing.
This is a great option, especially for complex prints which might be tricky to print at home with low-end printers. Plus, you get options like surface finishing and resin 3D prints.
-
5Attach magnets
On the sections that go at the two ends, we need to glue some magnets. This is going to allow them to stick to the central sections and move around freely, just like TARS.
Similarly, we'll glue two metal discs to the central section so that the magnets on the ends can snap right into place.I actually salvaged these magnets and discs from a broken pair of earphones.
-
6Solder
Alright, now it's time to solder some wires to our D1 Mini and the OLED display. I'm using a dual-color display where the top few rows of pixels are yellow, and the rest are blue. I thought it would give it a unique look.
Here's how we'll make the connections:
- VCC on the display goes to the 5V pin on the D1 Mini.
- GND goes to GND
- SCL goes to D1
- SDA goes to D2
-
7Assemble
Alright, now we can tuck the display and the D1 Mini inside TARS' central section, fitting them into the cutouts we made earlier.
I also made a small hole on the back to feed a micro USB cable through, which will power the D1 Mini. The beauty of powering it directly with a cable is that we can easily reprogram the microcontroller later by simply plugging the other end into our computer.
Finally, I used glue to secure each section together. Now, thanks to those magnets, the two end pieces should snap right into place with a satisfying click!
-
8Code
I adapted my Python code to create an Arduino code that performs the same function. The code is designed to call the APIs every hour to stay up-to-date with the latest weather conditions. So, the text on the display should refresh every hour.
It's important to remember that the Gemini API has rate limits. To avoid hitting those, I've added a 30-second delay before the first API call. This way, we don't bombard the API with requests if the power keeps cutting out, for example.
-
9Conclusion
Now, plug the USB cable into a power source and let TARS make the most hilarious weather commentary!
I hope you enjoyed this project and are inspired to build your own, because it's actually a pretty straightforward build. If you have any ideas on how to improve it, I'd love to hear them, so feel free to leave a comment below!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.