Skip to content

MicroGemini brings the power of Google's Gemini AI to your ESP8266 microcontroller. This project demonstrates how to connect a resource-constrained device like the NodeMCU ESP8266 to Google's Gemini API, allowing you to ask questions through a serial monitor and receive AI-generated responses directly on your device.

Notifications You must be signed in to change notification settings

charan-271/MicroGemini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroGemini

A project that brings the power of Google's Gemini AI to your ESP8266 microcontroller. Ask questions through the serial monitor and get AI-generated responses directly on your device!

Overview

MicroGemini leverages the ESP8266 WiFi capabilities to connect to Google's Gemini API, allowing you to interact with a powerful AI model using minimal hardware. This project demonstrates how even resource-constrained devices can harness the power of cloud-based AI services.

Hardware Requirements

  • NodeMCU ESP8266 board
  • USB cable for power and communication
  • Computer with serial monitor capability

Software Requirements

  • PlatformIO (or Arduino IDE with proper ESP8266 support)
  • Libraries:
    • ESP8266WiFi
    • ESP8266HTTPClient
    • WiFiClientSecure
    • ArduinoJson (v7.4.1 or newer)

Setup Instructions

1. Get a Google Gemini API Key

  1. Visit the Google AI Studio
  2. Create or sign in to your Google account
  3. Create an API key from the "Get API Key" option

Generating an API Key

2. Configure Your Credentials

Create a credentials.h file in the include directory with the following content:

#ifndef CREDENTIALS_H
#define CREDENTIALS_H

// WiFi credentials
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"

// Google Gemini API key
#define API_KEY "your_gemini_api_key"

#endif

Replace:

  • your_wifi_ssid with your WiFi network name
  • your_wifi_password with your WiFi password
  • your_gemini_api_key with the API key you obtained from Google AI Studio

3. Build and Upload

  1. Open the project in PlatformIO
  2. Build the project
  3. Upload to your NodeMCU board
  4. Open the serial monitor (set to 115200 baud)

Terminal Response After Uploading

4. Ask Questions

  1. Type your question in the serial monitor and press Enter
  2. Wait for the Gemini API to process your question
  3. View the AI's response in the serial monitor

Question and Answer Example

How It Works

  1. The ESP8266 connects to your local WiFi network
  2. When you enter a question in the serial monitor, the device:
    • Formats your question into a JSON payload
    • Sends a secure HTTPS request to the Gemini API
    • Receives and parses the JSON response
    • Displays the AI-generated answer

Challenges and Solutions

Challenge 1: Memory Limitations

ESP8266 has limited RAM, which can cause issues when dealing with large JSON responses from the API.

Solution: Used ArduinoJson's dynamic memory allocation and efficient parsing to handle responses without overflowing the available memory.

Challenge 2: HTTPS Connection

The ESP8266 has limited HTTPS capabilities, making secure connections challenging.

Solution: Implemented a workaround using client.setInsecure() to establish connections to the API endpoint.

Challenge 3: API Response Parsing

Parsing complex JSON structures with nested objects and arrays required careful handling.

Solution: Leveraged the ArduinoJson library to elegantly navigate and extract the required information from the response.

Project Highlights

  • Minimal Hardware Requirements: Achieves AI interaction with just an ESP8266 board
  • Real-time Responses: Get answers to your questions in seconds
  • Energy Efficient: Low power consumption compared to running a full computer
  • Expandable: Can be integrated into other IoT projects
  • Educational: Demonstrates IoT, API integration, and AI concepts in a single project

Future Enhancements

  • Add support for multi-turn conversations
  • Implement a web interface for interaction
  • Add voice input/output capabilities
  • Optimize for battery-powered operation

License

This project is open source and available under the MIT License.


Created with ❤️ by Charan

About

MicroGemini brings the power of Google's Gemini AI to your ESP8266 microcontroller. This project demonstrates how to connect a resource-constrained device like the NodeMCU ESP8266 to Google's Gemini API, allowing you to ask questions through a serial monitor and receive AI-generated responses directly on your device.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published