Grid frequency Meter Block Upgrade

2026

AI Slop Arduino Sketch

I selected an STM32F103 as the microcontroller for my grid frequency meter because of my passing familiarity with its timer peripherals. I did not realize at the time, but the ESP32 is similarly capable. I jammed an ESP32 dev board into the original box to post the measurements to the internet and set up a MySQL database to log the measurements, but the whole thing was a pain in the ass:

Previous Ratsnest of ESP32 Dev Board Connected to STM32F103

Previous Ratsnest of ESP32 Dev Board Connected to STM32F103

Interposer Board Bottom

Interposer Board Bottom

To solve all of these issues and to simplify the architecture, I decided to design an interposer board to replace the STM32F103 with an ESP32. Since this is 2025, I also decided to see how well Cursor AI would do at taking my STM32 Cube IDE project and turning it into an Arduino ESP32 project.

Interposer Board Top

Interposer Board Top

Interposer Board Bottom

Interposer Board Bottom

Software

With the guidance of an embedded engineer friend, I pointed Cursor to the old code and asked that it port the project to ESP32. I provided a pin assignment and explained the functionality. To my general astonishment, it produced a working result using timers and interrupts on the first try. To test it out, I pulled the STM32 Bluepill board and hooked an ESP32 Devkit board in with jumper wires.

Stuart Island Anthill

ESP32 Dev Board Jumpered Into STM32 Dev Board Socket

On the first try, it managed to zero the stepper motor and display the measured grid frequency on the front panel. I then asked that it create a web interface hosted by the ESP32 and it produced this:

Stuart Island Anthill

Cursor's First Web UI Attempt

I couldn't get it to fix the GPS PPS lock formatting error (and I couldn't sort it out myself), but ChatGPT was able to fix the formatting error after I gave it the malformed code block. The "PPS Frequency" is actually the internal oscillator frequency in MHz and is only called this because I named the variable in the original code poorly. By the end of night one, I had this:

Stuart Island Anthill

Improved Web UI

I spent most of my manual coding time changing the low pass filtering of measurements. There were some floating point error issues with the exponential averaging math, and I found that it was not actually necessary to add exponential averaging. I added this very early on in the project when there were bugs in the code causing bad measurements and never went back to see if it was actually needed.

For everything else, Cursor did a great job of updating the code. I used it to add publishing to MQTT and making the associated credentials and topics of this configurable on the fly. I also used it to allow WiFi credentials to be updated, for adding GPS parsing, and to update the Web UI to work for my website. I feel like a monkey that has been handed a machine gun. There are projects that I have put off for years because I am not excited write the code for them that are accessible to me now. I despise the impact that generative AI is having on writing—producing clickbait slop has never been easier—but it is a useful tool for generating code. I expect that we will see a massive market correction likely beyond what was seen in the dotcom bust in the coming years, but it's nice having everything subsidized by investor dollars for the time being.

Stuart Island Anthill

All Region Web UI

The web UI available at gridfrequency.us now establishes a client side web sockets connection to the MQTT server and updates in real time to show the current frequency of each of the three power grids in the US. This is a rather stark improvement over the previous web UI which is an HTML table that auto reloads once per second.

At the time of writing, only the western grid meter is in place as I collected the meters for the upgrade, but they will be redeployed soon.

Hardware

The hardware for this upgrade came after the software because I wanted to be certain that I didn't need to move any pins around. Since there is a VBATT pin on the STM32 bluepill, I was even able to add a new backup battery to the interposer to make changing the battery easier. After ~3 years, the batteries were all still over 2.9V. I had the PCB fabricated by OSHPark since it is the cheapest option for small PCBs these days with tariffs and rising shipping prices. I assembled the boards by hand and was glad to have a clean solution to the previous ratsnest.

Stuart Island Anthill

Removed Borg Implant

I made new needles for the meter as well and had them printed by JLCPCB since their resin printing service is much higher quality than what can be produced by my aging Ender 3.

Stuart Island Anthill

New Needle

A final problem that I solved in this upgrade was hardware getting loose and stripped. I upgraded to longer screws for the face plate since two of the mounting holes stripped on one of the meters, and I also applied removable locktite to all of the hardware including the bulkhead mount SMA connectors as they also have an annoying tendency to get loose when installing and removing antennas.