ChatGPT – Mit KI zum Programmiererfolg - AZ-Delivery

The following article was made available to us by our guest author Niklas Heinzel:

ChatGPT is currently in the process. But what is ChatGPT actually and what is it good for? In this article, we will therefore clarify to what extent ChatGPT could be the proclaimed AI revolution or whether it is no more than an Alexa on steroids.

What is ChatGPT?

ChatGPT is a powerful language generator developed by Openai, a startup funded by Microsoft. It is based on a transformer model that was trained with large amounts of text data. This enables him to generate human-like answers to questions and requirements.

One of ChatGPT's most important areas of application is the creation of natural language processing (Natural Language Processing, NLP), for chatbots and virtual assistants. It can also be used to create automatically generated texts, such as blog entries or news articles.

Another interesting area of ​​application is the text of the text since ChatGPT read a text and creates a summary, as well as answers questions and even leads a conversation.

In our maker scene in particular, ChatGPT may be of great help, since with the help of which you can easily create and transform programming codes. In order to test the possibilities of the AI, we will deal with the following to what extent ChatGPT for DIY projects or similar.

How does ChatGPT work?

ChatGPT works through the use of neuronal networks, especially the transformer model. The transformer model consists of several layers of neurons (following the model of neural networks in the human brain), which are connected to each other and are therefore able to learn large amounts of text data.

The model is trained by entering an input request and a previous question. After analyzing the context, it generates an answer based on what it has learned.

An important component of ChatGPT is the use of so-called "attack mechanisms". These enable the model to take certain parts of the input into account and ignore them in order to generate the answer.

ChatGPT also uses several layers of neurons to process the input. Each layer is used to analyze various aspects of input, such as the semantic meaning of the words, the grammatical structures, and the connections between words.

After training, the model will be able to generate an answer to an input request by analyzing the context and selecting the best-to-match answer, based on the learned pattern.

ChatGPT weighing and disclaimer

One of the great strengths of ChatGPT is its ability to react to previous inputs and to have a conversation, which differentiates it from other generative models. It can also be used to correct typing errors and add missing information in text.

Although ChatGPT provides impressive performance, it is important to note that it can still make mistakes and that the quality of its answers depends on the quality of the training data. There can also be problems with the fairness and ethics of automatically generated texts, especially if they are used for fake messages or propaganda.

Implementation of a concrete project with ChatGPT

In the following, we will be approaching the skills of ChatGPT

First, let's start with a simple blink sketch and reading a SHT30 for the ESP8266:

“Create a code for the ESP8266, in which the internal LED flashes rhythmically and the SHT30 is read out. The temperature and humidity values ​​are to be output on the serial monitor. ”

Issue of ChatGPT (Program code):

#include <Wire.H>
#include <Adafruit_sensor.H>
#include <Adafruit_sht31.H>

#define LED 2

Adafruit_sht31 SHT31 = Adafruit_sht31();

void set up() {
  pin mode(LED, OUTPUT);
  Serial.Begin(115200);

  IF (!SHT31.Begin(0x44)) {
    Serial.print("Couldn't Find Sht31");
    while (1);
  }
}

void loop() {
  float temperature = SHT31.Reading temperature();
  float humidity = SHT31.readhumidity();

  Serial.print("Temperature:");
  Serial.print(temperature);
  Serial.print(" *C");

  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.print(" %");

  digital(LED, HIGH);
  delay(500);
  digital(LED, Low);
  delay(500);
}

The solution issued by ChatGPT is successful in the compiler test, is syntactically flawless, and is well-legible. In addition, the code works and meets the requirements. The measurement data are output on the serial monitor as well and the LED flashes rhythmically (see screenshot)

Let's go to ChatGPT again with a change request and see what the AI ​​can make of it: 

"Add the code to read out an LDR, which is read out via the integrated ADC of the ESP8266."

Issue of ChatGPT (Program code):

#include <Wire.H>
#include <Adafruit_sensor.H>
#include <Adafruit_sht31.H>

#define LED 2
#define LDR_PIN A0

Adafruit_sht31 SHT31 = Adafruit_sht31();

void set up() {
  pin mode(LED, OUTPUT);
  Serial.Begin(115200);

  IF (!SHT31.Begin(0x44)) {
    Serial.print("Couldn't Find Sht31");
    while (1);
  }
}

void loop() {
  float temperature = SHT31.Reading temperature();
  float humidity = SHT31.readhumidity();

  Serial.print("Temperature:");
  Serial.print(temperature);
  Serial.print(" *C");

  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.print(" %");

  intimately LDRValue = analogead(LDR_PIN);
  Serial.print("LDR Value:");
  Serial.print(LDRValue);

  digital(LED, HIGH);
  delay(500);
  digital(LED, Low);
  delay(500);
}

In the solution presented by ChatGPT, the existing code was expanded as desired to read out an LDRS (Light Dependent Resistor), which could also be successfully output on the serial monitor.

After relatively simple codes were possible, or the editing of those, we should confront ChatGPT with a higher number of elements to be controlled, which are not found in every tutorial of their complexity by the search engine.

“Create an ESP8266 code in which an SHT30 sensor and an LDR are read out. These values ​​should then be output on a 0.91 “large OLED, as well as on the serial monitor. The commands are to be outlined in individual functions and called up in the Void Loop. ”

At this complexity level slowly sneak up Smaller error One that also with little Programming knowledge could be remedied in C ++:

The Adafruit_SHT30.H library was used by ChatGPT, a library existing until 2021, which is now under the name adafruit_sht31.h. The name was changed due to the extension of the manufacturer Sensirion's product portfolio.

The library also offers downward compatibility under the newer SHT31, but shows what crucial Disadvantage ChatGPT has: the one (at the current time 02/23) Existing limitation on data before 2021, it does not make it possible to incorporate recent knowledge into the AI.

The second error in the program code consists of the declaration of the parameters that are responsible for the dimensions of the display. These should be with a 0.91 “large OLED (128, 32).

Despite these little Mancos, she is Performance of the AI ​​is remarkable, because most of the time programming is, for many to make existing code snippets into a To integrate the overall system and Compiler-compliant (according to the required syntax) to prepare. They are considerable Time savings possible If it is all about checking the code output for correctness.

With the help of the following inputs, I refined the code with ChatGPT a bit: 

  1. "Create the code instead of the Adafruit Sht30 Libary with the Adafruit Sht31 Libary."
  2. "Adapt the code for a 0.91" Large Oled display. "
  • “2 seconds should take place at the end of the program until the next measurement can be carried out. All displayed elements on the display must be smaller because they are not completely visible. ”
  1. “Before the program starts, a splash screen should be shown on the OLED display. Add this to the code. "

This gives us the following result, which can be seen, also due to compliance with "syntactic design rules", which significantly facilitate the reading of the code (Program code):

#include <Wire.H>
#include <Adafruit_sensor.H>
#include <Adafruit_sht31.H>
#include <Adafruit_ssd1306.H>

Adafruit_sht31 SHT31 = Adafruit_sht31();
Adafruit_ssd1306 display(128, 32, &Wire);

void set up() {
  Serial.Begin(115200);
  IF (! SHT31.Begin(0x44)) {
    Serial.print("Couldn't Find Sht31");
    while (1);
  }

  display.Begin(Ssd1306_switchcapvcc, 0x3c);
  display.Clear display();
  display.display();
  
  Showplashscreen();
}

void loop() {
  float temperature, humidity;
  intimately Lightlevel;

  getting temperature lumidity(&temperature, &humidity);
  Lightlevel = getlight level();

  display values(temperature, humidity, Lightlevel);
  Printvalues(temperature, humidity, Lightlevel);

  delay(2000);
}

void getting temperature lumidity(float *temperature, float *humidity) {
  *temperature = SHT31.Reading temperature();
  *humidity = SHT31.readhumidity();
}

intimately getlight level() {
  return analogead(A0);
}

void display values(float temperature, float humidity, intimately Lightlevel) {
  display.Clear display();
  display.SettextSize(0.5);
  display.SettextColor(White);

  display.setcursor(0, 0);
  display.print("Temp:");
  display.print(temperature);

  display.setcursor(0, 15);
  display.print("Humidity:");
  display.print(humidity);

  display.setcursor(0, 30);
  display.print("Light Level:");
  display.print(Lightlevel);

  display.display();
}

void Printvalues(float temperature, float humidity, intimately Lightlevel) {
  Serial.print("Temperature:" + String(temperature));
  Serial.print("Humidity:" + String(humidity));
  Serial.print("Light Level:" + String(Lightlevel));
}

void Showplashscreen() {
  display.Clear display();
  display.SettextSize(1);
  display.SettextColor(White);

  display.setcursor(25, 20);
  display.print("SHT31 & LDR");

  display.display();
  delay(2000);
}

The subsequent addition of a splash screen, which shows 2 seconds before the start of the "ShT31 & LDR" program, is certainly noteworthy and has positive functions. However, it is important to mention the addition of ChatGPT as such in the HMI (Human Machine Interface), otherwise only what is requested will be issued as such and the integration performance does not exist.

A very common possibility for expanding the project is the connection/ establishment of a web server on which the collected data could also be visualized. A simple version of this should therefore be implemented with ChatGPT in order to create incentives for you and your readers.

"Extend the code so that the data can be displayed on a dedicated web server. "

After some time, ChatGPT stopped issuing the code because it seems that some sort of maximum length of an output message was reached. Here it is enough simply with "Continue the code. "and you're on your way.

In addition to the constant error source of the wrong scaling of the display, the correct SHT31 library has also been added automatically in the x-th iteration. Re-creation of the response can also be achieved by using the button "regenerate response".

The result of the request is really impressive and concludes our small project with a suitable website:

The final code looks like this Program code):

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

Adafruit_SHT31 sht31 = Adafruit_SHT31();
Adafruit_SSD1306 display(128, 32, &Wire);

const char* sside = "SSID";
const char* password = "PASSWORD";

ESP8266WebServer server(80);

float temperature, humidity;
int lightLevel;

void setup() {
  Serial.start(115200);
  if (! sht31.start(0x44)) {
    Serial.println("Couldn't find SHT31");
    while (1);
  }

  display.start(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();
  
  showSplashScreen();

  WiFi.start(sside, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  server.he("/", handleRoot);
  server.start();
  Serial.println("Web server started");

  Serial.println();
  Serial.println("HTTP server started");
  Serial.print("Use this URL to connect:);
  Serial.print("http://");
  Serial.print(WiFi.localIP());
}

void loop() {
  getTemperatureHumidity(&temperature, &humidity);
  lightLevel = getLightLevel();

  displayValues(temperature, humidity, lightLevel);
  printValues(temperature, humidity, lightLevel);

  server.handleClient();

  delay(2000);
}

void getTemperatureHumidity(float *temperature, float *humidity) {
  *temperature = sht31.readTemperature();
  *humidity = sht31.readHumidity();
}

int getLightLevel() {
  return analogueRead(A0);
}

void displayValues(float temperature, float humidity, int lightLevel) {
  display.clearDisplay();

  
  display.setTextSize(0.25);
  display.setTextColor(WHITE);

  display.setCursor(0, 0);
  display.print("Temperature:");
  display.print(temperature);
  display.cp437(true);
  display.write(167);
  display.println("C");

  display.setCursor(0, 12);
  display.print(Humidity:);
  display.print(humidity);
  display.println(" %");

  display.setCursor(0, 23);
  display.print("Light Level:");
  display.println(lightLevel);

  display.display();
}

void printValues(float temperature, float humidity, int lightLevel) {
  Serial.println("Temperature: + String(temperature));
  Serial.println("Humidity: + String(humidity));
  Serial.println("Light Level: + String(lightLevel));
}

void showSplashScreen() {
  display.clearDisplay();
    display.setTextSize(2);
  display.setCursor(20, 20);
  display.println('SHT31, LDR');
  display.setTextSize(1);
  display.setCursor(20, 40);
  display.println("Data Display");
  display.display();
  delay(2000);
}

void handleRoot() {
  String html = "";
  html += "

Temperature:

 + String(temperature) + #8451;";
  html += 

Humidity:

 + String(humidity) + "%";
  html += 

Light Level:

 + String(lightLevel) + "";
  html += "";
  server.send(200, "text/html", html);
}

Other functions

Almost an infinite number of things are possible with ChatGPT. The applications shown here are only a very small section of what is possible with the help of artificial intelligence.

In our context, for example, inquiries about the code created are possible, such as the question "At what address can I call up the web server?". Here a solution is described and the function is described.

Conclusion - what can chat and how does it help us?

Openai's ChatGPT is a strongly trained language model that is able to generate human-like texts/codes/tables etc. and to answer questions. It can cover a variety of topics, including programming, technology, science, art, and much more.

However, ChatGPT cannot do everything a human programmer can do and it is also bound by his knowledge of the data records. It is unable to think creatively and develop new concepts on your own. It can also make mistakes and not answer all inquiries exactly, since it was only trained on the data that it saw during its development.

Nevertheless, ChatGPT can be a useful tool for electronics makers by quickly generating code snippets and providing instructions to implement certain projects. It can also save time and resources by quickly providing answers to questions without having to search for hours on the Internet.

Overall, ChatGPT can be a great support for electronics makers as long as they are aware that it is not perfect and that they still have to be carefully checked before using them in their projects.

I hope that with this article I was able to point out the opportunities & risks of ChatGPT or other Ki-based solutions and could therefore contribute to a weighing debate in the course of the diverse possibilities of these solutions. Technology does not always have to be the "all-in-one solution", it will not replace from one day to other people, rather it can increasingly support us and focus on people as a creative spirit.

Niklas Heinzel

Esp-8266Projekte für anfängerSensoren

6 Reacties

Andreas Wolter

Andreas Wolter

@Kai: ChatGPT kann online bei openai.com entweder als kostenlose oder kostenpflichtige Variante genutzt werden.
Ich ergänze den Link im Artikel. Danke für den Hinweis.

Grüße,
Andreas Wolter
AZ-Delivery Blog

Kai

Kai

Toller Artikel!!!
Ich würde dies gerne selbst ausprobieren.
Wo finde ich den von Ihnen verwendeten ChatGPT?

Hannes Ronzmeier

Hannes Ronzmeier

Hallo.
Also Programmiererfolg würde ich das jetzt nicht unbedingt nennen. Meiner Meinung nach, sollte man ChatGPT nicht als Google Ersatz verwenden, denn genau das passiert hier- Codeabschnitte werden meist von Github und Co hergneommen und aggregiert. ChatGPT kann nützlich sein um Dummy Daten zu generieren oder konkrete Fragen “Wie schließe ich I2C an” doch für konkrete Aufgaben ist derzeit noch zu instabil.
Viele Grüße

Andreas Wolter

Andreas Wolter

@Martin: ich gebe Ihnen Recht. Für jemanden, der mit dem Programmieren gerade erst beginnt, kann ChatGPT etwas hinderlich sein und die Lernkurve stark abflachen lassen. Ich habe es selbst auch ausprobiert. Zuerst einfache kleine Arduino Sketches. Theoretisch werden dann nur die Beispielsketches dargestellt. Am Beispiel Blink habe ich das gesehen. Es ist 1:1 der Code aus dem Beispiel. Ich nutze ein optimiertes Blink mit einer boolschen Variable, statt des redundanten Codes. Ich habe ChatGPT gebeten, es zu optimieren. Es hat nicht direkt gewusst wie. Ich habe dann nur den Hinweis mit dieser Variablen gegeben und schon kam der Quellcode raus, den ich auch nutze. Das könnte ein Anfänger noch nicht unbedingt wissen. Wenn man ChatGPT die richtigen Fragen stellt, kann das gehen. Es fehlt aber jemand, der auf die Fehler achtet, die daraus entstehen.

Als zweiten Test habe ich mit Visual Studio ein Windows Tool mit grafischer Nutzeroberfläche damit programmieren wollen. Ich habe das gewählt, da ich das noch nie vorher gemacht hatte. Es hat sehr viele Anläufe gebraucht und am Ende musste ich es eigentlich selbst umsetzen. Beim Einstieg hat es mir geholfen. Später bei der Erweiterung des Programms hat es ständig den Kontext verloren. Es sollte Teile verändern. Der Code passte dann aber nicht mehr zum vorherigen gesamten Quelltext. Obwohl ChatGPT Kontext beachten sollte. Am Ende habe ich es fertiggestellt. ChatGPT habe ich dann nur noch verwendet, wenn ich Hinweise brauchte. Ich kenne die .NET Bibliotheken nicht. Dabei hat es mir geholfen.

Mein eigenes Fazit ist: wenn man ChatGPT alles machen lassen würde, würde man selbst nicht mehr überlegen, wie man sein Problem löst und wenn das Programm zu komplex wird, blickt man nicht mehr durch. Ähnlich wie in der Uni bei den Gruppenaufgaben. Wenn ein anderes Gruppenmitglied den Code geschrieben hat, kannte man ihn nicht, musste ihn trotzdem erklären können. Daran hat es mich erinnert.

Grüße,
Andreas Wolter
AZ-Delivery Blog

Frank

Frank

Hallo & ein sehr großes Lob für diesen Artikel! Er zeigt, für was man wie (Chat-)KI verwennden kann, ohne einfach andere Artikel und “KI-Gewäsch” abzuschreiben … bitte gerne mehr von solcher KI, Danke im Voraus! !!

Martin

Martin

Ich würde trotzdem dazu raten, sich mit dem Programmieren von Microcode auseinanderzusetzen und nicht einfach ChatGPT alles schreiben zu lassen. Der ausgegeben Code kann teilweise fatale Fehler aufweisen und muss immer noch einen Reviewprozess durchlaufen. Das Lernen von Konzepten wie CI/CD, oder auch Cleancode sollte nicht vernachlässigt werden. Für Einsteiger in die Programmierung sehe ich den Gebrauch von ChatGPT als kritisch an, weil hierdurch der Lernprozess eingeschränkt werden kann. Für Entwickler mit mehr Erfahrung jedoch sehe ich ChatGPT ebenfalls als ein sehr nützliches Hilfsmittel.

Laat een reactie achter

Alle opmerkingen worden voor publicatie gecontroleerd door een moderator

Aanbevolen blogberichten

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery