Information Technology & Programming

Let’s use Codeium for Arduino development!

Toon Robotics is supported by its audience. When you purchase through links on my site, I may earn an affiliate commision.

AI Coding Assistant Tools

Many AI tools have been released recently, and one of them is an AI tool for automatic source code completion during programming.

While regular interactive AIs such as ChatGPT are sufficient for simply outputting programs, the advantage of coding assistant AIs is that they are specialized for programming and can be integrated with the development environment that is usually used.

The most famous of these coding assistant AI is probably GitHub Copilot.

Recently, there are coding assistant AIs that can be run in a local environment, such as Meta’s Code Llama, but they require high computer performance and are complicated to manage, making them inconvenient. For this reason, GitHub Copilot, which is developed as a service, is advantageous in terms of convenience.

However, GitHub Copilot is subscription-based, so it is not easy to try. Thus, I will try Codeium, a free coding assistant AI tool for individuals.

I will also examine whether this coding assistant AI can be used in embedded and IoT device development such as Arduino.

Assumed development environment

This section describes the development environment assumed in this article. I will use Codeium as the coding assistant AI (Codeium is described below). As an Arduino development environment, I will use PlatformIO on Visual Studio Code to work with Codeium.

View Arduino on eBay

Codeium and its supported languages

What is Codeium?

Codeium, like GitHub Copilot, is a development tool that performs automatic code completion using AI.

Codeium provides extensions for various development environments and covers all major development environments. In this article, I will use Codeium on Visual Studio Code.

It is free for personal development (as of 3/5/2024). Paid plans seem to offer richer features, but I will use the free plan this time.

Supported languages

The Codeium FAQ page lists supported languages (Figure 1, 2).

What programming languages do you support?

Codeium’s performance is good (and enabled by default) for the following languages (alphabetical order): APL, Assembly, Astro, Blade, C, C++, C#, Clojure, CMake, COBOL, CoffeeScript, Crystal, CSS, CUDA, Dart, Delphi, Dockerfile, Elixir, Erlang, F#, Fortran, GDScript, Go, Gradle, Groovy, Hack, Haskell, HCL, HTML, Java, JavaScript, Julia, JSON, Kotlin, LISP, Less, Lua, Makefile, MATLAB, MUMPS, Nim, Objective-C, OCaml, pbtxt, PHP, Protobuf, Python, Perl, Powershell, Prolog, R, Ruby, Rust, SAS, Sass, Scala, SCSS, shell, Solidity, SQL, Starlark, Swift, Svelte, Typescript, TeX, TSX, VBA, Vimscript, Vue, YAML, Zig. On any other languages, you can explicitly enable Codeium.

Figure 2: Text excerpt from Figure 1. The bolded text indicates the languages supported by Codeium. It says here that other languages can also be used.

It doesn’t explicitly say Arduino.
The program for Arduino is basically composed of C/C++, so it seems to be available, but there are Arduino-specific functions and classes. So I don’t know how much the Codeium understands development with Arduino. Let’s give it a try.

Install Codeium extension and PlatformIO to Visual Studio Code

Install Codeium extension and PlatformIO to Visual Studio Code.
I will use PlatformIO in Visual Studio as the development environment for Arduino, and will also install extensions for Codeium(Figure 3).

Once installed, a Codeium button will appear (Figure 4, left), and clicking on it will bring up a chat area. Enter your text here and it will be answered (Figure 4).

Also, when you start typing your program in the editor, it will give you suggestions for code completion and adding comments. If you like it, you can adopt it. (Figure 5)

Let’s make a program for Arduino with Codeium!

Now I will actually create a program for Arduino with PlatformIO.

In PlatformIO, I will create a project with Arduino Leonardo as the supported board (Figure 6).

This is all the preparation required. Let’s start writing the code for the contents. First, since I plan to use servo motors in this project, I will install a library for servo motor control in PlatformIO and input code related to servos.

When I try to write setup() with only headers included and servo variables prepared,

As shown in Figure 7, attach(), which assigns pins to the servo, is now displayed. Since I will use a different pin number this time, I only rewrite that part.

Next, I will implement the contents of loop(). First, I will make a brief comment on the operation so that Codeium will understand how we want to write the code (Figure 8).

I repeat this process many times. Sometimes an unintended code is proposed.
In such cases, I either do not adopt the suggestion or adopt it and then modify it (Figure 9). When I make a comment, Codeium makes a better suggestion.

I also found it useful to have a function that automatically adds an explanatory comment to the code you have created. Pressing the “Generate Function Comment” button above a function will suggest an explanatory comment for the function (Figures 10 and 11).

If you select “Refactor” in Figure 10, a window like Figure 12 will open, and if you select “Add comments and docstrings to the code,” Codeium will write comments inside the function to explain the program behavior. These comments may not be the correct or intended explanation either, so confirmation is necessary.

These comments can also be in Japanese (Figure 13). Maybe other languages too.

Does Codeium understand Arduino specifications?

Codeium just suggested the code regarding servos. But does Codeium understand the rest of the Arduino specifications? Let’s give it a try.

I asked in a chat about how to use LEDs and servo motors with Arduino (Figure 14). Not all explanations were perfect, and for LEDs, only one of analogWrite() and digitalWrite() was explained. However, for the most part, the explanations were correct. It will be able to answer any questions specific to Arduino.

In addition to this, it understood the Arduino specifications and made suggestions, such as including Arduino-specific functions such as constrain() in their code suggestions.

Conclusion: It seems to be useful.

As we have seen, Codeium is able to provide code suggestions with some understanding of Arduino specifications.
It seems that Codeium can be used for embedded and IoT device development like Arduino.

For the latest status, check here.