[ad_1]
With billions of {dollars} invested in AI analysis and improvement. AI is evolving day-after-day, frequently reshaping the boundaries of what is doable. That’s merely why the newest model of ChatGPT now comes geared up with an enhanced Code Interpreter. With this modern addition, customers can anticipate extra dynamic code responses, bridging the hole between pure language processing and actionable programming options.
Do not get me improper! ChatGPT has all the time been spectacular at writing code. However its capabilities have really skyrocketed with the addition of a code interpreter. So right here at Robu! We have been desperate to check its new capabilities, and what higher method to try this aside from making a challenge 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 is just not 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 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 doable with AI by enabling information analytics, picture conversions, code modifying, and far more.
Benefits of Utilizing Google Sheet As a Knowledge Server
Leveraging Google Sheets as a knowledge server presents 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 Knowledge Logging: Google Sheets presents an easy and strong mechanism for information logging, eliminating the necessity for exterior third-party companies.
Superior Knowledge 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 cell platforms, making certain steady monitoring and updates on the go.
Integration Flexibility: Customized features and integrations with different Google apps might be effortlessly achieved through Google Scripts, enhancing its applicability.
Enhanced Knowledge 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 offers me the above code for the Google app script and simply by trying 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 stunned to see that it was completely error-free.
Now I instructed 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 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 Wanting on the Code
Effectively, if we have been to do that code in a straight ahead method, we might have made the schematic first after which we might have achieved the {hardware} circuit then shall be doing our code. However for this challenge, 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 trying 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 will appear to be 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 seems to be just like the picture above.
Deploying The Google App Script
When you go above and test the immediate that I’ve given to it, you’ll be able to see that I used to be very clear that I want correct instruction on methods 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 methods 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 offered code. And do not forget to stick in your Sheet ID and Sheet Identify.
Now it’s essential 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 it’s essential change the Who has entry to Anybody. As soon as achieved it’s essential click on on the Deploy button.
Then it’s a must to authorize your app with a google account and when you have achieved every little thing accurately you may be offered with a internet app URL. However for some motive it did not work for me on the primary try to I needed to undergo the next steps to make it work!
If the API additionally is just not working for you, you’ll be able to 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’ll be able to 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 challenge and it ought to work with none errors, however if you wish to check 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 end result=”Failed”; // default failure message
// Test if the offered parameters match our anticipated values
if(e.parameter.sheetname == SHEET_NAME && e.parameter.sheetid == SHEET_ID) {
attempt {
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
#embrace <WiFi.h>
#embrace <HTTPClient.h>
#embrace “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(“Didn’t 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 challenge, 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 straightforward monitoring. ChatGPT helped us write the code for the ESP32 machine and Google Sheets. We had a little bit bother setting it up, however we figured it out by following steps. General, we mixed AI and {hardware} to create a cool information tracker!
[ad_2]