March 16, 2023

This is an experiment in using ChatGPT 3.5 to debug a student question.

The responses shown were the first responses. Nothing was cherry-picked.

Debugging a student sketch

<aside> ℹ️ Note:

Transcript

Screenshot of Notion (3-16-23, 19-00-30).png

Notes

<aside> ℹ️ The conversation begins with a student question that was posted to Slack.

This is the original student code (minus a final “Thank you”, that I omitted for no good reason), copied from Slack and posted into ChatGPT.

</aside>

Untitled

<aside> ℹ️ Notes:

CleanShot 2023-03-16 at 19.18.06@2x.png

Experimenting With Stylistic Choices

<aside> ℹ️ Note: The code only supports one round (it does not contain logic to reset count back to 0), so this prompt is misleading.

However, it is the answer that was supplied by a (human) instructor in the channel, so I decided to see what ChatGPT would do with it…

</aside>

…and, in addition to adding code to turn off the LEDs that should not be lit, ChatGPT adds code (the new “overflow” condition) to reset the count back to zero, so that there is another round.

Untitled

<aside> ℹ️ I was fishing for ChatGPT to remove some lines from the count == 2 and count == 3 cases that turned on pins that were already HIGH.

</aside>

ChatGPT went in a different direction, though, and eliminated all calls to digitalWrite() by a write to PORTB. (I didn’t know about PORTB.)

CleanShot 2023-03-16 at 19.33.08@2x.png

<aside> ℹ️ Notes:

State Machine

CleanShot 2023-03-16 at 19.35.21@2x.png

<aside> ℹ️ Note that ChatGPT came up with descriptive names (OFF, LED1_ON, etc.) for the states of the state machine.

</aside>

ChatGPT is a Compiler?

Untitled

<aside> ℹ️ Not shown: a series of questions where I asked ChatGPT to use Object-Oriented Programming. It defined a C++ class to represent states, and a subclass to represent each specific state. It was an explosion of overly verbose (although, on a quick read, correct) code, that didn’t demonstrate much. Rather than try to coach it back on track, I restarted the conversation (in the colloquial sense, not by resetting the chat) by asking it to refer back to the code before these changes.

</aside>

I haven’t scrutinized or tested this assembly code.

Screenshot of Safari (3-16-23, 19-08-19).png

<aside> ℹ️ This doesn’t look right, but I tried it anyway. (Who knows — ChatGPT had known about PORTB, and I hadn’t…)

</aside>

CleanShot 2023-03-16 at 19.09.04@2x.png

<aside> ℹ️ …and, as (mostly) expected, it failed, so I pasted in the error message.

</aside>

<aside> ℹ️ The following instructions (untested) are closer to what I had been expecting the first time.

</aside>

Screenshot of Safari (3-16-23, 19-09-50).png

<aside> ℹ️ I pressed “Regenerate” to request another answer for the previous prompt, and it generated a completely different (untested) solution.

</aside>

Finding an Arduino Simulator

Screenshot of Notion (3-16-23, 19-10-19).png

<aside> ℹ️ ChatGPT is hallucinating. There are Arduino simulators (or emulators), but there is nothing called the “Arduino Simulator”, and there is no site https://arduinosimulator.org.

</aside>