With billions of {dollars} invested in AI analysis and growth. AI is evolving day-after-day, frequently reshaping the boundaries of what is potential. That’s merely why the newest model of ChatGPT now comes outfitted with an enhanced Code Interpreter. With this progressive addition, customers can count on extra dynamic code responses, bridging the hole between pure language processing and actionable programming options.
Do not get me mistaken! ChatGPT has at all times been spectacular at writing code. However its capabilities have actually skyrocketed with the addition of a code interpreter. So right here at Robu! We have been desirous to take a look at its new capabilities, and what higher manner to try this aside from making a venture with it proper? So, precisely as our title suggests, we’ll develop an ESP32-based information logger utilizing Google Sheets as our backend. for all code written by ChatGPT and its enhanced code interpreter. Sounds Fascinating proper! Let’s get proper into it.
Can chat GPT write code for me?
Chat GPT just isn’t particularly designed to write down code however can help within the course of. Utilizing machine studying algorithms, Chat GPT can analyze and perceive code snippets and generate new code based mostly on the enter it receives.
What’s a code interpreter?
Code interpreter (CI) is an official ChatGPT plugin by OpenAI that pushes the boundaries of what is potential with AI by enabling information analytics, picture conversions, code enhancing, and rather more.
Benefits of Utilizing Google Sheet As a Information Server
Leveraging Google Sheets as a knowledge server provides seamless information logging with out third-party dependencies, permits superior analytics with built-in capabilities, ensures cross-platform accessibility, and simplifies integrations with Google’s ecosystem.
Seamless Information Logging: Google Sheets provides a simple and strong mechanism for information logging, eliminating the necessity for exterior third-party companies.
Superior Information Manipulation: With its suite of capabilities, analyzing and manipulating collected information turns into a streamlined course of.
Cross-Platform Accessibility: Google Sheets helps entry from each desktop and cell platforms, guaranteeing steady monitoring and updates on the go.
Integration Flexibility: Customized capabilities and integrations with different Google apps will be effortlessly achieved through Google Scripts, enhancing its applicability.
Enhanced Information Visualization: With conditional formatting, information visualization, monitoring, and evaluation are considerably enhanced, permitting for clear and fast insights.
Prompting Chat GPT to Write us the ESP32 and AppScript Code
Now what we are going to do is immediate chat GPT to write down us the app script code however earlier than that, we’re going to click on on GPT-4 Mannequin and we are going to choose code interpreter from the choices.
Now we are going to give our immediate. “Write me an ESP32 code for Arduino IDE to get temperature and humidity information from the DHT22 sensor and ship that information to Google Sheets. Additionally, give me the Google App Script Code and an in depth directions”
The code interpreter provides me the above code for the Google app script and simply by wanting on the code I can clearly see that the sheet title and the sheet ID are lacking from the code.
As for the Arduino ESP32 code, I used to be very shocked to see that it was completely error-free.
Now I advised chat GPT that there needs to be sheet_id and sheet_name parameters “within the app script there needs to be an authentication parameter like sheet title and sheet id” so it gave me the next response.
With that, I used to be pleased with what chat GPT has supplied to us so I went forward and made the {hardware} circuit.
Creating the Schematic by Wanting on the Code
Properly, if we have been to do that code in a straight ahead manner, we might have made the schematic first after which we might have finished the {hardware} circuit then can be doing our code. However for this venture, we’re going to assume Chat GPT is aware of every little thing and we are going to take its judgment and make the {hardware} by wanting on the code.
Within the Schematic the DHT22 is linked to the GPIO4 of the ESP32. As soon as the {hardware} schematic was finished it might seem like what’s proven above.
And right here is the piece of code the place the chat GPT is telling us to attach the DHT22 to GPIO4 of the ESP32 module.
The precise {hardware} circuit appears to be like just like the picture above.
Deploying The Google App Script
In the event you go above and examine the immediate that I’ve given to it, you may see that I used to be very clear that I would like correct instruction on find out how to deploy the code. And what I’ve bought is proven above. An epic fail from chat GPT, so at this level I had to make use of my googling expertise to determine find out how to deploy the code. So, this is what I discovered,
Go to Extension and go to Apps Script. The brand new APP Script window will open. Now paste within the supplied code. And remember to stick in your Sheet ID and Sheet Identify.
Now it’s good to click on on the Settings Icon and click on on Net app
When you click on on a Net app, a brand new window will open, now within the description give your app a title. And most significantly it’s good to change the Who has entry to Anybody. As soon as finished it’s good to click on on the Deploy button.
Then you must authorize your app with a google account and when you have finished every little thing appropriately you may be introduced with a net app URL. However for some purpose it did not work for me on the primary attempt to I needed to undergo the next steps to make it work!
If the API additionally just isn’t working for you, you may observe the steps. Go to deploy and new deployment and now choose API Executable and click on on Deploy button, now copy the given API, for me this API labored like a attraction and simply by clicking on it you may see the info onto your google sheets.
Code for Arduino Nano ESP32 and Google App Script
The full code for Arduino Nano ESP32 and Google App Script is written beneath. You may simply copy-paste it in your venture and it ought to work with none errors, however if you wish to take a look at the capabilities of Chat GPT you should utilize the given immediate to try this.
Google App Script Code
var SHEET_NAME = ‘Sheet 1’; // Change to your sheet title
var SHEET_ID = ‘YOUR_SHEET_ID’; // Change to your sheet ID
perform doGet(e){
var end result=”Failed”; // default failure message
// Examine if the supplied parameters match our anticipated values
if(e.parameter.sheetname == SHEET_NAME && e.parameter.sheetid == SHEET_ID) {
strive {
var doc = SpreadsheetApp.openById(SHEET_ID);
var sheet = doc.getSheetByName(SHEET_NAME);
var newRow = sheet.getLastRow() + 1;
var rowData = [];
rowData[0] = new Date(); // Timestamp
rowData[1] = e.parameter.temperature; // Temperature from DHT22
rowData[2] = e.parameter.humidity; // Humidity from DHT22
sheet.getRange(newRow, 1, 1, rowData.size).setValues([rowData]);
end result=”Okay”; // success message
} catch(e){
end result=”Error: ” + e.toString();
}
}
return ContentService.createTextOutput(end result);
}
Arduino Nano ESP32 Code
#embody <WiFi.h>
#embody <HTTPClient.h>
#embody “DHT.h”
#outline DHTPIN 4 // Outline which pin the DHT22 is linked to
#outline DHTTYPE DHT22
// WiFi settings
const char* ssid = “YOUR_SSID”;
const char* password = “YOUR_PASSWORD”;
// Google Script Deployment URL
String GAS_URL = “YOUR_GOOGLE_SCRIPT_URL”;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.start(115200);
dht.start();
WiFi.start(ssid, password);
whereas (WiFi.standing() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Linked to WiFi”);
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println(“Did not learn from DHT sensor!”);
return;
}
sendDataToGoogleSheet(temperature, humidity);
delay(60000); // Ship information each 1 minute
}
void sendDataToGoogleSheet(float temperature, float humidity) {
if(WiFi.standing()== WL_CONNECTED){
HTTPClient http;
String url = GAS_URL + “?temperature=” + String(temperature) + “&humidity=” + String(humidity);
http.start(url);
int httpResponseCode = http.GET();
if(httpResponseCode>0){
String response = http.getString();
Serial.println(response);
} else {
Serial.print(“Error on sending POST: “);
Serial.println(httpResponseCode);
}
http.finish();
} else {
Serial.println(“Error in WiFi connection”);
}
}
Conclusion
On this venture, we have leveraged ChatGPT’s superior code interpreter to create an ESP32-based information logger with a DHT22 sensor, using Google Sheets for seamless information storage. This information is distributed to Google Sheets for simple monitoring. ChatGPT helped us write the code for the ESP32 machine and Google Sheets. We had slightly hassle setting it up, however we figured it out by following steps. Total, we mixed AI and {hardware} to create a cool information tracker!