HuskyLens project not working after adding Google Sheets integration

I'm using Huskylens, and for some reason the serial monitor isn't displaying the Huskylens's output. I first thought that it was because I'm trying to display it on a Google sheet, but I opened that up too, and there's nothing showing up. The project goal is to get the Huskylens to track a soccer ball for goalie training (I'm using a small object to start off with; it can't track fast things), and there are 2 push-buttons that input if the goalie has blocked the ball or not. It displayed the data on the serial monitor just fine when I used the Mega board and the starter code with the modifications at the bottom for the push-button, but when I added the GSheet32 thing and used the ESP32, I had to modify the code into what you see above, and now the serial monitor is continuously printing out dots every second on the same line, and the Google sheet is doing nothing (I have the Apps Script written, and the code thingy for it is on line 2). Do you know what I did wrong?

Here's the code:

#include <GSheet32.h>
GSheet32 Sheet("AKfycbxMZikdFlL1r2JCWe0Bjsl8Fc4Kca_lnL86yJtv1er4dG-oyWTEpbEcoH_8C7wPFm4R");

const char* ssid = "Tradition1871"; 
const char* password = "your WiFi password";



/***************************************************
 HUSKYLENS An Easy-to-use AI Machine Vision Sensor
 <https://www.dfrobot.com/product-1922.html>
 
 ***************************************************
 This example shows the basic function of library for HUSKYLENS via Serial.
 
 Created 2020-03-13
 By [Angelo qiao](Angelo.qiao@dfrobot.com)
 
 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************
 1.Connection and Diagram can be found here
 <https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336#target_23>
 2.This code is tested on Arduino Uno, Leonardo, Mega boards.
 ****************************************************/

#include "HUSKYLENS.h"



#define MYPORT_TX 11
#define MYPORT_RX 10

HUSKYLENS huskylens;
HardwareSerial mySerial(2);// RX, TX
//HUSKYLENS green line >> Pin 10; blue line >> Pin 11
void printResult(HUSKYLENSResult result);

const int BlockedButton = 8;
const int NotBlockedButton = 9;

int BlockedButtonState = 0;
int NotBlockedButtonState = 0;


void setup() {
    
    Serial.begin(115200);
    mySerial.begin(9600, SERIAL_8N1, MYPORT_RX, MYPORT_TX);
    pinMode (BlockedButton, INPUT);
    pinMode (NotBlockedButton, INPUT);
    while (!huskylens.begin(mySerial))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>Serial 9600)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
      Serial.begin(115200);
  Sheet.connectWiFi(ssid, password);
  Sheet.clearData(); // function to delete all data in the sheet
  // Add // if you don't want it to be used
}

void loop() {
    BlockedButtonState = digitalRead (BlockedButton);
    NotBlockedButtonState = digitalRead (NotBlockedButton);
    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    }
      Sheet.sendData("C","D","E","F","G");
}


void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK ){
        if (BlockedButtonState == HIGH && NotBlockedButtonState == LOW ){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=1 ")+F("scored_button=0 "));
        }
        else if (NotBlockedButtonState == HIGH && BlockedButtonState == LOW ){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=0 ")+F("scored_button=1 "));
          }
        else if (BlockedButtonState == LOW && NotBlockedButtonState == LOW){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=0 ")+F("scored_button=0 "));
          }
          
    }
    else if (result.command == COMMAND_RETURN_ARROW){
        Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID);
    }
    else{
        Serial.println("Object unknown!");
    }
}
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:40:1: error: expected ',' or ';' before 'void'
 void printResult(HUSKYLENSResult result);
 ^~~~
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino: In function 'void loop()':
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:80:13: error: 'printResult' was not declared in this scope
             printResult(result);
             ^~~~~~~~~~~
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:80:13: note: suggested alternative: 'result'
             printResult(result);
             ^~~~~~~~~~~
             result

This indicates your board is not able to connect to the Wi-Fi router:

It might be caused by a problem with the SSID and password you provided at lines 4 and 5 of the sketch:

Double-check to make sure those are correct. Note that the SSID must be for a 2.4 GHz access point. The Nano ESP32 board can not connect to access points that use the 5 GHz band.

I'm not sure what is going on here. The code you provided compiles without any error for me so it seems that this error was produced when you were compiling a different version of the code.

You are reporting two completely different problems at the same time here. There is the runtime problem of the board not being able to connect to the router, and then there is the compile time problem of the sketch not compiling due to invalid syntax. It is very strange to report both in the same post because you can't upload a sketch if it doesn't compile so the program that is running on your board when it fails to connect to the router must not have been produced from the code you were attempting to compile when you got those compilation errors.

The last problem was a problem that I had that had been solved a while ago. Sorry about that I forgot to delete that bit when I was copying and pasting

as for the wifi, I don't know the password since that's my school's wifi

Could I use a phone hotspot instead?

No worries. I'm glad you were able to solve that problem.

Yes, as long as the hotspot uses the 2.4 GHz band instead of 5 GHz. You can check the hotspot settings in your phone, or the phone's documentation to learn how to configure this.

Got it. Thanks! I'll check back up with you when I get my phone (which will probably be next week) or if someone else is kind let me use theirs

1 Like

I've got my phone hotspot now, but the school wifi makes the hotspot very spotty and I can't get anything to load or even work on my computer unless I use the school wifi. Is there a way I can connect the hotspot to the Arduino board or program while still using my school's wifi for my computer?

You can continue to use the school Wi-Fi on your computer. The idea was for the Arduino board to use the phone's hotspot.

Try this:

  1. Configure your phone to produce a 2.4 GHz Wi-Fi hotspot.
  2. Open the sketch in Arduino IDE.
  3. Change this line of the sketch so that it has the SSID of the hotspot instead of Tradition1871:
    const char* ssid = "Tradition1871"; 
    
  4. Change this line of the sketch so that it has the password of the hotspot instead of your WiFi password:
    const char* password = "your WiFi password";
    
  5. Upload the sketch to the Nano ESP32 board.
  6. Open the Arduino IDE Serial Monitor.

Hopefully this time the sketch will work as expected instead of only printing ..... in Serial Monitor as before.

I did that already, but when I use my hotspot, nothing loads because it barely has any service. I was wondering if there was a way (maybe like Bluetooth or something) to connect my phone to the computer or app without using it as a wifi source

By the way thank you for your help so far; you've gotten me 20 times farther than I could have gotten alone.

It sounds like using the phone hotspot is a dead end. Maybe it is worth seeing if it is possible to use the school Wi-Fi. It is possible that the school's Wi-Fi is open (not protected by a password).

There is an example sketch for the "WiFi" library of the ESP32 boards named "WiFiScan". This sketch scans for all the available 2.4 GHz Wi-Fi access points and then displays information about each of them in the Arduino IDE Serial Monitor.

Please try this:

  1. Connect your ESP32 board to the computer.
  2. Select the board and port in Arduino IDE.
  3. Select File > Examples > WiFi > WiFiScan from the Arduino IDE menus.
  4. Select Sketch > Upload from the Arduino IDE menus.
  5. Wait for the upload to finish successfully.
  6. If the Serial Monitor is not already open, select Tools > Serial Monitor from the Arduino IDE menus to open it.

You should now see something with this form in Serial Monitor:

Scan start
Scan done
3 networks found
Nr | SSID                  | RSSI | CH | Encryption
 1 | foo                   |  -42 |  1 | WPA+WPA2
 2 | bar                   |  -44 |  1 | WPA+WPA2
 3 | baz                   |  -92 |  1 | WPA2

If it says "open" under the "Encryption" column for the row that has the SSID of your school Wi-Fi access point then you can connect the ESP32 board to the school Wi-Fi without needing a password. I can provide instructions you can follow to do that.

After I connect it, will it clear the serial monitor of the wifi stuff and then start displaying the Huskylens data?

The sketch won't clear Serial Monitor automatically, but you can clear the Serial Monitor at any time by clicking the icon at the right side of the Serial Monitor toolbar that looks like an X overlayed over some lines ("Clear Output").

Ok. Will it start displaying the Huskylens data after the wifi data once it's connected?

Yes, but you are getting way ahead of yourself by thinking about the HuskyLens data. For now, please focus all your attention on finding a way to connect the ESP32 board to the Internet. HuskyLens is completely irrelevant for this phase of the project development.

Got it. Thanks! I'm just finishing lunch and then I'll get it all set up

I ran the Wifi scan thing, but the school wifi does not show up. All it shows are Voxel (for our school's Monoprice Voxel 3d printers), and Redwire (which IDK what the heck that is). Our school wifi does not show up.

It might be that it is 5 GHz. The ESP32 can only recognize access points on the 2.4 GHz band.

Is the Google Sheets integration essential for your project?

If you need to put the data in a spreadsheet, you could print the data to Serial in a CSV format. You could then manually copy and paste the data from Serial Monitor (though if you are using Arduino IDE 2.x this is not very easy to do) into into Google Sheets or any other spreadsheet program (e.g., Microsoft Excel, LibreOffice Calc). Or instead of Serial Monitor, you can use an external program to save the CSV data from the serial port to a file, which you can then import into Google Sheets or open in a local spreadsheet application.