Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

Troubleshooting • Re: Trying to get servos to update

$
0
0
Lot to unravel here, but happy to help a fellow Kiwi.

First, you don't need the servo driver board, you could drive your servos from the GPIO pins directly. But, that doesn't help if your software is no good.

Secondly, ChatGPT is not helpful. It produces something that looks like code, but you have to decide if it's any good, and if it's broken, you have to fix it. The same problem arises if you get a piece of code from another person, but no explanation. Or your own oh-so-clever code you wrote in the past, which you can't remember how it came to be. Comments are necessary to explain what's happening, and why a certain piece of code does things in this way.

To debug this problem I suggest a three-pronged approach. You have to verify that each part of the program does what it should. In this particular program this means "does the program fetch data from the source correctly?", "does the program convert the data to servo positions correctly?", and "does the program write the servo positions to the hardware correctly?".

You aren't going to be able to debug the whole thing at once, especially as you have no idea how you got to this point, so break it down.

I suggest that you add lots of print statements to dump out data at various points in the program, as well as short messages to say what it's doing. It may become obvious when your program says "I'm doing X", and the results indicate that it really wasn't.

For example, for the first breakdown I suggested, just print out the results of calling these functions and see if there's actually any data in there, and that the data looks plausible:

Code:

    try:        while True:            print("Fetching tide data...")            tide_values = fetch_tide_data()            print(tide_values)            print("Fetching water quality status...")            water_quality_status = get_water_quality_status()            print(water_quality_status)

Statistics: Posted by ame — Sat Jan 25, 2025 7:19 am



Viewing all articles
Browse latest Browse all 8037

Trending Articles