In my Engineering with ChatGPT blog entry, I touched upon my experiences with ChatGPT over the last year or two. I first started to use it for programming in January 2025, when I started to migrate to Arduino NANO 33 IOT microcontrollers. This blog entry will dig into my programming experiences, including lessons learned and best practices as I discuss the application driving the EnergyLab Sandbox here.
Besides using ChatGPT for programming for the first time, this was my first time using Arduino products, my prior experience was with Particle Photons and Raspberry Pi units. So the learning curve ahead of me was significant, at least for the various applications that I had in mind.
The EnergyLab Sandbox project required a few steps and platforms. The goal of this activity was to take some near-real time data (every 2 minutes) from the EnergyLAB LAN and display it on this hosted WordPress page.
Here’s the actual NANO-021 that collects the MQTT data and publishes it to the Google Sheet on this WordPress page shown below.
- MQTT Data: On the EnergyLab LAN, I have various devices and real-time sensor data that I send to one of two MQTT Brokers as I referenced in the blog entry here. So I already have plenty of data points to select.
- Arduino NANO: In this case the device I call NANO-021, will grab the data from a EnergyLab LAN MQTT Broker. ChatGPT helped write this program that publishes it every 2 minutes (adjustable) to a Google Sheet as shown above. I’ll describe this in more detail and show the actual program that ChatGPT wrote below.
- Google Sheet: The Google Sheet has two pages, the first “Visible” page that makes the display we see and the second “Hidden” page that gets the mqtt data and titles across a number of columns every two minutes, constantly updating these two lines. It also has a Google Script that ChatGPT helped write to publish these to the 2nd page of the Google Sheet. After you hit “Deploy”, Google provides a URL that you insert into your Arduino code as shown in a section below to make this magic happen.
- Hosted WordPress: I wanted to publish some basic “Live” data from the MQTT broker from the boiler project and EcoFlow power station project on the internet. But to get some context around it I embedded it into these WordPress pages.
Programming the NANO with ChatGPT: Here’s a side by side example of an interaction between the the Arduino IDE and ChatGPT. You write prompts (i.e. details of what you have and want do) in ChatGPT and then copy and paste the results into the Arduino IDE.
I tried in the beginning to just interact via prompts and copy paste the ChatGPT code into the Arduino IDE. It worked, but found it worked better and faster if you take the Arduino Serial Monitor output from the program running at various point and paste it into ChatGPT. This helped speed up the process and success of the programming.
Ultimately, ChatGPT after several interactive, part-time sessions, over a week or two, wrote 99.99% of this 315 line, heavily commented program.
The speed at which it responds is almost instantaneous, and seems to get better over time and with each ChatGPT session, especially as OpenAI adds new features and capabilities. Remembering prior sessions was one of the greatest features, so your not always starting from scratch each time.
The actual running Arduino program has several blocks of code that were added incrementally over time as noted below.
- Connecting Arduino library modules for communicating with WiFi network and MQTT.
- Telling the NANO what MQTT data points we need.
- Initialization the various data point on startup.
- Connecting to the WiFi network and making sure it stays connected.
- Subscribing and getting the MQTT data from the MQTT Broker.
- Connecting to the Google Sheet using the script URL Google provided when first setting up the Google Sheet and sending it the JSON payload.
- Setup to make the WiFi and MQTT connections.
- Main loop, keep doing this over and over, maintain a heartbeat, and reconnect if needed.
- All of the code was also heavily commented and provides diagnostic output via the Arduino IDE and NANO’s Serial Monitor, i.e. text to tell you what the program was doing or problems.
Lessons Learned: Patience, especially when I first started, sometimes the interactive sessions felt like I was talking to a five year old. At times it wouldn’t remember what we just did and figured out. It got much better over time after feeding it the errors back from the Arduino Serial Monitor after code changes. It doesn’t get upset when you comment on dumb mistakes it made, but I still find myself saying thanks after it worked. It always offers more ideas and suggestions after each project is finally working.
This is the 21st NANO unit its programmed, various programs such as sensing, calculating, driving displays, calculating and creating new time series data streams, all running on the NANO’s, help me better understand and aid in my experiments and curiosity, about how “real world” “devices and systems work over time, especially at scan rates of 1 minute or faster.
Best Practices: Defining exactly what you want in the ChatGPT makes the biggest difference in success. I tried giving it the task of writing the whole program at one time and then asked for enhancements. That didn’t go well, it would loose sections of code or change them for no reason.
It’s best to work in modular sections or pieces. Say start with, help me connect to my WiFi network, lets add my MQTT broker, show me these MQTT data points in the Serial Monitor, lets send data to a Google Sheet, how do I embed this in a WordPress page, then follow-up as needed to make sure it all keeps running. Share the Serial Monitor output and what’s happening or not happening on the Google Sheet.
Next steps: Continue to watch the operation of the data coming into the EnergyLAB Sandbox. As of 03/16/25, its at Version 1.6, I’m not sure yet of the Google Sheet limits on updates and speed, currently set at 2 minute updates. Looking for more efficient and secure ways to get my EnergyLAB LAN Grafana graphics and InfluxDB time series to the Internet.