Image
Taisuke Kodama
Taisuke Kodama
Staff Application Engineer
Published: October 31, 2023

This blog introduces how to do AI coding using ChatGPT and the RL78 Arduino-compatible board, along with its practical examples.

Background Knowledge

What is ChatGPT?

ChatGPT is an AI tool developed by OpenAI that can understand user input text or questions based on pre-trained text information and produce answers. However, it doesn't always generate accurate content, so users need to be aware of this when using it.

What is Arduino?

Arduino is an open-source platform for easily conducting electronic projects. It consists of a board equipped with a microcontroller (Arduino board) and a software development environment (Arduino IDE). As of September 2023, with RL78 products, software can be developed for the following boards using the Arduino IDE.

  • RL78/G24 Fast Prototyping Board
  • RL78/G23-64p Fast Prototyping Board
  • RL78/G22 Fast Prototyping Board
  • RL78/G16 Fast Prototyping Board
  • RL78/G15 Fast Prototyping Board

Information for supporting boards:
Home · renesas/Arduino Wiki · GitHub

Trying Out AI Coding

For this demonstration, I used the RL78/G23-64p Fast Prototyping Board to generate a program with ChatGPT that blinks an LED. I will explain the actual process from Step 1 to Step 5.

STEP 1. Environment Setup

Prepare the RL78/G23-64p Fast Prototyping Board (RL78/G23-64p FPB). Connect the board to your PC using a Micro USB Type-B cable.

Image
RL78/G23-64p Fast Prototyping Board (RL78/G23-64p FPB)

Install the Arduino IDE on your PC. After installation, install the package for RL78/G23-64p FPB from the board manager.

Install Guide:
Quick Start Guide · renesas/Arduino Wiki · GitHub

Step 2. Input Circuit Information to ChatGPT

For the program we're creating, we'll use the onboard LED (User LEDs).

Image

Use the information from the link below to input the LED pin information and control signal information into ChatGPT.

Reference for PIN information:
RL78G23 64pin Fast Prototyping Board · renesas/Arduino Wiki · GitHub

 
Example of input prompt:
Arduino Board Specifications:
The board features two LEDs (LED1, LED2).
The LEDs are pulled up with resistors, and the cathode side is connected to the pin.
Name pin memo
LED1 16 -
LED2 15 -
 

STEP 3. Input Coding Specifications to ChatGPT

I requested ChatGPT to write a program that blinks LED1 and LED2 every second.

 
Example of input prompt:
Software Specifications:
LED1 and LED2 should toggle ON and OFF every second.
The initial state of LED1 is ON, and the initial state of LED2 is OFF.
 

STEP 4. Execute ChatGPT's Output Program

Create a new sketch in the Arduino IDE, copy and paste the program output by ChatGPT, then run Verify and Upload.

For detailed operation and execution procedures of Arduino IDE, please refer to:
Quick Start Guide · renesas/Arduino Wiki · GitHub
Home · renesas/Arduino Wiki · GitHub

STEP 5. Verification and Revision

This time, the program was output as expected in both gpt-3.5 and gpt-4. If the program doesn't operate as expected, request a revision from ChatGPT. Make an effort to input concise and clear information. Moreover, there's a tendency for gpt-4 to produce more expected results than gpt-3.5.

Image

Conclusion

Although the theme was simple this time, I succeeded in generating the targeted code using ChatGPT. I would like to challenge even more advanced themes in the future. For those of you who are interested, why not try AI coding for yourself?

Appendix

 
Full text of Input Prompt to ChatGPT:
Request for Arduino Program Creation
Arduino Board Specifications:
The board features two LEDs (LED1, LED2).
The LEDs are pulled up with resistors, and the cathode side is connected to the pin.
Name pin memo
LED1 16 -
LED2 15 -

Software Specifications:
LED1 and LED2 should toggle ON and OFF every second.
The initial state of LED1 is ON, and the initial state of LED2 is OFF.
 

General caution for ChatGPT Generated Codes:
Before utilizing generated codes, certain screening processes would be recommended because those codes may possibly infringe on third-party intellectual property rights or contain malware fragments as well as deriving other unwanted outcomes.

Share this news on