Serial Monitor Output to Google Sheets

Hello! This is a project my group is doing in our high school engineering class. We are trying to connect our serial monitor output to Google Sheets so we don't just have to copy and paste it from the serial monitor. I put part of the example code into the main code we are using, and I also tried to run just the example code, and both did not work, saying this:


I looked in the files and it shows "#include <Wifi.h>", but somehow it doesn't work.
I am using this:

(by the way GitHub is restricted for our school so I can't see the page)
Do you know how to fix the wifi.h thingy?

Looks like you're missing a library. Do you know how to locate the library? Did you download it at home but not at school, for example? Is the library one of those managed by Library Manager, in the IDE? There's so much we don't know about your particular situation, that's about all I can say.

I do not know which library I'm supposed to use, but I did include the GSheet32 library and it automatically put in "#include ". I also looked in the file and opened another file called GSheet32.cpp and that is where the error is coming from. The whole project is basically using a Huskylens camera for Arduino with an Arduino Mega board and getting it to track an object (our end goal is to track a soccer ball and develop a heat map for goalie training), which we are then trying to stream the data from the serial monitor output onto Google Sheets so it can be moved into MatLab (which we already figured out how to do the Matlab portion). There are also 2 pushbuttons that allow us to manually input whether the object (in this case the soccer ball) was blocked or not. If you know a better way to live stream the data from the serial monitor into Google Sheets, then I will do it instead of this, because I can't get past the Wifi.h error. If not, then I hope this information helps.


This code below is the GSheet32.cpp:
#include "GSheet32.h"
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;
WiFiClient client;
GSheet32::GSheet32(String GAS_ID){
    _GAS_ID = GAS_ID;
}

void GSheet32::connectWiFi(const char* ssid, const char* pass){
    _ssid = ssid;
    _pass = pass;

    WiFi.begin(_ssid, _pass);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
    Serial.println();
    Serial.print("Succes!! Connect to : "+WiFi.SSID());
}

void GSheet32::sendData(String colC){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE, String colF){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE+"&value4="+colF;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE, String colF, String colG){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE+"&value4="+colF+"&value5="+colG;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::clearData(){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?clearData=true";
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}
#include "GSheet32.h"
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;
WiFiClient client;
GSheet32::GSheet32(String GAS_ID){
    _GAS_ID = GAS_ID;
}

void GSheet32::connectWiFi(const char* ssid, const char* pass){
    _ssid = ssid;
    _pass = pass;

    WiFi.begin(_ssid, _pass);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
    Serial.println();
    Serial.print("Succes!! Connect to : "+WiFi.SSID());
}

void GSheet32::sendData(String colC){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE, String colF){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE+"&value4="+colF;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::sendData(String colC, String colD,String colE, String colF, String colG){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?value1="+colC+"&value2="+colD+"&value3="+colE+"&value4="+colF+"&value5="+colG;
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

void GSheet32::clearData(){
    String url = "https://script.google.com/macros/s/" + _GAS_ID + "/exec?clearData=true";
    http.begin(url.c_str()); //Specify the URL and certificate
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();
    String payload;
    if (httpCode > 0){
      payload = http.getString();
     Serial.println(httpCode);
     Serial.println(payload);
     }else {
     Serial.println("Failed");
    }
        
     http.end();
}

(I forgot to add the first 3 lines in the last reply (those lines include the Wifi.h thingy))

Are you using the Arduino Mega 2560 AVR board? If so, you don't have wifi and that library won't be available. It looks like that project was for an ESP8266 or ESP32.

oh crap you're right. Do you have any other ways to take data live from the serial monitor and put it in google sheets? could I use an arduino uno instead?

An Uno board doesn't have Wifi either. You don't need the Arduino Serial Monitor to capture the data. Any terminal program will work as well (Teleterm, etc.) and those programs allow you to save the output to a file (locally on your PC) which may be an easy solution to just import that file into your google spreadsheet.

Will it connect to Google Sheets and continuously stream the data there while the program is still running, or will it only work once the program is stopped? I need it to stream live, so the goalie can continuously see the data while they are still training.

It would basically be like viewing the serial monitor, only the data is showing constantly in the Google Sheet instead of the serial monitor tab.

Then get yourself an ESP8266 or ESP32 which has wifi and move your project to that board. Put your Uno and Mega back on the shelf for some other project.

OK, I will talk to my teacher about getting one. Thank you!

Also, will this work? this is an esp8266 and an uno I think.

Which one would be better, in your opinion?

Why use 2 boards? And no, it won't work like that. The Uno is a 5V board and the ESP8266 is a 3.3V board. You can not simply connect pins together.

Which one would you prefer, The esp32 or the esp8266?

Depends on how much you want to spend. The ESP32 is new, more powerful but costs more. Either will work [you have not said what data you are trying to send - sensors connected?]

The only 2 things that are connected are a Huskylens object-recognizing camera and 2 pushbuttons.

Thank you very much, this really helps!

WARNING: library GSheet32 claims to run on esp32 architecture(s) and may be incompatible with your current board which runs on renesas_uno architecture(s).
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:5:1: error: 'HTTPClient' does not name a type; did you mean 'HttpClient'?
 HTTPClient http;
 ^~~~~~~~~~
 HttpClient
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::connectWiFi(const char*, const char*)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:22:42: error: invalid operands of types 'const char [23]' and 'const char*' to binary 'operator+'
     Serial.print("Succes!! Connect to : "+WiFi.SSID());
                  ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::sendData(arduino::String)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:27:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:28:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::sendData(arduino::String, arduino::String)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:44:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:45:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::sendData(arduino::String, arduino::String, arduino::String)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:61:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:62:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::sendData(arduino::String, arduino::String, arduino::String, arduino::String)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:78:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:79:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::sendData(arduino::String, arduino::String, arduino::String, arduino::String, arduino::String)':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:95:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:96:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp: In member function 'void GSheet32::clearData()':
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:112:5: error: 'http' was not declared in this scope
     http.begin(url.c_str()); //Specify the URL and certificate
     ^~~~
C:\Users\william.randolph_stu\Documents\Arduino\libraries\GSheet32\GSheet32.cpp:113:29: error: 'HTTPC_STRICT_FOLLOW_REDIRECTS' was not declared in this scope
     http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1