You are on page 1of 17

DESKTOP BOT

Why A ChatGPT Terminal?


Our Friend Arduino
ChatGPT Terminal Operation In A Nutshell
Major Components For The ChatGPT Terminal
Microcontroller Dev Board
PS/2 Keyboard
OLED
Other Stuff
Laser Engraved Enclosure
The Connections
ChatGPT Terminal Code
A Full Walk Through Of This ChatGPT Terminal
ChatGPT Terminal Resources
CODE
Website
https://www.programmingelectronics.com/chatGPT-terminal?
utm_source=youtube&utm_medium=description&utm_campaign=video&utm_content=ch
atGPT+in+your+Arduino+project%3F!
Compounds required
DESKTOP BOT

Get 10 tips every new Arduino coder should know ➜

Can you integrate the power of a chatGPT terminal into your


own Arduino projects?

I don’t mean using chatGPT to help write your code, I mean


incorporating the textual responses from chatGPT to do
something for your project.

The answer is a bold yes!

What it will look like depends a lot on what you’re trying to


achieve.

In this exploratory project you’ll interface an Arduino


compatible wireless ESP32 with the OpenAI API and create
a standalone “retro” chatGPT terminal using a keyboard as
the input device and an OLED as the display.

This is really just the starting point.

Once you understand how to access and parse the chatGPT


API from a wireless microcontroller you open up a ton of
new and unexplored possibilities. From autonomously
intelligent control of hardware to next level human interface
devices.
DESKTOP BOT

What we are doing here is pulling the power of AI out of the


cloud and figuring out how to substantiate it.

Hardware is eating AI, and you’re the chef.

Why A ChatGPT Terminal?

The truth is, millions (if not billions) of dollars is going to be


generated by embedding intelligence into hardware
devices. There is an enormous financial incentive for
pushing AI to the edge.
DESKTOP BOT

But how it all plays out remains to be seen, and what ends
up actually being useful and solving problems that people
are willing to pay for – it’s anybody’s guess.

What is starting to happen on a huge scale at this very


moment is the prototyping of AI edge applications.

We all see the hint of immense usefulness in these large


language models like chatGPT, but how can we bring them
to bear in the physical world?

So we could all sit back in an armchair and come up with


some conceptual ideas about how this technology could be
useful.

Or we could take a more practical approach, and just try


things. By trying different things, we can gain insight into
what sounds like a great idea, and what actually has some
traction.

What you need now is a way to get started pronto and try as
much as you can.

This chatGPT terminal can be your first stab in the dark.

Our Friend Arduino


DESKTOP BOT

What better way is there to try things fast and cheap than
digging into the Arduino treasure trove?

Arduino has a huge ecosystem of developers, tons of


inexpensive interoperable hardware, and arguably the most
extensive open source code base for working with external
hardware than any other development board in the known
universe.

It’s a prototyper’s dream. PLUS it’s just not that hard to


work with compared to many other options. So even if
you’re a novice programmer, you can get up and running
pretty quickly especially if you invest in some good training
(shameless plug 😉).

The Arduino ecosystem is the place to start.


DESKTOP BOT

ChatGPT Terminal Operation In A Nutshell

Here is a quick outline of this simple chatGPT Terminal.

1. You type your chat on an old school keyboard


2. An Arduino compatible ESP32 records your
keypresses and sends a POST request to the OpenAI
API
3. When the response comes back, you show the text on
an OLED.
4. Repeat.

Pretty straight forward!

Now I am SURE you’re thinking – why not didn’t make this


voice-to-text input and text-to-audio output – like a mini
Alexa?

I can assure you that it is something I considered, and


something I plan to explore more.

But this project is an exploration of interfacing with the


chatGPT API then figuring out how to make something that
understands me better than Alexa.

Using an external keyboard turned out to be a really easy


way to input text that my code could easily parse.
DESKTOP BOT

An additional benefit of the keyboard is that everybody


knows how to use one, so when it’s laying out, people
assume they can type into it.

Major Components For The ChatGPT Terminal

There are 3 major components you’ll need for this project:

1. Microcontroller Dev Board


2. PS/2 Keyboard
3. OLED

Microcontroller Dev Board

For this project we’ll use the FeatherS2 – ESP32-S2 by


Unexpected Maker as the brains of the project.

The ESP32 is a WiFi (and bluetooth) enabled


microcontroller, and they have tons of great development
boards for them.
DESKTOP BOT

You definitely don’t need this exact model, any ESP32 (or
ESP8266) would probably work just fine.

PS/2 Keyboard

You’ll also need a PS/2 style keyboard – these are old


school keyboards that have what is not a very outdated
connector type. The reason I went with this style keyboard
is because the software to read the incoming keypresses is
simple to implement and available in multiple different
Arduino libraries.
DESKTOP BOT

OLED

Finally you’ll need an OLED display to show the text in


stunning 8 kilo-pixel resolution! OK, maybe not the most
high resolution screen you could dream up, but these 128 x
64 px displays are everywhere.

You can use different display sizes as long as the pixel ratio
stays the same, otherwise you’ll need to adjust the code.
I’ve used 0.94”, 1.3”, and 2.42” OLED displays.

Other Stuff

Check the bottom of this post for a link to the full Bill of
Materials (BOM) which includes all the stuff you’ll need,
plus some tools you may want.

We’ll do a more thorough walk through of the Bill of


Materials (BOM) in the later lessons.
DESKTOP BOT

Laser Engraved Enclosure

To make the enclosure I used a 40W Monport Laser


Engraver to cut and engrave the enclosure from sheets of
bamboo.

It’s a great desktop engraver, and I was surprised how easy


it was to get up and running. They packaged the thing
great, and it arrived pretty much fully assembled.

The monport laser came ready to use with Lightburn, a


software for operating laser engravers. I’d never used it
before, but it was relatively straightforward.

It is nice to have a “Laser” to use now. (If you want to get


one of these, you can save 6% by using code Academy6
when you check out).
DESKTOP BOT

The Connections

This wiring diagram lays out the connections you’ll need


between the major components of your chatGPT terminal.
This shows using an I2C OLED display, you’ll need to
change up the connections for using SPI.

Function ESP32 GPIO For FeatherS2


Used Chip Pin # Number Peripheral Silk Screen
Marking

I2C – 14 IO9 / OLED – I2C SCL


SCL D11 (SCL)

I2C – 13 IO8 / OLED – I2C SDA


SDA D10 (SDA)

SPI – 40 IO36 / OLED – SPI SCK


SCLK D25 – (SCK)
DESKTOP BOT

SPI – 39 IO35 / OLED – SPI SDO


MOSI D24 – (SDA)

SPI – SS 37 IO33 / OLED – SPI 33


D20 – (CS)

SPI – 42 IO38 / OLED – SPI 38


DC D21 – (DC)

GPIO 11 IO6 / Keyboard 6


D18

Interrupt 10 IO5 / Keyboard 5


D19

For the above pins, keep in mind if you plan on using I2C
with the OLED then you only need 2 pins, whereas if you use
SPI, you’ll need 4. The SPI labeling may be a bit wonky,
because the OLED graphic driver implemented a non
standard SPI protocol.

If you’d like a more in-depth walk through of assembly, we


have a full walk through of this project in our training
program.

ChatGPT Terminal Code

The code flow for this system is not too complicated.


DESKTOP BOT

Basically, the system is always waiting for keyboard input.


If the keyboard input is part of a chat message, it saves it to
a special message array. If it’s a command key, like SHIFT,
or ENTER, then it take the appropriate action.

When a message is submitted by the user, an API call is


made to the chatGPT API to get a response.

The response is then parsed by the code, and the pertinent


information saved to the messages array.

Finally, it’s displayed on the OLED one word at a time


(mimicking the web chatGPT interface), where the user can
then use the up and down arrows to scroll through the
response.
DESKTOP BOT

And that’s pretty much a full cycle. Read keypresses, hit


API, display response.

There is also a way to inject system messages (learn more


about the system role here) that help steer the response
from chatGPT. The default system message is “Respond
like a pirate”. To change the system message you press
escape and you’ll be prompted to type a new one.

In order to link up the code with your WiFi and OpenAI API
Secret Key, you’ll need to make fill in your info on the
credentials.h file.

The full code for this project is below. If you’d like more
details of the program’s structure we have a full walk
through of this project in our training program.

The major libraries use are the:

● WiFi – for connecting the ESP32 to the internet


● WiFiClientSecure – for making a secure connection to
the OpenAI server
● U8g2lib – Universal Graphics Library for using the
OLED
● ArduinoJson – for handling JSON formatting for API
calls
● PS2KeyAdvanced – for handling keyboard input
● PS2KeyMap – for handling more details of keyboard
input
DESKTOP BOT

A Full Walk Through Of This ChatGPT Terminal

I think there should be more than enough information above


to help you build your own chatGPT Terminal.

That being said, if you would like a more in-depth walk


through of the Bill of Materials, a step-by-step instruction of
wiring the project, and a high level understanding the code
flow, then we offer a full walk through of this chatGPT
Terminal project in our training program you can check out
here >>

ChatGPT Terminal Resources

CODE

● Code

tROUBLE SHOOT LCD

https://youtu.be/oUuYSU2e3rk

Code 1.0

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
DESKTOP BOT

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to


0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
//lcd.setCursor(3,0);
lcd.print("16:36");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}

void loop()
{
}
DESKTOP BOT

Website

https://www.programmingelectronics.com/chatGPT-terminal?
utm_source=youtube&utm_medium=description&utm_campaign=video&
utm_content=chatGPT+in+your+Arduino+project%3F!

VIDEO URL
chatGPT in your Arduino project?!

Compounds required
1. Microcontroller Development Board:
a. ESP32 or ESP8266 development board (e.g., FeatherS2, NodeMCU, etc.)
2. PS/2 Keyboard:
a. PS/2 style keyboard for user input(change into speech recognition)
3. OLED Display:
a. OLED display module (128x64 resolution) for displaying the AI-generated
responses
4. Wires and Breadboard:
a. Jumper wires for connecting components
b. Breadboard for prototyping
5. Power Supply:
a. USB cable or appropriate power supply for the development board

Speech recognition

You might also like