These days you can’t get away from the Artificial Intelligence (AI) hype, it is unavoidable. Supposedly it can do anything and everything with no limitations. But beyond the marketing, there is a lot that AI can do to help make your life easier. I’m going to walk you through how you can utilize AI for ham radio applications. It is a great way to solve problems and create software for your projects, even if you are not a programmer.
I think the best way to show you how to use an AI Large Language Model (LLM) is to run through the prompts I used on a project for remote station temperature monitoring. I needed a way to get sensor readings from an external sensing board on a Raspberry Pi for display on a computer data dashboard. I decided I wanted a script that could collect the readings every few minutes and transmit them to a second computer that served up all the dashboards for the station. Some call this a “single pane of glass” since you can go to one location and see everything together rather than separate applications/computer web page locations that only show individual readings.
I’m going to use ChatGPT to help me. This is my main AI choice for programming and is free for a certain number of requests a day. If you find yourself using it a lot, it will prompt you to upgrade to the $20 a month plan. You can always just take a break and come back when it asks you to upgrade if you don’t want to pay or are still experimenting with it. You can easily pick up where you left off after the program usage timer resets.
Just go to https://chatgpt.com/ and you’ll see a screen that looks a lot like Google. If you set up a login, it will remember previous conversations and projects but you can start off anonymously at first, if you want. It is important that you DO NOT put anything personal into it like passwords, credit card info, etc. as you don’t want your information inadvertently revelated in someone else’s inquiries. Partly why it is free is it is learning from everyone so it can get better at its answers. There are settings you can turn off to protect yourself from it consuming your personal data but better safe than sorry.
Another thing to consider is that if an AI doesn’t know something it will often make up an answer – this is called “hallucination” so always check what it tells you. Sometimes it will be quite certain in its responses and they can often be very wrong so remember it can make “mistakes.”
The box you see when you land on the main ChatGPT webpage that says “Ask anything” is called the prompt box. This is where you are going to type in your requests.
In my case, I have a Raspberry Pi with an external BME 280 board that senses temperature, humidity and barometric pressure like the one below.
In the ChatGPT prompt box. Here is what I typed. There is no need to type please or thank you since that just uses compute power and electricity, so try to get in the habit of skipping pleasantries (my actual prompt entries are in italics).
Write me a bash script for a BME280 board on a Raspberry Pi to gather temperature, humidity and pressure and then publish that data to corresponding MQTT topics.
Let’s breakdown what I just requested it to do.
I asked it to take readings from the BME 280 sensor board using a bash script which is a simplified program I can run on the Raspberry Pi easily. I then told it to transmit that data out using something called an MQTT server which I can have another computer to listen to take data and process or display it.
This way I can put a small, inexpensive computer in a place that I need the sensor reading, so I don’t need to run long sensor wires all the back to my main machine. I just need to make sure I can have ethernet or wifi available to my Raspberry Pi at the remote location.
Even if you are not a programmer, you still need to be able to explain what you want it to do with some accepted computer terminology. You can always ask it for help if you are not sure what to say or just try to explain things as best as you can. What I often do is just look at some web pages describing what others have done or a YouTube video or two for application like what I want to do.
Here’s what I get back from ChatGPT (I have shortened some of the output as indicated by “…”, I’m just trying to give you the major steps in the process). First, it will tell you a bit what is it is assuming you want it to do and what equipment it thinks you have. This is helpful for troubleshooting later or correcting it.
_____________________________________________________________
Here’s a Bash script that takes a reading from a BME280 sensor and publishing pressure, temperature, and humidity readings to the same MQTT topics:
๐ Assumptions:
• You're running this on a Raspberry Pi or Linux with:
o Python installed
o The BME280 connected via I²C (address 0x77)
o mosquitto-clients installed (mosquitto_pub available)
o A Python script available to get readings from the BME280 (provided below)
_____________________________________________________________
It then generated the script for me.
_____________________________________________________________
✅ Bash Script (bme280_mqtt.sh)
….
_____________________________________________________________
After giving me the script, it then told me what I need to do and any commands I need to enter. It will often describe highlights of what it has built for you as well as offer suggestions.
_____________________________________________________________
๐ Required Python Dependency
…
_____________________________________________________________
⏲️ Set to Run Every 5 Minutes
…
Would you like this to also log to file (e.g., pressure log) or calculate dew point like the Node-RED flow?
_____________________________________________________________
Next, I did everything it asked me to do in the steps above but I got some errors which I pasted into the prompt box so it could help me to troubleshoot. It can tell what I pasted in is an error, so I don’t need to describe the output I’m giving it, since it knows we are working on the script together.
pip3 install RPi.bme280 smbus2 error: externally-managed-environment
error: externally-managed-environment
…
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
hint: See PEP 668 for the detailed specification.
_____________________________________________________________
You're encountering this error because your Python environment is PEP 668-compliant, which means it prevents direct installation of Python packages into the system-managed Python environment to avoid breakage.
✅ Solution: Use a Python Virtual Environment
This is the safest and recommended approach.
…
_____________________________________________________________
๐ง Step-by-Step Fix:
…
_____________________________________________________________
It ended up that it needed to change some things in the script it wrote for me to work with its suggestions, so I asked it to do that.
update the script
_____________________________________________________________
Here’s your updated bme280_mqtt.sh Bash script that:
• Activates a Python virtual environment (~/bme280-env)
• Runs a Python block to collect BME280 sensor data
• Publishes it to MQTT topics
✅ Final Script: bme280_mqtt.sh
…
๐ฆ Install Instructions
…
Let me know if you'd like dew point calculation or InfluxDB integration added as well.
_____________________________________________________________
I like that it is always suggesting things and it assumes there are no issues. I’m still getting an error, so I paste it into the prompt box.
$ ./bme280_mqtt.sh Error: Connection refused
_____________________________________________________________
The Error: Connection refused you're seeing is coming from the mosquitto_pub commands, which indicates that the script is:
• Correctly gathering sensor data, but
• Failing to connect to your MQTT broker.
_____________________________________________________________
✅ Let's troubleshoot step-by-step:
...
_____________________________________________________________
I’m going to skip ahead after some back and forth troubleshooting after which I get it working.
_____________________________________________________________
…
Let me know if you'd like to add:
• Logging to file
• Dew point calculation
• InfluxDB support
• JSON output on MQTT topics
_____________________________________________________________
Now I decided I want to have it compute Dew point as well:
yes add logging to file and Dew point calculation
_____________________________________________________________
Great! Below is your enhanced Bash script with:
✅ New Features:
1. Logging to file (/home/pi/bme280_log.json)
2. Dew point calculation
๐ ️ Prerequisites:
…
๐ Full Script: bme280_mqtt.sh
…
๐งช Test It
…
_____________________________________________________________
And since everything works. I’m done. Here’s the final output on the dashboard. The script runs every 3 minutes and sends the data to the dashboard computer for display and graphing.
I hope this gives you some idea of what is possible with AI solutions like ChatGPT, Claude and DeepMind. I find that ChatGPT is the best for programming, and I like Claude for helping me do graphic oriented user interfaces like web dashboards and logos. I haven’t really played much with DeepMind since I find the other two quite capable of what I need.
We are not yet at the point where you can just type a line into the prompt box and tell any of these systems to write you a full program instantly, but they are getting better by the day. Who knows what will be possible in the future? What I do know is I have found that AI can help me to write programs quickly especially batch scripts that I used to spend hours on troubleshooting.
I encourage you to find a project you want to do with an LLM helping you to code and experiment. It is the best way to see what this technology can do for you. I have also learned a lot about programming since I now feel that I have a 24 hour a day private tutor helping me.
73
Comments
Post a Comment