Shop OBEX P1 Docs P2 Docs Learn Events
CHAT GPT and my Propeller board — Parallax Forums

CHAT GPT and my Propeller board

Lightwheel58Lightwheel58 Posts: 6
edited 2024-02-15 17:27 in C/C++

I made a little project for a microbit I have and decided to take the code from it which was in Python
and convert it into Blockly Prop for my Propeller board and it would not compile on the Simple IDE.
The project consists of a plastic box that has a piezo sensor for a cell phone to lie on. My metal shop is
dirty and loud so this keeps the phone protected and when a call comes in the sensor triggers a relay to
to play a Ma Bell retro ringtone over a speaker which is loud enough to hear over a power hammer.

Is this code that GPT gave me worth fixing? or is it Dschunke 🙄

CON
  sensorPin = 0
  outputPin = 2
  threshold = 30

VAR
  sensorValue

OBJ
  serial: "FullDuplexSerial"

PUB Initialize()
  serial.start(9600, sensorPin, sensorPin)

PUB Main()
  repeat
    sensorValue := analogRead(sensorPin)
    serial.sendDec(sensorValue)

    if sensorValue > threshold
      high(outputPin)
      serial.str(string("Vibration detected!"))
    else
      low(outputPin)

    waitcnt(clkfreq / 10 + cnt)

Comments

  • Hi @Lightwheel58

    I've added 3 backticks around your code posting above, so the code highlighting/formatting works on this forum.
    If you click the cog/settings icon, top right of your post, you can see what I did.
    Makes it easier for people to read and help you.

    Hopefully one of the code experts will have some ideas for you soon!
    All the best with your project.

  • thanks for your
    help

  • I think your code is missing analogRead()

  • evanhevanh Posts: 15,862

    Posting Spin code in the C forum ain't ideal. There is a couple of C compilers for the Propellers if you'd like to use C.

    Regarding the posted code, Spin has no reserved method name for startup of program, the Spin compilers just use the first method listed. In this case Initialize() becomes your startup method. And since it only starts the comport and then finishes you won't get any results.

    It looks to be Spin1 rather than Spin2: PropTool won't like the round brackets without parameters within. Just remove the brackets.

    The high and low statements aren't in Spin. Use OUTA[outputPin] = 1 and OUTA[outputPin] = 0 instead.

    Your string() will need line termination added if you want each occurrence on a new line.

  • Perhaps I'm missing something, but it looks like you are initializing the serial RX,TX pins to the same pin as the sensor pin.

    Never trust Chat GPT to generate code.... As a "test" I asked Chat GPT to generate PIC Assembly code to determine which WORD between two WORDs was the largest. It was a joke the number of iterations I had to go through to coach and tell it what to do and at that I had to have a bit of prior knowledge on how the Carry Flag works between two BYTES and how to test the HIGH BYTE vs the LOW BYTE. And the chat GPT did not gain knowledge on previous iterations... IOW it was very forgetful within the current conversation.

  • Thanks for the help
    I had hoped it might be an easy fix of a simple error but the vibe tells ditch this sketch and go back to square one, I did surprisingly have some luck earlier with the CHATGPT...now I have found it's limits ;)

Sign In or Register to comment.