---
title: "Chatting with chatGPT on WIZnet Pico Board using MicroPython"
url: "https://maker.wiznet.io/scarlet/projects/chatting-with-chatgpt-on-wiznet-pico-board-using-micropython/"
markdown_url: "https://maker.wiznet.io/scarlet/projects/chatting-with-chatgpt-on-wiznet-pico-board-using-micropython/md"
type: "WCC: WIZnet Created Content"
author: "scarlet"
original_author: "scarlet"
published: "2023-04-20"
language: "en"
tags: ["AIoT"]
hardware: ["Raspberry Pi RP2040", "WIZnet W5100S-EVB-Pico", "WIZnet W5500-EVB-Pico"]
likes: 8
views: 1305
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Chatting with chatGPT on WIZnet Pico Board using MicroPython

> Chatting with openAI on WIZnet Pico Board using MicroPython. send prompt message or communication with the chatGPT model.

Original author: scarlet

## Components

- **Raspberry Pi RP2040** x 1 ([docs](https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html))
- **WIZnet W5100S-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S/w5100s-evb-pico))
- **WIZnet W5500-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/w5500-evb-pico))
- Software: **MicroPython** ([docs](http://micropython.org/))

## Documents and links

- [git](https://github.com/scarletwiz/RP2040-OpenAI-Micropython) (code)

## Article

**How to Use RP2040 OpenAI Example**

![](https://github.com/scarletwiz/RP2040-OpenAI-Micropython/raw/main/static/images/cover_image.png)

!! You can check out the code and details of this project on the site below

<https://github.com/scarletwiz/RP2040-OpenAI-Micropython>

![](https://maker.wiznet.io/upload/ckeditor5/257865589%5F1682092384%2Egif)

**Step 1: Prepare Software**

The following Python IDE program is required for test, download and install from below links.

> [**Thonny**](https://thonny.org/)

Deploying firmware to the device. you can use the below firmware.

> [**FW for RP2040_OpenAI_Micropython**](https://github.com/scarletwiz/RP2040-OpenAI-Micropython/releases/tag/uf2_ver_1)

If you need a detailed explanation of firmware and Thonny setup, please refer to the video below.

> [**Raspberry Pi Pico MicroPython Guide**](https://www.youtube.com/watch?v=8FcFhZRNNxE)

**Step 2: Prepare hardware**

Combine WIZnet Ethernet HAT with Raspberry Pi Pico.

Connect ethernet cable to Ethernet HAT ethernet port.

Connect Raspberry Pi Pico to desktop or laptop using 5 pin micro USB cable.

If you use W5100S-EVB-Pico, you can skip '1. Combine...'

**Step 3: Setup Example**

To test the **Open AI example**, minor settings shall be done in code.

Check COMport in **Device Manager** and then open **Thonny** Python IDE.

![](https://github.com/Wiznet/RP2040-HAT-MicroPython/raw/main/static/images/HTTP/Thonny_conf_1.png)

Setup SPI and Reset pin in **chat_with_openai.py** or **send_prompt.py** file.

If you are not using the WIZnet PICO Board, please adjust the SPI pin configuration according to your hardware setup.

```plaintext
spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
```

Enter OpenAI information(version, API key) into the **chatGPT.py** file.

> If you have not generated an API key, please generate one on the following site <https://platform.openai.com/account/api-keys>

```plaintext
api_key = "insert your API-KEY"
    chatgpt_url = "https://api.openai.com/v1/chat/completions"
    chatgpt_ver= "gpt-3.5-turbo"
```

**Step 4: Upload and Run1. send prompt to openAI**

![](https://github.com/scarletwiz/RP2040-OpenAI-Micropython/raw/main/static/images/send_prompt.png)

The function **'send_prompt_to_chatGPT'** sends the prompt to openAI and receives a response from the model. If the response is successful, the generated text is printed serial program.

Enter the prompt as a parameter for the **[send_prompt_to_chatGPT]** function.

```plaintext
send_prompt_to_chatGPT("Hello")
```

**2. chat with openAI**

![](https://github.com/scarletwiz/RP2040-OpenAI-Micropython/raw/main/static/images/chat_with_openAI.png)

The function **'chat_with_chatGPT'** enables communication with the chatGPT model using the OpenAI API via a serial program. It user enter a message and sends it to OpenAI as a prompt, then prints the response.

The default exit command is **">exit"**. To modify the exit command, please modify the relevant section in the **chatGPT.py** file.

```plaintext
end_command= ">exit"
```

---

Source: https://maker.wiznet.io/scarlet/projects/chatting-with-chatgpt-on-wiznet-pico-board-using-micropython/
