Shunlongwei Co. ltd.

IGBT Module / LCD Display Distributor

Customer Service
+86-755-8273 2562

AI Coding with Chat-GPT for RL78 Microcontroller (Arduino)

Posted on: 11/28/2023

In this blog, I will introduce how to do AI coding using Chat-GPT and the RL78 Arduino-compatible board, along with its practical examples.

Background knowledge

What is Chat-GPT?

Chat-GPT 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 ‘23, 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 Chat-GPT 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 Gude:
Quick Start Guide · renesas/Arduino Wiki · GitHub

Step 2. Input circuit information to Chat-GPT

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 Chat-GPT.

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 Chat-GPT

I requested Chat-GPT 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 Chat-GPT’s output program

Create a new sketch in the Arduino IDE, copy & paste the program output by Chat-GPT, 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 Chat-GPT. 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 to generate the targeted code using Chat-GPT. 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 Chat-GPT:
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 utilize generated codes, certain screening processes would be recommended because those codes may possibly infringe third-party intellectual property rights or contain malware fragments as well as deriving other unwanted outcomes.