Writing libraries to support our favorite microcontrollers is a big task, but what if ChatGPT could lend a hand? Adafruit's own Limor "Ladyada" Fried has tasked ChatGPT to write Arduino drivers in her own style, creating a "mini-Limor" bot to handle the task.
Ladyada spends a lot of time writing Arduino libraries, and has produced hundreds of libraries to support Adafruit's impressive range of boards (many of which feature in our best Grove and Stemma QT page). GPT-4 has already been trained using many of Adafruit's drivers found on GitHub. These drivers are written in the "Ladyada style" (Adafruit_BusIO) and that means it can create drivers using this template.
The workflow involves a lot of datasheet references, binary tables and bit insets, all of which need to be understood and converted into C or Python code. This task isn't easy (trust us, we have tried it our self). There isn't a standard format to get this data. Datasheets can be wildly different.
For "mini-Limor", Fried's workflow involves asking ChatGPT to "[write] an arduino library in the same style as ladyada / limor fried". In the example Fried tasks ChatGPT to create a driver for the VCNL4020 ambient light and infrared sensor, an I2C based sensor. The workflow uses a free PDF parsing plugin (AI PDF) that reads a datasheet, extracts register names, values, creates enum tables and text for comments.
Fried then asks ChatGPT to create a skeleton file for the VCNL4020 which it was partially successful in creating. Then Fried asks it to create the registers, using data directly from the datasheet. After that Fried moves on to making the library.
Is this a faster process? Well, no. According to Adafruit's blog post, "The amount of time it takes for ChatGPT to write a driver is about the same as it would take Ladyada" and the resulting driver requires human interaction to check that it is valid, as Fried states in the video, ChatGPT can sometimes "hallucinate" and introduce mistakes. That being said, it does free up Fried to undertake other tasks.
The produced work is based upon Adafruit's own prior work, but Adafruit has confirmed that when any Large Language Model (LLM) is used, it will be disclosed and linked to.
Good drivers form the basis on which learners can cut their teeth without getting too technical, especially with I2C, SPI and many other protocols. If the process can be refined and automated, then it could help developers such as Adafruit to create drivers and libraries for many of the popular programming languages. The process could be used to address third-party software support with the Arduino Uno R4 range of boards. Fried also mentions that this process can also be used with CircuitPython, meaning that the Raspberry Pi Pico range of boards.
Adafruit has a blog post and links to the entire process, including ChatGPT logs for reference.