Chat GPT very good but not quite perfect

Jeremy Leach

Senior Member
Hi,

It's been a very long time since I avidly posted here, but I've recently had a little project on the go for an unusual van hear, and I was drawn back to the ease of use of the PICAXE .

As I'm very rusty on syntax and have lately been getting into AI in a big way, I thought I'd just tell ChatGPT what I wanted, that I was using an 08M, what my pinout needs to be, and just let it get on with it ! I'm very impressed that it has quite a deep understanding of PICAXEs and the code it spewed out is below. But I've had to tweak it a little because :

1. It omitted dirsC, so didn't specify the inputs and outputs - not good !
2. It originally thought it ok to use w0 and b0 as if they were completely separate variables - it didn't understand the nuance that b0 is part of w0. A pretty fundamental blooper.

I've told it off over these issues so hopefully it'll learn (I'm not exactly sure how it learns from user input though, but I'm guessing it must do). I'm just interested if anyone else has used AI to generate code and thought I'd share my experience.

Code:
symbol thermalSwitch = pinC.4       ' Input from thermal switch (e.g., physical pin 4 on 08M2)
symbol relayOutput = C.2            ' Output to the TIP31C (e.g., physical pin 5 on 08M2)
symbol ledOutput = C.1              ' Output to the LED (e.g., physical pin 6 on 08M2)

symbol failsafeTriggered = b0       ' Flag to track the failsafe state (0 = normal, 1 = failsafe)
symbol aliveCounter = b1            ' Timer variable for "I'm alive" flash

dirsC = %00000110                   ' Set C.2 and C.1 as outputs, others as inputs

high relayOutput                    ' Start with relay de-energized (heater ON by default)
low ledOutput                       ' Ensure LED is off initially

failsafeTriggered = 0
gosub startupFlash                  ' Flash the LED at startup

main:
    do
        if thermalSwitch = 1 and failsafeTriggered = 0 then
            gosub activateFailsafe   ' Trigger the failsafe if the thermal switch opens
        endif

        if failsafeTriggered = 1 then
            gosub alertFailsafe      ' Activate LED and buzzer in failsafe state
        else
            gosub aliveFlash         ' Perform the "I'm alive" flash
        endif

        pause 100                   ' Small delay for loop stability
    loop

startupFlash:
    for b1 = 1 to 3                 ' Flash LED 3 times at startup
        high ledOutput              ' Turn LED ON
        pause 200                   ' Keep LED ON for 200ms
        low ledOutput               ' Turn LED OFF
        pause 200                   ' Keep LED OFF for 200ms
    next b1
    return

activateFailsafe:
    failsafeTriggered = 1           ' Set failsafe state
    low relayOutput                 ' Energize the relay to turn OFF the heater
    return

alertFailsafe:
    high ledOutput                  ' Turn LED ON
    pause 500                       ' Keep LED ON for 500ms
    low ledOutput                   ' Turn LED OFF
    pause 500                       ' Keep LED OFF for 500ms
    return

aliveFlash:
    aliveCounter = aliveCounter + 1 ' Increment the counter
    if aliveCounter >= 50 then      ' ~5 seconds (50 x 100ms loop pauses)
        high ledOutput              ' Brief flash of LED
        pause 100                   ' Keep LED ON for 100ms
        low ledOutput               ' Turn LED OFF
        aliveCounter = 0            ' Reset counter
    endif
    return
 
You could probably omit that DIRs command ... setting pins HIGH or LOW automatically makes them outputs ... and I believe pins default to input at reset.

So did this code compile and work as expected?

Yes, ChatGPT is pretty crazy! And it's only getting better! It's fun to play with for sure!
 
You could probably omit that DIRs command ... setting pins HIGH or LOW automatically makes them outputs ... and I believe pins default to input at reset.

So did this code compile and work as expected?

Yes, ChatGPT is pretty crazy! And it's only getting better! It's fun to play with for sure!
I've had to make a couple more tweaks but only because my circuit design was a bit different to what I'd told it. It's all working fine now and I've got to say, it saved me a lot of time typing and refreshing my memory about syntax.

Ah yes I'd forgotten that about the IO direction being set when used - cheers !

It's interesting how engineering types immediately realise that AI 'is only going to get better' and the huge potential that implies. I feel many are still missing the point. I've recently got into two-way real time chats with Google Gemini - quite amazing. I'm using Chat GPT daily as an assistant for (mainly) C# coding and it's fantastic, and has taught me such a lot about coding in more modern ways.
 
I'm not exactly sure how it learns from user input though
My understaning is that within a single session these LLMs have all learnt from your responses and providing feedback to the LLM to try and get it to generate a more correct answer, e.g. like telling it that b0 is a part of w0, is what is referred to "Prompt Engineering".

Whether any of the LLMs add what you've taught them to the underlying model, so that they can use they info you gave them in their answers to other people's queries, is a different issue.
 
I guess a way to test if it's "learning" is to go back and ask it to generate the same code based on the same conditions you gave it before (chat GPT chats are stored in history, so you should be able to go back and re-create the question) ... see if it "learned" from your correction. I just asked it if it knew about PICAXE BYTE and WORD variables, and it said it did, explained how W0 is made of B0 and B1 and gave a small sample of code putting a variable into B0 and another into W1 and then "debug" for both.

However, it's very difficult to know what these LLMs are just parroting back vs. what they are putting together based on "learning"
 
I guess a way to test if it's "learning" is to go back and ask it to generate the same code based on the same conditions you gave it before (chat GPT chats are stored in history, so you should be able to go back and re-create the question) ... see if it "learned" from your correction. I just asked it if it knew about PICAXE BYTE and WORD variables, and it said it did, explained how W0 is made of B0 and B1 and gave a small sample of code putting a variable into B0 and another into W1 and then "debug" for both.

However, it's very difficult to know what these LLMs are just parroting back vs. what they are putting together based on "learning"
After I corrected it about B0 and W0 yesterday it said I was right and modified the code but no apology :).

I've noticed with Chat GPT that each conversation topic seems to be isolated memory wise, as if each thread spawns a new 'person' you are speaking with. For example after having had a long discussion yesterday about my heating system details, it got so familiar with all my terminology to the point it was making me laugh. Then this morning I mistakenly started a fresh chat on the topic and it was as if I was talking to a separate person who I'd never spoken to about it before ! But when I appended to my old chat it remembered everything.
 
If an AI system were to apply your corrections across the system, that would make it wide open to malicious corrections. Hopefully, some serious fact-checking can be applied then before it accepts a correction.
 
Back
Top