March 16, 2023
- Debugging a student sketch
- Experimenting With Stylistic Choices
- State Machine
- ChatGPT is a Compiler?
- Finding an Arduino Simulator
- Bing Chat
- Perpexity.ai
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
- My prompts to ChatGPT are in the left column, in black text with a white background.
- ChatGPT responses are in the left column, on a light blue background; except for code, which is white (and other colors) on black.
- Commentary about the conversation is in the right column, on gray.
Transcript
Notes
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.
- The issue that
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. - The comment “you should check for a rising edge” is not correct. The submitted code already does this.
- ChatGPT has made a couple of non-functional improvements: it has added comments, and it has changed
digitalRead(7)
todigitalRead(button)
.
Experimenting With Stylistic Choices
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…
…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.
count == 2
and count == 3
cases that turned on pins that were already HIGH.ChatGPT went in a different direction, though, and eliminated all calls to digitalWrite()
by a write to PORTB
. (I didn’t know about PORTB
.)
- ChatGPT ends its response in the middle of a sentence output. Either it ran out of tokens (sometimes this happens), or there was a service interruption (I tried this the day after ChatGPT 4.0 was announced, and there was a lot of traffic, and a large number of outages, that day).
- This could have been even more concise (I’ll stop short of better) if I’d continued to let it use
PORTB
.
State Machine
OFF
, LED1_ON
, etc.) for the states of the state machine.ChatGPT is a Compiler?
I haven’t scrutinized or tested this assembly code.
PORTB
, and I hadn’t…)Finding an Arduino Simulator
https://arduinosimulator.org
.Let’s direct this question to a couple of Chatbots that are actually connected to the web. Bing Chat uses ChatGPT 4.0; I’m guessing Perplexity uses GPT 3.5, plus some secret sauce. Both of them are “retrieval-augmented” models, that combine web search (and possibly other corpora and other augmentations) with language models.