Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:21 02 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : AI research project for this month

     Page 4 of 4    
Author Message
stef123
Regular Member

Joined: 25/09/2024
Location: United Kingdom
Posts: 89
Posted: 09:57am 27 May 2025
Copy link to clipboard 
Print this post

Thats another and huge Problem with LLMs. If there isn't a large code base with which to train an LLM, it can't respond to that code.

The best thing to do, in principle, would be to invent a specific LLM code, which would then be run locally through an interpreter or cross-compiler - instead of putting the cart before the horse.

Recently i also ran into a problem which my LLMs couldn´t solve. I understand C++ and so by that Arduino Code - up to a certain point, but i don't like to write it because of the finicky upper/lowercase Syntax and other weird constructions. Props to the People who write it with joy, i would go crazy. So i am somehow a noob in this field -  no problem for me , on the other hand i can write for example ARM-Assembly which in turn some others can't.


So in Arduino i was trying to put together a string including decimals and floats from uint8_t and float variables, by using snprintf , which eventually exits an STM32 on one of its serial ports. It sucessfully printed out the chars and also decimals, but no floats, LLMs were thinking here and there, coming up with crazy solutions, but nothing usable. I was already at the point where i was about to give up, because it didn't make any sense anymore.

The final Solution was simple: The Problem was the Library i've used, newlib-nano, which doesn't fully include handling of floats in order to keep the code small (if 4K counts on a 128K Micro).

So the LLMs - which i previously told on which Micro i am and which Platform i was using - could -in theory- easily figure out that this could be related to a wrong library. but didn´t get it. If i could ask an LLM -directly- if a wrong library could be the issue, then they would deliver the correct answer: Float is disabled by default - or use dtostrf.

Thats a key problem: In theory they "know" the answer, but don´t get the link, because nobody told them to create a Link between A and B, neither by hand, or by training data.
Edited 2025-05-30 14:47 by stef123
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3348
Posted: 10:57pm 04 Jun 2025
Copy link to clipboard 
Print this post

"AI-generated code could expand the pool from 30 million to a billion developers, unlocking personalised software everywhere."

Exponential View
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3348
Posted: 07:28pm 28 Jun 2025
Copy link to clipboard 
Print this post

English as a programming language

I've written maybe 3 very simple Python programs in my life, and haven't touched it in years. But apparently python is the programming language of AI.

In Google Gemini, I made this request:

Please produce python code for a raspberry pi which will read a file containing lines like the following one and produce a line chart graph with 6 lines labeled "Upper", "Middle", "South", "Lower", "Side", and "East": 

250628144138  14.8  223 15.1 9.8  207 21.2 10.5  238 22.7 8.8  136 15.4 10.2  334 32.8 9.7  184 18.9

Data items are separated by one or more spaces. The 7th and 8th characters in the first data item are the hour of the day ("00" - "23") and the 9th and 10th are the time in minutes. These make up the horizontal axis of the graph. Note that the horizontal spacing must account for 60 minutes to the hour, not 100.

The numbers to be plotted for each time slot are the 3rd, 6th, 9th, 12th, 15th, and 18th data items.

The file to be read will be named "/home/nn/panels.txt". The output file will be named "/home/nn/panels.html".


I have 6 mini solar panels placed variously on the front of my barn, nominal 18V max, less than 2-3 watts. I want to chart production over the course of a day so that I can understand shading over time. It has been almost totally overcast today, with a short period of very weak sun.

Here is the code which Gemini produced:

import plotly.graph_objects as go

# --- Configuration ---
# Input file containing the data
input_file_path = "/home/nn/panels.txt"

# Output HTML file for the graph
output_file_path = "/home/nn/panels.html"

# --- Data Processing ---

# Lists to store the parsed data from the file
# The x_axis will store time in a format Plotly understands (HH:MM)
x_axis_times = []

# Dictionaries to hold the data for each of the 6 lines
plot_data = {
   "Upper": [],
   "Middle": [],
   "South": [],
   "Lower": [],
   "Side": [],
   "East": []
}

print(f"Attempting to read data from: {input_file_path}")

try:
   with open(input_file_path, 'r') as f:
       for line_num, line in enumerate(f, 1):
           # Skips empty lines
           if not line.strip():
               continue

           # Split the line into parts. Handles one or more spaces.
           parts = line.split()

           # A valid line must have at least 18 data items
           if len(parts) < 18:
               print(f"Warning: Skipping malformed line #{line_num}. Not enough data items.")
               continue

           try:
               # --- 1. Extract Time for the X-axis ---
               timestamp_str = parts[0]
               if len(timestamp_str) < 10:
                   print(f"Warning: Skipping malformed line #{line_num}. Timestamp is too short.")
                   continue
               
               # Extract hour (characters 7-8) and minute (characters 9-10)
               hour = int(timestamp_str[6:8])
               minute = int(timestamp_str[8:10])
               
               # Format as "HH:MM". This ensures the chart handles time correctly
               # (e.g., it knows 60 minutes are in an hour).
               x_axis_times.append(f"{hour:02d}:{minute:02d}")

               # --- 2. Extract Data for the Y-axis ---
               # The values to be plotted are the 3rd, 6th, 9th, 12th, 15th, and 18th items.
               # Python list indices are 0-based, so we access parts[2], parts[5], etc.
               plot_data["Upper"].append(float(parts[2]))
               plot_data["Middle"].append(float(parts[5]))
               plot_data["South"].append(float(parts[8]))
               plot_data["Lower"].append(float(parts[11]))
               plot_data["Side"].append(float(parts[14]))
               plot_data["East"].append(float(parts[17]))

           except (ValueError, IndexError) as e:
               print(f"Warning: Skipping malformed line #{line_num}. Error processing data: {e}")
               continue

except FileNotFoundError:
   print(f"Error: The input file was not found at {input_file_path}")
   print("Please make sure the file exists and the path is correct.")
   exit()

# --- Graph Creation ---

if not x_axis_times:
   print("Error: No valid data was read from the file. Cannot generate a graph.")
   exit()
   
print(f"Successfully processed {len(x_axis_times)} data points.")
print("Generating the line chart...")

# Create a new figure
fig = go.Figure()

# Add each of the 6 lines (traces) to the figure
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["Upper"], mode='lines', name='Upper'))
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["Middle"], mode='lines', name='Middle'))
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["South"], mode='lines', name='South'))
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["Lower"], mode='lines', name='Lower'))
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["Side"], mode='lines', name='Side'))
fig.add_trace(go.Scatter(x=x_axis_times, y=plot_data["East"], mode='lines', name='East'))

# --- Final Touches ---

# Update the layout with titles and axis labels
fig.update_layout(
   title='Panel Data Readings Over Time',
   xaxis_title='Time of Day (HH:MM)',
   yaxis_title='Data Value',
   legend_title='Panel Location',
   font=dict(
       family="Courier New, monospace",
       size=14,
       color="RebeccaPurple"
   )
)

# By providing time as "HH:MM" strings, Plotly automatically sets the
# x-axis type to 'category' or 'date', correctly spacing the time values
# and solving the "60 minutes per hour" requirement.

# --- Output ---

# Write the figure to an HTML file
try:
   fig.write_html(output_file_path)
   print(f"Success! Graph has been saved to: {output_file_path}")
except Exception as e:
   print(f"Error: Could not write the output file. {e}")


I changed only the paths of the input and output files to fit my Pi.

Here is my data for the 2+ hours I had the program working (6 INA226 current monitors calculating current through 12V-24V LED modules being read by an ESP32-C3Supermini):

250628134452  14.9   230 15.4 9.8   212 21.6 10.5   249 23.6 8.8   134 15.2 10.2   336 32.9 9.8   188 19.2
250628134752  14.5   205 14.2 9.7   194 19.9 10.4   220 21.1 8.8   125 14.2 10.1   293 29.1 9.7   172 17.7
250628135254  14.6  212 14.5 9.8  199 20.4 10.4  223 21.3 8.8  126 14.3 10.1  287 28.5 9.7  177 18.2
250628135554  14.5  206 14.2 9.7  193 19.8 10.4  219 21.0 8.8  125 14.2 10.1  293 29.1 9.7  172 17.7
250628135854  14.2  190 13.3 9.7  180 18.5 10.4  204 19.7 8.8  120 13.6 10.0  282 28.1 9.7  160 16.5
250628140154  13.7  161 11.7 9.6  156 16.1 10.3  177 17.2 8.7  105 12.1 10.0  261 26.2 9.6  139 14.5
250628140454  14.0  175 12.5 9.7  166 17.2 10.4  193 18.6 8.7  108 12.3 10.0  279 27.8 9.6  148 15.3
250628140754  14.2  187 13.2 9.7  176 18.2 10.4  205 19.7 8.8  118 13.4 10.1  301 29.8 9.7  157 16.2
250628141054  14.0  176 12.5 9.7  168 17.3 10.4  193 18.7 8.8  110 12.6 10.0  276 27.5 9.6  149 15.4
250628141354  14.4  201 13.9 9.7  190 19.4 10.4  216 20.7 8.8  118 13.5 10.1  289 28.7 9.7  167 17.3
250628141654  14.8  226 15.2 9.8  211 21.5 10.5  237 22.6 8.8  132 14.9 10.1  310 30.6 9.8  186 19.1
250628141954  14.6  211 14.5 9.8  198 20.3 10.5  224 21.4 8.8  127 14.4 10.1  308 30.5 9.7  177 18.1
250628142254  15.1  243 16.1 9.8  226 22.9 10.6  255 24.2 8.8  140 15.8 10.2  344 33.7 9.8  201 20.5
250628142724  16.0  307 19.2 10.0  288 28.7 10.7  321 29.9 8.9  178 19.9 10.4  424 40.8 10.0  257 25.8
250628143024  16.1  312 19.4 10.0  293 29.3 10.8  327 30.4 8.9  178 19.9 10.4  414 39.9 10.0  262 26.3
250628143324  16.0  308 19.2 10.0  291 29.0 10.8  330 30.6 8.9  182 20.3 10.4  420 40.4 10.0  259 26.0
250628143624  15.3  259 16.9 9.9  242 24.5 10.6  276 26.0 8.9  156 17.6 10.3  378 36.8 9.8  216 21.9
250628144438  14.2  187 13.2 9.7  178 18.3 10.4  203 19.6 8.8  119 13.5 10.1  293 29.1 9.7  158 16.3
250628144738  14.0  177 12.6 9.7  170 17.5 10.3  192 18.5 8.8  112 12.8 10.0  276 27.5 9.6  150 15.6
250628145038  13.6  154 11.3 9.6  150 15.7 10.3  170 16.5 8.7  101 11.5 9.9  242 24.3 9.6  134 14.0
250628145338  13.8  164 11.9 9.6  159 16.5 10.3  178 17.3 8.7  104 11.9 9.9  245 24.6 9.6  141 14.7
250628145638  14.0  176 12.6 9.7  169 17.5 10.3  188 18.2 8.8  112 12.7 10.0  253 25.3 9.6  150 15.6
250628145938  13.6  153 11.3 9.6  150 15.6 10.3  167 16.3 8.7  102 11.7 9.9  227 22.9 9.6  134 14.0
250628150238  13.3  138 10.4 9.6  137 14.3 10.2  152 14.9 8.7   94 10.7 9.8  208 21.1 9.5  122 12.7
250628150538  12.9  122 9.4 9.5  123 12.9 10.1  136 13.4 8.7   85 9.8 9.8  190 19.4 9.5  109 11.5
250628150838  12.8  113 8.9 9.5  115 12.1 10.1  126 12.5 8.7   79 9.1 9.7  172 17.7 9.5  103 10.9
250628151138  12.8  116 9.0 9.5  118 12.4 10.1  128 12.7 8.7   79 9.1 9.7  165 17.0 9.5  105 11.1
250628151438  13.3  139 10.4 9.6  138 14.4 10.2  152 14.8 8.7   89 10.3 9.8  193 19.7 9.6  123 12.8
250628151738  13.7  159 11.6 9.6  155 16.1 10.3  173 16.8 8.7  100 11.5 9.9  225 22.8 9.6  137 14.3
250628152038  13.9  171 12.3 9.7  164 17.0 10.3  186 18.0 8.8  108 12.4 10.0  254 25.5 9.6  146 15.2
250628152338  13.9  172 12.3 9.7  166 17.2 10.3  186 18.0 8.8  109 12.5 10.0  251 25.2 9.6  148 15.3
250628152638  14.1  184 13.0 9.7  176 18.1 10.4  197 19.0 8.8  115 13.1 10.0  264 26.4 9.7  156 16.2
250628152938  14.2  187 13.2 9.7  179 18.4 10.4  197 19.0 8.8  116 13.3 10.0  260 26.1 9.7  159 16.4
250628153238  14.0  177 12.7 9.7  171 17.6 10.3  189 18.3 8.8  112 12.8 10.0  251 25.2 9.7  152 15.8
250628153538  13.5  148 11.0 9.6  146 15.2 10.2  161 15.8 8.7   99 11.3 9.9  219 22.2 9.6  130 13.6
250628153838  13.0  124 9.5 9.5  125 13.1 10.1  137 13.5 8.7   85 9.8 9.8  184 18.9 9.5  111 11.7
250628154138  12.9  120 9.3 9.5  122 12.8 10.1  132 13.0 8.7   82 9.4 9.7  174 17.9 9.5  108 11.4
250628154438  13.1  128 9.8 9.5  128 13.4 10.2  141 13.9 8.7   87 10.0 9.8  193 19.7 9.5  114 12.0
250628154738  12.7  109 8.6 9.5  112 11.8 10.1  124 12.2 8.6   77 8.9 9.7  175 17.9 9.5  100 10.5
250628155038  12.4   96 7.8 9.4  100 10.6 10.0  111 11.0 8.6   70 8.1 9.7  154 16.0 9.4   89 9.4


It ran with no changes. I copied the output html file to /var/www/html, and it immediately displayed when I entered the URL:



I am very impressed. It no doubt would have taken me many hours to produce this chart using MMBasic DOS or MMB4L or lua or php. All I did was provide a sufficiently complete specification and some data. I like that it was able to pick out the data from my saying use the 3rd, 6th, 9th, 12th, 15th, and 18th words in each line.

(Now if I can just teach it to code using MMB4L.)
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 4 of 4    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025