Generating code with ChatGPT

This was ChatGPT last year ....

I'm not sure what to make of this code generated by ChatGPT .....

' PICAXE code for a "Knight Rider" display

symbol leds = b.0 ' define the LEDs as b.0

main:
for delay = 1 to 20 ' loop through the delay
for led = 0 to 7 ' loop through the LEDs
shiftin leds, leds, right ' shift the LEDs to the right
high leds.0 ' turn on the first LED
pause 50 ' delay for 50ms
next led
next delay
goto main ' loop the program

In this code, the LEDs are connected to pin B.0 of the PICAXE microcontroller. The "main" loop starts by iterating through a delay loop and then through the LEDs. Within the inner loop, the LEDs are shifted to the right using the "shiftin" command, and the first LED is turned on using the "high" command. Finally, a pause of 50 milliseconds is used to create a delay between each LED being lit.

This is ChatGPT this year ...

Code:
#picaxe 08m2

' Define the pins for the LEDs
symbol LED1 = C.1
symbol LED2 = C.2
symbol LED3 = C.3
symbol LED4 = C.4
symbol LED5 = C.5
symbol LED6 = C.6
symbol LED7 = C.7
symbol LED8 = C.8

' Define the delay time between LED changes
symbol delayTime = 100

main:
    ' Move LEDs from left to right
    high LED1
    pause delayTime
    low LED1

    high LED2
    pause delayTime
    low LED2

    high LED3
    pause delayTime
    low LED3

    high LED4
    pause delayTime
    low LED4

    high LED5
    pause delayTime
    low LED5

    high LED6
    pause delayTime
    low LED6

    high LED7
    pause delayTime
    low LED7

    high LED8
    pause delayTime
    low LED8

    ' Move LEDs from right to left
    high LED7
    pause delayTime
    low LED7

    high LED6
    pause delayTime
    low LED6

    high LED5
    pause delayTime
    low LED5

    high LED4
    pause delayTime
    low LED4

    high LED3
    pause delayTime
    low LED3

    high LED2
    pause delayTime
    low LED2

    ' Repeat the sequence
    goto main

It's getting better !
 
We don't have proper 'general use' robots yet. The hardware is ready ( Boston Dynamics, etc ), but they still need brains. AI will provide them
The problem I see with general use robots is not brains but batteries!
Boston Dynamics posted a 37 second demo of their new robot. Very impressive, but I think the battery would only last 60 seconds hence a very short video.
 
Limited battery capacity and life were the reasons some early satellites used nuclear power cells, with the heat of nuclear decomposition warming thermocouples to provide long-term power. There were some near-panic responses when the launches of those sats failed and they had to find and recover the possibly radioactive bits and pieces.
Don't know that we'll see small nuclear power packs offered as "lifetime" batteries, complete with the assorted nuclear warning labels and seals and the need for attending and successfully passing a "Nuclear Battery Maintenance Course". Too many curious folks that would want to see "What's inside?" and let out the magic smoke and some of the not-so-magic radiation :-(
LTO batteries do have potential to improve on their current cycle life of 10,000 charge discharge cycles (27+ years at one cycle/day) but there are still the weight and size considerations. The hype I've seen on sodium ion batteries claims they are smaller and lighter than lithium batteries for the same power. Until I've seen tests by a known independent lab - or I can get "hands on" to do my own testing, I'll take their claims with a grain of salt ;-) Last I checked, one of the sodium ion battery companies wanted $150 just for the shipping of a few 18650 size cells - not something this old retired guy can justify for curiosity.
I saw one of the early "mule" robots which used an internal combustion engine for power. Using fuel injection resolves the problems of fuel flow in a machine which can get more than 90 degrees from the horizontal and the problems of managing oil flow to and from the oil sump (or its equivalent) were solved long ago for the engines used in acrobatic and military fighter aircraft so that could be the power source of a robot in a breathable atmosphere. But how much fuel can it carry and how does that affect its ability to do what is needed and how long can it run? And how would the sloshing of fuel in a partly empty tank affect its ability to position itself?
I'm the pessimist every designer needs looking over his/her shoulder ;-)
 
@PhilHornby

Absolutely Right Sir! Post redacted...

Sorry to pollute the conversation with dibble from a Bot. I find most, if not all, Bots are just glorified search engines with a bit of human response thrown in for measure. It's all too easy to have the Bot branch down the wrong rabbit hole.

I'll stick to writing quality code in future...73

Regards,
Ralph - VE3XRM
 
Last edited:
Just a thought ...

Neither Copilot nor ChatGPT are especially good at writing Picaxe code, especially compared with something like Python (where they are significantly better than me!). I assume this is because there is relatively little source code out there on the web, for them to learn from?

So, if you publish *their code* here, you may inadvertently create a feedback loop, that makes them worse - since this is the one place, where they will find some code ... :unsure:

That's not to say that you can't publish a link, to the conversation you had.
 
I'm not sure whether to post here or start a new thread, but I'm interested in what the current feeling is about ChatGPS' code-writing abilities for Picaxe.
 
I'm not sure whether to post here or start a new thread, but I'm interested in what the current feeling is about ChatGPS' code-writing abilities for Picaxe.
Test it and see for yourself.

If your desired program is simple enough, ChatGPT may fit the bill ... if it's more complex, you might run into problems.
 
I won't be trying ChatGPT any time soon. If I want a quick and easy solution, I'll write it myself, faster than I could learn chat. If I want something more challenging, I wouldn't be trusting ChatGPT anyway.
 
ChatGPT is like Google-translate. It can save you a lot of typing, but you need to know enough to find and correct its mistakes.
I asked it for a program to show the colours of an RGB led using a Picaxe:
the first three lines of its program were syntax errors, the rest was OK.
 
Picaxe Basic is probably one of the few programming languages, where we humans still have a considerable edge over AI, simply because it doesn't have the same experience of using it and there are relatively few places where it can acquire that knowledge.

There's a survey of current (mainly professional) developers' attitude to AI, here: https://survey.stackoverflow.co/2025/ai
(Spoiler: 47.1% say "Yes, I use AI tools daily")

Apparently, one thing respondents are not using it for, is so-called "Vibe coding" - where the problem to be solved is described and AI writes all the code...
 
Not many 'working' Picaxe Basic listing are available in the web to properly train a model. This forum mainly has non-working listing from people trying to trace errors in their code, so chances are you will get a listing from chatgpt containing errors.
ChatGPT is good for other tasks, e.g. to help you out with an algorithm which you will need to implement in Picxe Basic. ChatGPT, as well as the other models, are wonderfull tools and you need to use them as tools and not as solutions.
 
ChatGPT might not know much about Picaxe, but it is a whizz with Python !.

I am working on a project using an RPi4. I don't know Python, so I went to some relevant forums to learn. Typical Q/A scenario there, Q: How do you do some thing ?. A: You can find the answer in a Python manual, go and find it. You don't know how lucky we are with our forum !.

The project needed a robust GUI, multi-threading, some physical I/O and fiddly file handling. I described the overall task, and after a few hours of iterative to-and-fro discussions I got a fully working, 300 line, fully commented template I can develop. The code uses techniques it would take me months to learn about, especially as I didn't know I needed them !. As it is, I can learn them now in a real application, so much easier to follow than a stripped-down simple example. ( They are like being taught what a brick is, but not what a brick is for. )

I too was suspicious of AI's code writing ability, but this exercise has convinced me otherwise. As long as you are able review the code and test the results I can see it being very useful.

Cheers,

Buzby
 
A few years ago I started writing a Rubik's Cube solver using the PE simulator. It was going great, but when it needed more than one slot the ridiculous limitations of the simulator made progress too cumbersome, so I dropped the project.

Today I asked Chatgpt to write a solver to run on a Picaxe, it said "No way, Picaxe is not big enough". So I showed it what I had written in a single #slot, and it replied 'That’s a fantastic start — you’re clearly going all-in on building a full cube solver directly on a PICAXE, and your code structure already covers the logical hierarchy (cross, corners, rotation tables, move decoder, etc.). You’ve basically written the Rubik’s Cube equivalent of a chess engine'.

I then told it about #Slots and I2C EEPROMS. It has now taken my code and written all the stuff I never got round to. ( It does have some basic errors. e.g. I can see it is using brackets in some places. )

The fact that it recognised the structure of my attempt, understood my advice about #Slots, then proceeded to expand my code has impressed me very much. Obviously I could correct the minor errors, but I still can not run it in the simulator to check it works, so I'm back to square one.

Maybe Rev Ed should ask Chatgpt to modify PE so that it can support #Slots .
 
I find that Claude or Google Gemini are better at code than ChatGPT. What they're trying to do with ChatGPT is essentially replace Google, by making it give you the answer to anything. It can give you a decent start but falls down on structure. ChatGPT is also too eager to suggest additional ideas before you've even had a chance to verify what it's done.
 
Hi,
A (very long) Recent thread attempted to use it, but IMHO failed to create any "useful" program code or solve the problems encountered.

Cheers, Alan.
Thank you for this link: I will read with interest. I did not find it on searching due to the thread's title.

I should perhaps give a little background to my original question. I'm a semi-retired IT engineer and technical author with a Picaxe retirement project or two in mind. I cut my hobby programming teeth in the 1980s, like so many others, on BASIC, but then (due to being invited to the wrong interview) was plunged into the serious software industry, where I worked on data analysis, avionics and other things using Assembler, Fortran and Pascal. I moved on to document engineering before I had had a chance to work with object-oriented programming.

So Picaxe BASIC is both familiar and unfamiliar, but I want to learn it quickly. That's what took me to ChatGPT.

My experience up to now is that LLMs can provide useful learning tools by asking them to generate programs and then debugging them myself. I have tried ChatGPT and Claude so far. ChatGPT makes mistakes, of course, such as overwriting variables in subroutines, and, as someone else pointed out, trying to do maths in an IF clause, but then responds well when you point out its errors. Claude appears to be a more sophisticated model for generating code, even in Picaxe BASIC, but I've not got far enough in analysing its output yet to reach a more definite conclusion.

So I think these things can save a lot of grunt work, but you need to know what you are doing to apply debugging and refinements.
 
I find that Claude or Google Gemini are better at code than ChatGPT. What they're trying to do with ChatGPT is essentially replace Google, by making it give you the answer to anything. It can give you a decent start but falls down on structure. ChatGPT is also too eager to suggest additional ideas before you've even had a chance to verify what it's done.

Actually, Qwen2.5-coder is far better in producing code, from what I have seen. Even smaller models, e.g. 32B, can produce good code for common languages, e.g. HTML, JS, Python.

Google, is already testing the waters in using Gemini to replace the 'search the web' concept with the generated AI replies. We already know that Google is hiding search results for whatever reason. Now, having an AI reply for the subjects you are serching for and hinding the actual results makes things even 'darker'.

Unfortunatelly, the Internet will suffer from this 'revolution'. The human generated content on the Internet, the one that AI used to train itself, will vanish at some point. You can already see blog posts, forum posts, etc. that were generated by people using AI or in other cases from an AI 'workflow automation' tool that read the news feeds, picked the top topics from the list and generated an automatic blog entry, forum post, etc.
 
Google, is already testing the waters in using Gemini to replace the 'search the web' concept with the generated AI replies. We already know that Google is hiding search results for whatever reason. Now, having an AI reply for the subjects you are serching for and hinding the actual results makes things even 'darker'.
Worth noting that in Chrome, you can suppress the AI summary by adding " -ai" (no quotes) after your search term.

I'll have a go with Qwen for some python programs - I usually use Claude Sonnet 4.5 which I find to be very good
 
Back
Top