With billions of {dollars} invested in AI analysis and improvement. 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 revolutionary addition, customers can count on extra dynamic code responses, bridging the hole between pure language processing and actionable programming options.
Do not get me flawed! ChatGPT has all the time been spectacular at writing code. However its capabilities have actually skyrocketed with the addition of a code interpreter. So right here at Robu! We had been wanting to take a look at its new capabilities, and what higher approach to try this apart 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 Attention-grabbing proper! Let’s get proper into it.
Can chat GPT write code for me?
Chat GPT just isn’t particularly designed to put in writing code however can help within the course of. Utilizing machine studying algorithms, Chat GPT can analyze and perceive code snippets and generate new code primarily based 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 features, ensures cross-platform accessibility, and simplifies integrations with Google’s ecosystem.
Seamless Information Logging: Google Sheets provides an easy and strong mechanism for information logging, eliminating the necessity for exterior third-party providers.
Superior Information Manipulation: With its suite of features, analyzing and manipulating collected information turns into a streamlined course of.
Cross-Platform Accessibility: Google Sheets helps entry from each desktop and cellular platforms, making certain steady monitoring and updates on the go.
Integration Flexibility: Customized features and integrations with different Google apps will be effortlessly achieved by way of 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 put in writing 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 identify 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 instructed chat GPT that there must be sheet_id and sheet_name parameters “within the app script there must be an authentication parameter like sheet identify and sheet id” so it gave me the next response.
With that, I used to be proud of what chat GPT has offered to us so I went forward and made the {hardware} circuit.
Creating the Schematic by Trying on the Code
Nicely, if we had been to do that code in a straight ahead approach, we’d have made the schematic first after which we’d have achieved the {hardware} circuit then will probably 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 related to the GPIO4 of the ESP32. As soon as the {hardware} schematic was achieved it could appear 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 possibly can see that I used to be very clear that I want correct instruction on how you can 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 how you can 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 offered code. And do not forget to stick in your Sheet ID and Sheet Identify.
Now you should click on on the Settings Icon and click on on Internet app
When you click on on a Internet app, a brand new window will open, now within the description give your app a identify. And most significantly you should change the Who has entry to Anybody. As soon as achieved you should click on on the Deploy button.
Then it’s a must to authorize your app with a google account and if in case you have achieved every little thing appropriately you can be offered with a internet app URL. However for some motive 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 possibly can comply with 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 allure and simply by clicking on it you possibly can see the information 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 under. You’ll be able to 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 use the given immediate to try this.
Google App Script Code
var SHEET_NAME = ‘Sheet 1’; // Change to your sheet identify
var SHEET_ID = ‘YOUR_SHEET_ID’; // Change to your sheet ID
perform doGet(e){
var outcome=”Failed”; // default failure message
// Verify if the offered 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]);
outcome=”Okay”; // success message
} catch(e){
outcome=”Error: ” + e.toString();
}
}
return ContentService.createTextOutput(outcome);
}
Arduino Nano ESP32 Code
#embody <WiFi.h>
#embody <HTTPClient.h>
#embody “DHT.h”
#outline DHTPIN 4 // Outline which pin the DHT22 is related 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 shipped to Google Sheets for simple monitoring. ChatGPT helped us write the code for the ESP32 machine and Google Sheets. We had a bit hassle setting it up, however we figured it out by following steps. General, we mixed AI and {hardware} to create a cool information tracker!