A.I. Claude to write code

Yesterday I tried using the A.I. Claude

It took about two hours and lots of back and forforth, but Claude wrote a program for Arduino Uno Q AppLab that lets me control 8 of the output pins on the Uno Q by using a web page.

It generated the sketch.ino, main.py, index.htm, app.js ….

The webpage shows the status of the 8 pins and lets me turn them on and of.

Claude figured out the correct syntax for all the different functions. It was a lot better than using the A.I. in Google Chrome. Anybody else tried it?

Post all the code so we can see what it did.

What sort of "back and forth", and why two hours?

The main problem has been that beginners without the skills to recognize coding mistakes generally can't get useful results from the LLMs.

I asked Google: "what is googles claude equivalent. is it different than the ai in chrome". Spoiler for the second half: yes.

yes - why?

it's probably much faster than this with the right prompting.

I

screen shot of the app. Claude A.I. wrote

copy of the app is attached.

It was an experiment for me. … to see what it could do. I was impressed. figured other people might be interested.

The reason it took quite awhile is my trying to figure out what Claude wanted…. it started to give pretty qood answers once i gave it a screen shot of the “About Arduino App Lab”. Then all the code it was generating got really good.

forum8pins.zip (21.6 KB)

I asked Claude if it could write VHDL for an fpga and it asked what kind of combinational or sequential , and other options i wanted. I said serial in, to 16bit, into a fifo with Pclk, Hsync,Vsync. and it wrote the code and asked what core i used, i said tang nano and it aksed which pinout as it could make me a .cst file for pin matrixing. Wild times. Mentioning specific signal and net names in the required design is critical info. I wonder if i missed out Vsync it would add it anyway.

Hi, I'm using Claude Code, but with little bit different chain. Visual Studio Code with Remote and Claude Code plugin. In this setup Visual Studio Code is running on personal computer, but agent run directly on Arduino, can write code, interact with filesystem or run commands. Claude coding results looks like this:

I have imported your app into my App Lab and run it successfully; it is working well. Some improvements are needed to make it more graphical, such as replacing 1/0 with an LED or bulb ON/OFF indicator similar Blink LED with UI app example of App Lab. Thank you for sharing your work.

However, if we use AI in this way to develop applications, then when will we be able to observe the mistakes that a human would normally make, or engage in discussion and challenge incorrect assumptions?

Thanks for sharing your approach @milanriha!

Is the agent running on an UNO Q board?

Are you using an existing solution for the on-board agent part of your system, or is it something you created from scratch? Which model are you running on the board?

yes, it is. Probably this process

arduino 2246821 2244608 3 07:12 ? 00:01:37 /home/arduino/.vscode-server/extensions/anthropic.claude-code-2.1.145-linux-arm64/resources/native-binary/claude --output-format

Nothing custom, just install Claude Code plugin and Remote plugin.

Which part of this app could you write? Don't you know how write program for MCU and MPU and excnage data between them?

For example, I could write the .py and .ino and for other sections of the app, I would take help of forum members or AI.

@tom2020

I am giving below the source code for the .py and .ino files of your app. Interested readers my get involved, read it and debate if there are something that deos not match between the .py and .ino files, working principle, etc.

Sketch.ino

#include "Arduino_RouterBridge.h"

#define NUM_BTNS 8
int pins[]      = {4, 5, 6, 7, 8, 9, 11, 12};
int pinStates[] = {0, 0, 0, 0, 0, 0,  0,  0};

String read_buttons() {
  String payload = "{";
  for (int i = 0; i < NUM_BTNS; i++) {
    payload += "\"btn" + String(i + 1) + "\":" + String(pinStates[i]);
    if (i < NUM_BTNS - 1) payload += ",";
  }
  payload += "}";
  return payload;
}

void set_pin(String args) {
  int comma  = args.indexOf(",");
  String btn = args.substring(0, comma);
  int val    = args.substring(comma + 1).toInt();
  int idx    = btn.substring(3).toInt() - 1;
  if (idx >= 0 && idx < NUM_BTNS) {
    digitalWrite(pins[idx], val);
    pinStates[idx] = val;
  }
}

bool linux_started() { return true; }

void setup() {
  Bridge.begin();
  for (int i = 0; i < NUM_BTNS; i++) {
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], LOW);
  }
  Bridge.provide("set_pin", set_pin);
  Bridge.provide("linux_started", linux_started);
  bool started = false;
  while (!started) {
    Bridge.call("linux_started").result(started);
  }
}

void loop() {
  Bridge.notify("payload", read_buttons());
  delay(500);
}

main.py

from arduino.app_utils import App, Bridge
from arduino.app_bricks.web_ui import WebUI
import time
import threading
import json
import os

ui = WebUI()

def pin_callback(data):
    print("pins:", data)
    ui.send_message("payload", data)

def set_pin_handler(client_id, data):
    pin_key = data.get("pin")
    val     = int(data.get("value", 0))
    print("set_pin:", pin_key, "->", val)
    Bridge.call("set_pin", pin_key + "," + str(val))

def get_sysinfo():
    info = {}
    try:
        with open("/proc/stat") as f:
            a = f.readline().split()[1:]
        time.sleep(0.2)
        with open("/proc/stat") as f:
            b = f.readline().split()[1:]
        idle  = int(b[3]) - int(a[3])
        total = sum(int(x) for x in b) - sum(int(x) for x in a)
        info["cpu"] = round(100.0 * (1 - idle/total), 1) if total else 0
    except:
        info["cpu"] = 0
    try:
        d = {}
        with open("/proc/meminfo") as f:
            for line in f:
                p = line.split()
                d[p[0].rstrip(":")] = int(p[1])
        total = d["MemTotal"]
        free  = d.get("MemAvailable", d.get("MemFree", 0))
        used  = total - free
        info["mem_pct"]   = round(100.0 * used / total, 1)
        info["mem_used"]  = round(used  / 1024**2, 2)
        info["mem_total"] = round(total / 1024**2, 2)
    except:
        info["mem_pct"] = info["mem_used"] = info["mem_total"] = 0
    try:
        st = os.statvfs("/")
        total = st.f_blocks * st.f_frsize
        free  = st.f_bavail * st.f_frsize
        used  = total - free
        info["disk_pct"]   = round(100.0 * used / total, 1)
        info["disk_used"]  = round(used  / 1024**3, 2)
        info["disk_total"] = round(total / 1024**3, 2)
    except:
        info["disk_pct"] = info["disk_used"] = info["disk_total"] = 0
    try:
        with open("/proc/uptime") as f:
            secs = float(f.readline().split()[0])
        h, r = divmod(int(secs), 3600)
        m, s = divmod(r, 60)
        info["uptime"] = "{:02d}:{:02d}:{:02d}".format(h, m, s)
    except:
        info["uptime"] = "00:00:00"
    return info

def sysinfo_loop():
    while True:
        try:
            ui.send_message("sysinfo", json.dumps(get_sysinfo()))
        except Exception as e:
            print("sysinfo error:", e)
        time.sleep(3)

ui.on_message("set_pin", set_pin_handler)
Bridge.provide("payload", pin_callback)

threading.Thread(target=sysinfo_loop, daemon=True).start()

App.run()

Qustion-1:
If the purpose of the following code at the sketch side is to wait until the Linux has started, then there should be a correspondingg Bridge.provide("linux_started", linuxStarted) function in the python script; unfortunately, I can't trace it? Will you help to find it there?

while (!started) {
    Bridge.call("linux_started").result(started);
  }

These are the code that I use for the above purpose.
At MCU side:

  String value = ""; //value is updated by Linux at MPU
  bool success = false;
  
  // Wait until Linux is started
  do
  {
      RpcCall rpc = Bridge.call("linux_started");
      success = rpc.result(value);
  }
  while(success != true);   //true = 1 or false = 0, value = any value comes from MPU
  Monitor.println(value); //shows: Linux has booted...!

At MPU side:

#used only for sync purposes
def linuxStarted():
  return "Linux has booted...!"  # goes to MCU

Bridge.provide("linux_started", linuxStarted)

The guy with the Swiss accent is out in front of everyone using Claude code for ESP32 development and testing.

AI-Driven ESP32 Workflow (Spec → Code → Test) using Claude Code

After my last video, many of you asked for a deeper look at how I actually work
with AI and the ESP32. So today I will show you a real example project — an iOS
voice keyboard for any computer. But that’s only half of the story. You will
also see how I automatically test ESP32 devices using an “ESP32 workbench” — a
Raspberry Pi running special software that allows an AI agent to program,
flash, monitor, and even test Wi-Fi and BLE behavior of ESP32 boards. The
second part is a full walk-through, from the installation of Claude Code till
the test of the project, if you want to see the extreme power of today’s AI