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.
<aside> ℹ️ Note:
Transcript
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>
<aside> ℹ️ Notes:
val
is uninitialized is correct. The consequence of this is that the code behaves nondeterministically if the button is pressed when it starts: it might detect this as a button press; it might not.digitalRead(7)
to digitalRead(button)
.
</aside><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.
<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
.)
<aside> ℹ️ Notes:
PORTB
.
</aside><aside>
ℹ️ Note that ChatGPT came up with descriptive names (OFF
, LED1_ON
, etc.) for the states of the state machine.
</aside>
<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.
<aside>
ℹ️ This doesn’t look right, but I tried it anyway. (Who knows — ChatGPT had known about PORTB
, and I hadn’t…)
</aside>
<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>
<aside> ℹ️ I pressed “Regenerate” to request another answer for the previous prompt, and it generated a completely different (untested) solution.
</aside>
<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>